Compare commits

..

41 Commits

Author SHA1 Message Date
Aidan Timson
5dc95faaa9 Comments 2025-10-16 16:37:35 +01:00
Aidan Timson
28447b107d Add guard 2025-10-16 16:29:14 +01:00
Aidan Timson
e664b06d9f Fix leak 2025-10-16 16:27:37 +01:00
Aidan Timson
5502940814 Simplify 2025-10-16 16:21:50 +01:00
Aidan Timson
ebbca36212 Remove duplicate transitions (non view transitions) 2025-10-16 16:15:53 +01:00
Aidan Timson
25f1937860 Remove unused code 2025-10-16 12:51:59 +01:00
Aidan Timson
0a1086fb87 Cleanup 2025-10-16 12:38:45 +01:00
Aidan Timson
0b9ed858b9 Move duplicated logic into mixin 2025-10-16 12:32:05 +01:00
Aidan Timson
6d3aa9d1a2 Flip logic 2025-10-16 12:29:38 +01:00
Aidan Timson
7de89f7147 Setup other layouts 2025-10-16 12:17:34 +01:00
Aidan Timson
a7a093833f Fix 2025-10-16 11:08:21 +01:00
Aidan Timson
a02487a377 Fix 2025-10-16 11:05:56 +01:00
Aidan Timson
fcf1618f5c Cleanup 2025-10-16 10:58:04 +01:00
Aidan Timson
fc62a1de55 Fix 2025-10-16 10:57:49 +01:00
Aidan Timson
9cde2fa533 Rename 2025-10-16 10:03:27 +01:00
Aidan Timson
74065ad25d Cleanup 2025-10-16 10:01:17 +01:00
Aidan Timson
e7ed7b926d Cleanup 2025-10-16 09:57:22 +01:00
Aidan Timson
589e21aa4c Rename, zero for reduced motion 2025-10-16 09:56:39 +01:00
Aidan Timson
4d1295ebaf Show on loaded 2025-10-16 09:12:17 +01:00
Aidan Timson
364834001b Rename 2025-10-16 08:48:58 +01:00
Aidan Timson
3ff72bb0d9 Fade out launch screen 2025-10-16 08:46:36 +01:00
Aidan Timson
f3621f8e83 Allow transition name to be provided by caller 2025-10-15 12:36:59 +01:00
Aidan Timson
fb71f88ea0 Use generic transition names 2025-10-15 12:22:43 +01:00
Aidan Timson
cd0398c3ba Switch to mixin 2025-10-15 12:10:31 +01:00
Aidan Timson
0c57fc6b58 Cleanup 2025-10-15 11:50:15 +01:00
Aidan Timson
aef25d0606 Order 2025-10-15 11:48:49 +01:00
Aidan Timson
ab1c736e28 Revert 2025-10-15 11:46:40 +01:00
Aidan Timson
7a16c515bb Remove sidebar code 2025-10-15 11:46:40 +01:00
Aidan Timson
d72ace6f45 POC: view transitions 2025-10-15 11:46:40 +01:00
Aidan Timson
ad94d988bd Respect reduced motion 2025-10-15 11:46:40 +01:00
Aidan Timson
e646bc31d2 Add to hui views 2025-10-15 11:46:40 +01:00
Aidan Timson
60f7a319a2 Add animations 2025-10-15 11:46:40 +01:00
Aidan Timson
fdd268036a Cleanup 2025-10-15 11:46:39 +01:00
Aidan Timson
58eb72d970 Use index based delay 2025-10-15 11:46:39 +01:00
Aidan Timson
9227a78a15 Faster 2025-10-15 11:46:39 +01:00
Aidan Timson
fdab6d0f3c Fade in menu button 2025-10-15 11:46:39 +01:00
Aidan Timson
a82f969a82 Move 2025-10-15 11:46:39 +01:00
Aidan Timson
d78c8034d0 Cap stagger at 8 items 2025-10-15 11:46:39 +01:00
Aidan Timson
7eba7664e7 Animate sidebar 2025-10-15 11:46:39 +01:00
Aidan Timson
528a1a3477 Set base themable animation durations 2025-10-15 11:46:39 +01:00
Aidan Timson
e5df96ebb1 Create fade in slide down shared animation 2025-10-15 11:46:39 +01:00
50 changed files with 765 additions and 642 deletions

View File

@@ -34,7 +34,7 @@
"@codemirror/legacy-modes": "6.5.2",
"@codemirror/search": "6.5.11",
"@codemirror/state": "6.5.2",
"@codemirror/view": "6.38.6",
"@codemirror/view": "6.38.5",
"@date-fns/tz": "1.4.1",
"@egjs/hammerjs": "2.0.17",
"@formatjs/intl-datetimeformat": "6.18.2",
@@ -52,7 +52,7 @@
"@fullcalendar/list": "6.1.19",
"@fullcalendar/luxon3": "6.1.19",
"@fullcalendar/timegrid": "6.1.19",
"@home-assistant/webawesome": "3.0.0-beta.6.ha.5",
"@home-assistant/webawesome": "3.0.0-beta.6.ha.4",
"@lezer/highlight": "1.2.1",
"@lit-labs/motion": "1.0.9",
"@lit-labs/observers": "2.0.6",

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiEye, mdiEyeOff } from "@mdi/js";
import { mdiDrag, mdiEye, mdiEyeOff } from "@mdi/js";
import type { CSSResultGroup } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -129,7 +129,7 @@ export class DialogDataTableSettings extends LitElement {
${canMove && isVisible
? html`<ha-svg-icon
class="handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
slot="graphic"
></ha-svg-icon>`
: nothing}

View File

@@ -1,13 +1,13 @@
import { mdiDragHorizontalVariant } from "@mdi/js";
import { mdiDrag } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { isValidEntityId } from "../../common/entity/valid_entity_id";
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
import type { HomeAssistant, ValueChangedEvent } from "../../types";
import "../ha-sortable";
import "./ha-entity-picker";
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
@customElement("ha-entities-picker")
class HaEntitiesPicker extends LitElement {
@@ -118,7 +118,7 @@ class HaEntitiesPicker extends LitElement {
? html`
<ha-svg-icon
class="entity-handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
></ha-svg-icon>
`
: nothing}

View File

@@ -1,5 +1,5 @@
import "@material/mwc-menu/mwc-menu-surface";
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import { mdiDrag, mdiPlus } from "@mdi/js";
import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import type { IFuseOptions } from "fuse.js";
import Fuse from "fuse.js";
@@ -86,8 +86,8 @@ export class HaEntityNamePicker extends LitElement {
private _editIndex?: number;
private _validTypes = memoizeOne((entityId?: string) => {
const options = new Set<string>(["text"]);
private _validOptions = memoizeOne((entityId?: string) => {
const options = new Set<string>();
if (!entityId) {
return options;
}
@@ -119,22 +119,22 @@ export class HaEntityNamePicker extends LitElement {
return [];
}
const types = this._validTypes(entityId);
const options = this._validOptions(entityId);
const items = (
["entity", "device", "area", "floor"] as const
).map<EntityNameOption>((name) => {
const stateObj = this.hass.states[entityId];
const isValid = types.has(name);
const isValid = options.has(name);
const primary = this.hass.localize(
`ui.components.entity.entity-name-picker.types.${name}`
);
const secondary =
(stateObj && isValid
stateObj && isValid
? this.hass.formatEntityName(stateObj, { type: name })
: this.hass.localize(
`ui.components.entity.entity-name-picker.types.${name}_missing` as LocalizeKeys
)) || "-";
) || "-";
return {
primary,
@@ -169,9 +169,9 @@ export class HaEntityNamePicker extends LitElement {
};
protected render() {
const value = this._items;
const value = this._value;
const options = this._getOptions(this.entityId);
const validTypes = this._validTypes(this.entityId);
const validOptions = this._validOptions(this.entityId);
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
@@ -185,11 +185,12 @@ export class HaEntityNamePicker extends LitElement {
>
<ha-chip-set>
${repeat(
this._items,
this._value,
(item) => item,
(item: EntityNameItem, idx) => {
const label = this._formatItem(item);
const isValid = validTypes.has(item.type);
const isValid =
item.type === "text" || validOptions.has(item.type);
return html`
<ha-input-chip
data-idx=${idx}
@@ -200,10 +201,7 @@ export class HaEntityNamePicker extends LitElement {
.disabled=${this.disabled}
class=${!isValid ? "invalid" : ""}
>
<ha-svg-icon
slot="icon"
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon slot="icon" .path=${mdiDrag}></ha-svg-icon>
<span>${label}</span>
</ha-input-chip>
`;
@@ -237,7 +235,7 @@ export class HaEntityNamePicker extends LitElement {
.hass=${this.hass}
.value=${""}
.autofocus=${this.autofocus}
.disabled=${this.disabled}
.disabled=${this.disabled || !this.entityId}
.required=${this.required && !value.length}
.helper=${this.helper}
.items=${options}
@@ -284,16 +282,13 @@ export class HaEntityNamePicker extends LitElement {
this._opened = true;
}
private get _items(): EntityNameItem[] {
private get _value(): EntityNameItem[] {
return this._toItems(this.value);
}
private _toItems = memoizeOne((value?: typeof this.value) => {
if (typeof value === "string") {
if (value === "") {
return [];
}
return [{ type: "text", text: value } satisfies EntityNameItem];
return [{ type: "text", text: value } as const];
}
return value ? ensureArray(value) : [];
});
@@ -301,7 +296,7 @@ export class HaEntityNamePicker extends LitElement {
private _toValue = memoizeOne(
(items: EntityNameItem[]): typeof this.value => {
if (items.length === 0) {
return "";
return [];
}
if (items.length === 1) {
const item = items[0];
@@ -317,21 +312,19 @@ export class HaEntityNamePicker extends LitElement {
const options = this._comboBox.items || [];
const initialItem =
this._editIndex != null ? this._items[this._editIndex] : undefined;
this._editIndex != null ? this._value[this._editIndex] : undefined;
const initialValue = initialItem ? formatOptionValue(initialItem) : "";
const filteredItems = this._filterSelectedOptions(options, initialValue);
if (initialItem?.type === "text" && initialItem.text) {
if (initialItem && initialItem.type === "text" && initialItem.text) {
filteredItems.push(this._customNameOption(initialItem.text));
}
this._comboBox.filteredItems = filteredItems;
this._comboBox.setInputValue(initialValue);
} else {
this._opened = false;
this._comboBox.setInputValue("");
}
}
@@ -339,16 +332,15 @@ export class HaEntityNamePicker extends LitElement {
options: EntityNameOption[],
current?: string
) => {
const items = this._items;
const value = this._value;
const excludedValues = new Set(
items
.filter((item) => UNIQUE_TYPES.has(item.type))
.map((item) => formatOptionValue(item))
);
const types = value.map((item) => item.type) as string[];
const filteredOptions = options.filter(
(option) => !excludedValues.has(option.value) || option.value === current
(option) =>
!UNIQUE_TYPES.has(option.value) ||
!types.includes(option.value) ||
option.value === current
);
return filteredOptions;
};
@@ -359,14 +351,16 @@ export class HaEntityNamePicker extends LitElement {
const options = this._comboBox.items || [];
const currentItem =
this._editIndex != null ? this._items[this._editIndex] : undefined;
this._editIndex != null ? this._value[this._editIndex] : undefined;
const currentValue = currentItem ? formatOptionValue(currentItem) : "";
let filteredItems = this._filterSelectedOptions(options, currentValue);
this._comboBox.filteredItems = this._filterSelectedOptions(
options,
currentValue
);
if (!filter) {
this._comboBox.filteredItems = filteredItems;
return;
}
@@ -378,8 +372,9 @@ export class HaEntityNamePicker extends LitElement {
ignoreDiacritics: true,
};
const fuse = new Fuse(filteredItems, fuseOptions);
filteredItems = fuse.search(filter).map((result) => result.item);
const fuse = new Fuse(this._comboBox.filteredItems, fuseOptions);
const filteredItems = fuse.search(filter).map((result) => result.item);
filteredItems.push(this._customNameOption(input));
this._comboBox.filteredItems = filteredItems;
}
@@ -387,7 +382,7 @@ export class HaEntityNamePicker extends LitElement {
private async _moveItem(ev: CustomEvent) {
ev.stopPropagation();
const { oldIndex, newIndex } = ev.detail;
const value = this._items;
const value = this._value;
const newValue = value.concat();
const element = newValue.splice(oldIndex, 1)[0];
newValue.splice(newIndex, 0, element);
@@ -398,7 +393,7 @@ export class HaEntityNamePicker extends LitElement {
private async _removeItem(ev) {
ev.stopPropagation();
const value = [...this._items];
const value = [...this._value];
const idx = parseInt(ev.target.dataset.idx, 10);
value.splice(idx, 1);
this._setValue(value);
@@ -416,7 +411,7 @@ export class HaEntityNamePicker extends LitElement {
const item: EntityNameItem = parseOptionValue(value);
const newValue = [...this._items];
const newValue = [...this._value];
if (this._editIndex != null) {
newValue[this._editIndex] = item;

View File

@@ -1,39 +1,23 @@
import "@material/mwc-menu/mwc-menu-surface";
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
import type { IFuseOptions } from "fuse.js";
import Fuse from "fuse.js";
import { mdiDrag } from "@mdi/js";
import type { HassEntity } from "home-assistant-js-websocket";
import { css, html, LitElement, nothing } from "lit";
import type { PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
import memoizeOne from "memoize-one";
import { ensureArray } from "../../common/array/ensure-array";
import { fireEvent } from "../../common/dom/fire_event";
import { stopPropagation } from "../../common/dom/stop_propagation";
import { computeDomain } from "../../common/entity/compute_domain";
import {
STATE_DISPLAY_SPECIAL_CONTENT,
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS,
} from "../../state-display/state-display";
import type { HomeAssistant, ValueChangedEvent } from "../../types";
import "../chips/ha-assist-chip";
import "../chips/ha-chip-set";
import "../chips/ha-input-chip";
import "../ha-combo-box";
import type { HaComboBox } from "../ha-combo-box";
import "../ha-sortable";
interface StateContentOption {
primary: string;
value: string;
}
const rowRenderer: ComboBoxLitRenderer<StateContentOption> = (item) => html`
<ha-combo-box-item type="button">
<span slot="headline">${item.primary}</span>
</ha-combo-box-item>
`;
import "../chips/ha-input-chip";
import "../chips/ha-chip-set";
import type { HaComboBox } from "../ha-combo-box";
const HIDDEN_ATTRIBUTES = [
"access_token",
@@ -90,7 +74,7 @@ const HIDDEN_ATTRIBUTES = [
];
@customElement("ha-entity-state-content-picker")
export class HaStateContentPicker extends LitElement {
class HaEntityStatePicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public entityId?: string;
@@ -111,28 +95,26 @@ export class HaStateContentPicker extends LitElement {
@property() public helper?: string;
@query(".container", true) private _container?: HTMLDivElement;
@state() private _opened = false;
@query("ha-combo-box", true) private _comboBox!: HaComboBox;
@state() private _opened = false;
protected shouldUpdate(changedProps: PropertyValues) {
return !(!changedProps.has("_opened") && this._opened);
}
private _editIndex?: number;
private _options = memoizeOne(
private options = memoizeOne(
(entityId?: string, stateObj?: HassEntity, allowName?: boolean) => {
const domain = entityId ? computeDomain(entityId) : undefined;
return [
{
primary: this.hass.localize(
"ui.components.state-content-picker.state"
),
label: this.hass.localize("ui.components.state-content-picker.state"),
value: "state",
},
...(allowName
? [
{
primary: this.hass.localize(
label: this.hass.localize(
"ui.components.state-content-picker.name"
),
value: "name",
@@ -140,13 +122,13 @@ export class HaStateContentPicker extends LitElement {
]
: []),
{
primary: this.hass.localize(
label: this.hass.localize(
"ui.components.state-content-picker.last_changed"
),
value: "last_changed",
},
{
primary: this.hass.localize(
label: this.hass.localize(
"ui.components.state-content-picker.last_updated"
),
value: "last_updated",
@@ -155,7 +137,7 @@ export class HaStateContentPicker extends LitElement {
? STATE_DISPLAY_SPECIAL_CONTENT.filter((content) =>
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS[domain]?.includes(content)
).map((content) => ({
primary: this.hass.localize(
label: this.hass.localize(
`ui.components.state-content-picker.${content}`
),
value: content,
@@ -164,201 +146,105 @@ export class HaStateContentPicker extends LitElement {
...Object.keys(stateObj?.attributes ?? {})
.filter((a) => !HIDDEN_ATTRIBUTES.includes(a))
.map((attribute) => ({
primary: this.hass.formatEntityAttributeName(stateObj!, attribute),
value: attribute,
label: this.hass.formatEntityAttributeName(stateObj!, attribute),
})),
] satisfies StateContentOption[];
];
}
);
private _filter = "";
protected render() {
if (!this.hass) {
return nothing;
}
const value = this._value;
const stateObj = this.entityId
? this.hass.states[this.entityId]
: undefined;
const options = this._options(this.entityId, stateObj, this.allowName);
const options = this.options(this.entityId, stateObj, this.allowName);
const optionItems = options.filter(
(option) => !this._value.includes(option.value)
);
return html`
${this.label ? html`<label>${this.label}</label>` : nothing}
<div class="container ${this.disabled ? "disabled" : ""}">
<ha-sortable
no-style
@item-moved=${this._moveItem}
.disabled=${this.disabled}
handle-selector="button.primary.action"
filter=".add"
>
<ha-chip-set>
${repeat(
this._value,
(item) => item,
(item: string, idx) => {
const label = options.find((o) => o.value === item)?.primary;
const isValid = !!label;
return html`
<ha-input-chip
data-idx=${idx}
@remove=${this._removeItem}
@click=${this._editItem}
.label=${label || item}
.selected=${!this.disabled}
.disabled=${this.disabled}
class=${!isValid ? "invalid" : ""}
>
<ha-svg-icon
slot="icon"
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
</ha-input-chip>
`;
}
)}
${this.disabled
? nothing
: html`
<ha-assist-chip
@click=${this._addItem}
.disabled=${this.disabled}
label=${this.hass.localize(
"ui.components.entity.entity-state-content-picker.add"
)}
class="add"
>
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</ha-assist-chip>
`}
</ha-chip-set>
</ha-sortable>
${value?.length
? html`
<ha-sortable
no-style
@item-moved=${this._moveItem}
.disabled=${this.disabled}
handle-selector="button.primary.action"
>
<ha-chip-set>
${repeat(
this._value,
(item) => item,
(item, idx) => {
const label =
options.find((option) => option.value === item)?.label ||
item;
return html`
<ha-input-chip
.idx=${idx}
@remove=${this._removeItem}
.label=${label}
selected
>
<ha-svg-icon slot="icon" .path=${mdiDrag}></ha-svg-icon>
${label}
</ha-input-chip>
`;
}
)}
</ha-chip-set>
</ha-sortable>
`
: nothing}
<mwc-menu-surface
.open=${this._opened}
@closed=${this._onClosed}
@opened=${this._onOpened}
@input=${stopPropagation}
.anchor=${this._container}
>
<ha-combo-box
.hass=${this.hass}
.value=${""}
.autofocus=${this.autofocus}
.disabled=${this.disabled || !this.entityId}
.required=${this.required && !value.length}
.helper=${this.helper}
.items=${options}
allow-custom-value
item-id-path="value"
item-value-path="value"
item-label-path="primary"
.renderer=${rowRenderer}
@opened-changed=${this._openedChanged}
@value-changed=${this._comboBoxValueChanged}
@filter-changed=${this._filterChanged}
>
</ha-combo-box>
</mwc-menu-surface>
</div>
<ha-combo-box
item-value-path="value"
item-label-path="label"
.hass=${this.hass}
.label=${this.label}
.helper=${this.helper}
.disabled=${this.disabled}
.required=${this.required && !value.length}
.value=${""}
.items=${optionItems}
allow-custom-value
@filter-changed=${this._filterChanged}
@value-changed=${this._comboBoxValueChanged}
@opened-changed=${this._openedChanged}
></ha-combo-box>
`;
}
private _onClosed(ev) {
ev.stopPropagation();
this._opened = false;
this._editIndex = undefined;
}
private async _onOpened(ev) {
if (!this._opened) {
return;
}
ev.stopPropagation();
this._opened = true;
await this._comboBox?.focus();
await this._comboBox?.open();
}
private async _addItem(ev) {
ev.stopPropagation();
this._opened = true;
}
private async _editItem(ev) {
ev.stopPropagation();
const idx = parseInt(ev.currentTarget.dataset.idx, 10);
this._editIndex = idx;
this._opened = true;
}
private get _value() {
return !this.value ? [] : ensureArray(this.value);
}
private _toValue = memoizeOne((value: string[]): typeof this.value => {
if (value.length === 0) {
return undefined;
}
if (value.length === 1) {
return value[0];
}
return value;
});
private _openedChanged(ev: ValueChangedEvent<boolean>) {
const open = ev.detail.value;
if (open) {
const options = this._comboBox.items || [];
const initialValue =
this._editIndex != null ? this._value[this._editIndex] : "";
const filteredItems = this._filterSelectedOptions(options, initialValue);
this._comboBox.filteredItems = filteredItems;
this._comboBox.setInputValue(initialValue);
} else {
this._opened = false;
}
this._opened = ev.detail.value;
this._comboBox.filteredItems = this._comboBox.items;
}
private _filterSelectedOptions = (
options: StateContentOption[],
current?: string
) => {
const value = this._value;
private _filterChanged(ev?: CustomEvent): void {
this._filter = ev?.detail.value || "";
return options.filter(
(option) => !value.includes(option.value) || option.value === current
);
};
const filteredItems = this._comboBox.items?.filter((item) => {
const label = item.label || item.value;
return label.toLowerCase().includes(this._filter?.toLowerCase());
});
private _filterChanged(ev: ValueChangedEvent<string>) {
const input = ev.detail.value;
const filter = input?.toLowerCase() || "";
const options = this._comboBox.items || [];
const currentValue =
this._editIndex != null ? this._value[this._editIndex] : "";
this._comboBox.filteredItems = this._filterSelectedOptions(
options,
currentValue
);
if (!filter) {
return;
if (this._filter) {
filteredItems?.unshift({ label: this._filter, value: this._filter });
}
const fuseOptions: IFuseOptions<StateContentOption> = {
keys: ["primary", "secondary", "value"],
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
ignoreDiacritics: true,
};
const fuse = new Fuse(this._comboBox.filteredItems, fuseOptions);
const filteredItems = fuse.search(filter).map((result) => result.item);
this._comboBox.filteredItems = filteredItems;
}
@@ -371,40 +257,43 @@ export class HaStateContentPicker extends LitElement {
newValue.splice(newIndex, 0, element);
this._setValue(newValue);
await this.updateComplete;
this._filterChanged({ detail: { value: "" } } as ValueChangedEvent<string>);
this._filterChanged();
}
private async _removeItem(ev) {
ev.stopPropagation();
const value = [...this._value];
const idx = parseInt(ev.target.dataset.idx, 10);
value.splice(idx, 1);
const value: string[] = [...this._value];
value.splice(ev.target.idx, 1);
this._setValue(value);
await this.updateComplete;
this._filterChanged({ detail: { value: "" } } as ValueChangedEvent<string>);
this._filterChanged();
}
private _comboBoxValueChanged(ev: ValueChangedEvent<string>): void {
private _comboBoxValueChanged(ev: CustomEvent): void {
ev.stopPropagation();
const value = ev.detail.value;
const newValue = ev.detail.value;
if (this.disabled || value === "") {
if (this.disabled || newValue === "") {
return;
}
const newValue = [...this._value];
const currentValue = this._value;
if (this._editIndex != null) {
newValue[this._editIndex] = value;
} else {
newValue.push(value);
if (currentValue.includes(newValue)) {
return;
}
this._setValue(newValue);
setTimeout(() => {
this._filterChanged();
this._comboBox.setInputValue("");
}, 0);
this._setValue([...currentValue, newValue]);
}
private _setValue(value: string[]) {
const newValue = this._toValue(value);
const newValue =
value.length === 0 ? undefined : value.length === 1 ? value[0] : value;
this.value = newValue;
fireEvent(this, "value-changed", {
value: newValue,
@@ -414,64 +303,10 @@ export class HaStateContentPicker extends LitElement {
static styles = css`
:host {
position: relative;
width: 100%;
}
.container {
position: relative;
background-color: var(--mdc-text-field-fill-color, whitesmoke);
border-radius: var(--ha-border-radius-sm);
border-end-end-radius: var(--ha-border-radius-square);
border-end-start-radius: var(--ha-border-radius-square);
}
.container:after {
display: block;
content: "";
position: absolute;
pointer-events: none;
bottom: 0;
left: 0;
right: 0;
height: 1px;
width: 100%;
background-color: var(
--mdc-text-field-idle-line-color,
rgba(0, 0, 0, 0.42)
);
transform:
height 180ms ease-in-out,
background-color 180ms ease-in-out;
}
.container.disabled:after {
background-color: var(
--mdc-text-field-disabled-line-color,
rgba(0, 0, 0, 0.42)
);
}
.container:focus-within:after {
height: 2px;
background-color: var(--mdc-theme-primary);
}
label {
display: block;
margin: 0 0 var(--ha-space-2);
}
.add {
order: 1;
}
mwc-menu-surface {
--mdc-menu-min-width: 100%;
}
ha-chip-set {
padding: var(--ha-space-2) var(--ha-space-2);
}
.invalid {
text-decoration: line-through;
padding: 8px 0;
}
.sortable-fallback {
@@ -491,6 +326,6 @@ export class HaStateContentPicker extends LitElement {
declare global {
interface HTMLElementTagNameMap {
"ha-entity-state-content-picker": HaStateContentPicker;
"ha-entity-state-content-picker": HaEntityStatePicker;
}
}

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiTextureBox } from "@mdi/js";
import { mdiDrag, mdiTextureBox } from "@mdi/js";
import type { TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
@@ -105,7 +105,7 @@ export class HaAreasFloorsDisplayEditor extends LitElement {
<ha-svg-icon
class="handle"
slot="icons"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
></ha-svg-icon>
`}
<ha-items-display-editor

View File

@@ -49,16 +49,12 @@ export class HaDialogHeader extends LitElement {
display: flex;
flex-direction: row;
align-items: center;
padding: 0 var(--ha-space-1);
padding: 4px;
box-sizing: border-box;
}
.header-content {
flex: 1;
padding: 10px var(--ha-space-1);
display: flex;
flex-direction: column;
justify-content: center;
min-height: var(--ha-space-12);
padding: 10px 4px;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
@@ -67,7 +63,7 @@ export class HaDialogHeader extends LitElement {
.header-title {
height: var(
--ha-dialog-header-title-height,
calc(var(--ha-font-size-xl) + var(--ha-space-1))
calc(var(--ha-font-size-xl) + 4px)
);
font-size: var(--ha-font-size-xl);
line-height: var(--ha-line-height-condensed);
@@ -80,19 +76,19 @@ export class HaDialogHeader extends LitElement {
}
@media all and (min-width: 450px) and (min-height: 500px) {
.header-bar {
padding: 0 var(--ha-space-2);
padding: 16px;
}
}
.header-navigation-icon {
flex: none;
min-width: var(--ha-space-2);
min-width: 8px;
height: 100%;
display: flex;
flex-direction: row;
}
.header-action-items {
flex: none;
min-width: var(--ha-space-2);
min-width: 8px;
height: 100%;
display: flex;
flex-direction: row;

View File

@@ -1,5 +1,5 @@
import { ResizeController } from "@lit-labs/observers/resize-controller";
import { mdiDragHorizontalVariant, mdiEye, mdiEyeOff } from "@mdi/js";
import { mdiDrag, mdiEye, mdiEyeOff } from "@mdi/js";
import type { TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
@@ -178,7 +178,7 @@ export class HaItemDisplayEditor extends LitElement {
? this._dragHandleKeydown
: undefined}
class="handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
slot="end"
></ha-svg-icon>
`

View File

@@ -0,0 +1,152 @@
import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
import type { ImageSelector } from "../../data/selector";
import type { HomeAssistant } from "../../types";
import "../ha-icon-button";
import "../ha-textarea";
import "../ha-textfield";
import "../ha-picture-upload";
import "../ha-radio";
import "../ha-formfield";
import type { HaPictureUpload } from "../ha-picture-upload";
import { URL_PREFIX } from "../../data/image_upload";
@customElement("ha-selector-image")
export class HaImageSelector extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public value?: any;
@property() public name?: string;
@property() public label?: string;
@property() public placeholder?: string;
@property() public helper?: string;
@property({ attribute: false }) public selector!: ImageSelector;
@property({ type: Boolean }) public disabled = false;
@property({ type: Boolean }) public required = true;
@state() private showUpload = false;
protected firstUpdated(changedProps): void {
super.firstUpdated(changedProps);
if (!this.value || this.value.startsWith(URL_PREFIX)) {
this.showUpload = true;
}
}
protected render() {
return html`
<div>
<label>
${this.hass.localize(
"ui.components.selectors.image.select_image_with_label",
{
label:
this.label ||
this.hass.localize("ui.components.selectors.image.image"),
}
)}
<ha-formfield
.label=${this.hass.localize("ui.components.selectors.image.upload")}
>
<ha-radio
name="mode"
value="upload"
.checked=${this.showUpload}
@change=${this._radioGroupPicked}
></ha-radio>
</ha-formfield>
<ha-formfield
.label=${this.hass.localize("ui.components.selectors.image.url")}
>
<ha-radio
name="mode"
value="url"
.checked=${!this.showUpload}
@change=${this._radioGroupPicked}
></ha-radio>
</ha-formfield>
</label>
${!this.showUpload
? html`
<ha-textfield
.name=${this.name}
.value=${this.value || ""}
.placeholder=${this.placeholder || ""}
.helper=${this.helper}
helperPersistent
.disabled=${this.disabled}
@input=${this._handleChange}
.label=${this.label || ""}
.required=${this.required}
></ha-textfield>
`
: html`
<ha-picture-upload
.hass=${this.hass}
.value=${this.value?.startsWith(URL_PREFIX) ? this.value : null}
.original=${this.selector.image?.original}
.cropOptions=${this.selector.image?.crop}
select-media
@change=${this._pictureChanged}
></ha-picture-upload>
`}
</div>
`;
}
private _radioGroupPicked(ev): void {
this.showUpload = ev.target.value === "upload";
}
private _pictureChanged(ev) {
const value = (ev.target as HaPictureUpload).value;
fireEvent(this, "value-changed", { value: value ?? undefined });
}
private _handleChange(ev) {
let value = ev.target.value;
if (this.value === value) {
return;
}
if (value === "" && !this.required) {
value = undefined;
}
fireEvent(this, "value-changed", { value });
}
static styles = css`
:host {
display: block;
position: relative;
}
div {
display: flex;
flex-direction: column;
}
label {
display: flex;
flex-direction: column;
}
ha-textarea,
ha-textfield {
width: 100%;
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-selector-image": HaImageSelector;
}
}

View File

@@ -1,9 +1,4 @@
import {
mdiClose,
mdiDelete,
mdiDragHorizontalVariant,
mdiPencil,
} from "@mdi/js";
import { mdiClose, mdiDelete, mdiDrag, mdiPencil } from "@mdi/js";
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
import { customElement, property, query } from "lit/decorators";
import memoizeOne from "memoize-one";
@@ -97,7 +92,7 @@ export class HaObjectSelector extends LitElement {
? html`
<ha-svg-icon
class="handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
slot="start"
></ha-svg-icon>
`

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant } from "@mdi/js";
import { mdiDrag } from "@mdi/js";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
@@ -197,7 +197,7 @@ export class HaSelectSelector extends LitElement {
? html`
<ha-svg-icon
slot="icon"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
></ha-svg-icon>
`
: nothing}

View File

@@ -36,7 +36,7 @@ export class HaSelectorUiStateContent extends SubscribeMixin(LitElement) {
.helper=${this.helper}
.disabled=${this.disabled}
.required=${this.required}
.allowName=${this.selector.ui_state_content?.allow_name || false}
.allowName=${this.selector.ui_state_content?.allow_name}
></ha-entity-state-content-picker>
`;
}

View File

@@ -34,6 +34,7 @@ const LOAD_ELEMENTS = {
file: () => import("./ha-selector-file"),
floor: () => import("./ha-selector-floor"),
label: () => import("./ha-selector-label"),
image: () => import("./ha-selector-image"),
background: () => import("./ha-selector-background"),
language: () => import("./ha-selector-language"),
navigation: () => import("./ha-selector-navigation"),

View File

@@ -36,6 +36,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
@property({ attribute: false }) public value?: HassServiceTarget;
@property() public label?: string;
@property() public helper?: string;
@property({ type: Boolean, reflect: true }) public compact = false;
@@ -99,7 +101,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
(floor_id) => html`
<ha-target-picker-value-chip
.hass=${this.hass}
type="floor"
.type=${"floor"}
.itemId=${floor_id}
@remove-target-item=${this._handleRemove}
@expand-target-item=${this._handleExpand}
@@ -112,7 +114,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
(area_id) => html`
<ha-target-picker-value-chip
.hass=${this.hass}
type="area"
.type=${"area"}
.itemId=${area_id}
@remove-target-item=${this._handleRemove}
@expand-target-item=${this._handleExpand}
@@ -125,7 +127,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
(device_id) => html`
<ha-target-picker-value-chip
.hass=${this.hass}
type="device"
.type=${"device"}
.itemId=${device_id}
@remove-target-item=${this._handleRemove}
@expand-target-item=${this._handleExpand}
@@ -138,7 +140,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
(entity_id) => html`
<ha-target-picker-value-chip
.hass=${this.hass}
type="entity"
.type=${"entity"}
.itemId=${entity_id}
@remove-target-item=${this._handleRemove}
@expand-target-item=${this._handleExpand}
@@ -151,7 +153,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
(label_id) => html`
<ha-target-picker-value-chip
.hass=${this.hass}
type="label"
.type=${"label"}
.itemId=${label_id}
@remove-target-item=${this._handleRemove}
@expand-target-item=${this._handleExpand}
@@ -171,6 +173,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
type="entity"
.hass=${this.hass}
.items=${{ entity: ensureArray(this.value?.entity_id) }}
.collapsed=${this.compact}
.deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains}
@@ -186,6 +189,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
type="device"
.hass=${this.hass}
.items=${{ device: ensureArray(this.value?.device_id) }}
.collapsed=${this.compact}
.deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains}
@@ -204,6 +208,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
floor: ensureArray(this.value?.floor_id),
area: ensureArray(this.value?.area_id),
}}
.collapsed=${this.compact}
.deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains}
@@ -219,6 +224,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
type="label"
.hass=${this.hass}
.items=${{ label: ensureArray(this.value?.label_id) }}
.collapsed=${this.compact}
.deviceFilter=${this.deviceFilter}
.entityFilter=${this.entityFilter}
.includeDomains=${this.includeDomains}
@@ -271,12 +277,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
auto-size-padding="16"
@wa-after-show=${this._showSelector}
@wa-after-hide=${this._hidePicker}
trap-focus
role="dialog"
aria-modal="true"
aria-label=${this.hass.localize(
"ui.components.target-picker.add_target"
)}
>
${this._renderTargetSelector()}
</wa-popover>
@@ -287,11 +287,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
.open=${this._pickerWrapperOpen}
@wa-after-show=${this._showSelector}
@closed=${this._hidePicker}
role="dialog"
aria-modal="true"
aria-label=${this.hass.localize(
"ui.components.target-picker.add_target"
)}
>
${this._renderTargetSelector(true)}
</ha-bottom-sheet>`
@@ -399,12 +394,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
}
: { [typeId]: id },
});
this.shadowRoot
?.querySelector(
`ha-target-picker-item-group[type='${this._newTarget?.type}']`
)
?.removeAttribute("collapsed");
}
private _handleTargetPicked = async (

View File

@@ -2,13 +2,26 @@ import { TopAppBarFixedBase } from "@material/mwc-top-app-bar-fixed/mwc-top-app-
import { styles } from "@material/mwc-top-app-bar/mwc-top-app-bar.css";
import { css } from "lit";
import { customElement, property } from "lit/decorators";
import { ViewTransitionMixin } from "../mixins/view-transition-mixin";
import { haStyleViewTransitions } from "../resources/styles";
@customElement("ha-top-app-bar-fixed")
export class HaTopAppBarFixed extends TopAppBarFixedBase {
export class HaTopAppBarFixed extends ViewTransitionMixin(TopAppBarFixedBase) {
@property({ type: Boolean, reflect: true }) public narrow = false;
@property({ type: Boolean, reflect: true, attribute: "content-loading" })
public contentLoading = true;
protected onLoadTransition(): void {
// Trigger the transition when content is slotted
this.startViewTransition(() => {
this.contentLoading = false;
});
}
static override styles = [
styles,
haStyleViewTransitions,
css`
header {
padding-top: var(--safe-area-inset-top);
@@ -23,6 +36,10 @@ export class HaTopAppBarFixed extends TopAppBarFixedBase {
);
padding-bottom: var(--safe-area-inset-bottom);
padding-right: var(--safe-area-inset-right);
view-transition-name: layout-fade-in;
}
:host([content-loading]) .mdc-top-app-bar--fixed-adjust {
opacity: 0;
}
:host([narrow]) .mdc-top-app-bar--fixed-adjust {
padding-left: var(--safe-area-inset-left);

View File

@@ -7,17 +7,18 @@ import type { MDCTopAppBarAdapter } from "@material/top-app-bar/adapter";
import { strings } from "@material/top-app-bar/constants";
import MDCFixedTopAppBarFoundation from "@material/top-app-bar/fixed/foundation";
import { html, css, nothing } from "lit";
import { property, query, customElement } from "lit/decorators";
import { property, query, customElement, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styles } from "@material/mwc-top-app-bar/mwc-top-app-bar.css";
import { haStyleScrollbar } from "../resources/styles";
import { ViewTransitionMixin } from "../mixins/view-transition-mixin";
import { haStyleScrollbar, haStyleViewTransitions } from "../resources/styles";
export const passiveEventOptionsIfSupported = supportsPassiveEventListener
? { passive: true }
: undefined;
@customElement("ha-two-pane-top-app-bar-fixed")
export class TopAppBarBaseBase extends BaseElement {
export class TopAppBarBaseBase extends ViewTransitionMixin(BaseElement) {
protected override mdcFoundation!: MDCFixedTopAppBarFoundation;
protected override mdcFoundationClass = MDCFixedTopAppBarFoundation;
@@ -48,6 +49,15 @@ export class TopAppBarBaseBase extends BaseElement {
@query(".pane .ha-scrollbar") private _paneElement?: HTMLElement;
@state() private _loaded = false;
protected onLoadTransition(): void {
// Trigger the transition when content is slotted
this.startViewTransition(() => {
this._loaded = true;
});
}
@property({ attribute: false, type: Object })
get scrollTarget() {
return this._scrollTarget || window;
@@ -144,7 +154,12 @@ export class TopAppBarBaseBase extends BaseElement {
: nothing}
<div class="main">
${this.pane ? html`<div class="shadow-container"></div>` : nothing}
<div class="content">
<div
class=${classMap({
content: true,
loading: !this._loaded,
})}
>
<slot></slot>
</div>
</div>
@@ -245,6 +260,7 @@ export class TopAppBarBaseBase extends BaseElement {
static override styles = [
styles,
haStyleScrollbar,
haStyleViewTransitions,
css`
header {
padding-top: var(--safe-area-inset-top);
@@ -341,6 +357,10 @@ export class TopAppBarBaseBase extends BaseElement {
.mdc-top-app-bar--pane .content {
height: 100%;
overflow: auto;
view-transition-name: layout-fade-in;
}
.content.loading {
opacity: 0;
}
.mdc-top-app-bar__title {
font-size: var(--ha-font-size-xl);

View File

@@ -247,7 +247,10 @@ export class HaWaDialog extends LitElement {
.header-title {
margin: 0;
margin-bottom: 0;
color: var(--ha-dialog-header-title-color, var(--primary-text-color));
color: var(
--ha-dialog-header-title-color,
var(--ha-color-on-surface-default, var(--primary-text-color))
);
font-size: var(
--ha-dialog-header-title-font-size,
var(--ha-font-size-2xl)

View File

@@ -18,7 +18,7 @@ export class HaTargetPickerItemGroup extends LitElement {
Record<TargetType, string[]>
>;
@property({ type: Boolean, reflect: true }) public collapsed = false;
@property({ type: Boolean }) public collapsed = false;
@property({ attribute: false })
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@@ -50,11 +50,7 @@ export class HaTargetPickerItemGroup extends LitElement {
}
});
return html`<ha-expansion-panel
.expanded=${!this.collapsed}
left-chevron
@expanded-changed=${this._expandedChanged}
>
return html`<ha-expansion-panel .expanded=${!this.collapsed} left-chevron>
<div slot="header" class="heading">
${this.hass.localize(
`ui.components.target-picker.selected.${this.type}`,
@@ -82,10 +78,6 @@ export class HaTargetPickerItemGroup extends LitElement {
</ha-expansion-panel>`;
}
private _expandedChanged(ev: CustomEvent) {
this.collapsed = !ev.detail.expanded;
}
static styles = css`
:host {
display: block;

View File

@@ -130,7 +130,7 @@ export class HaTargetPickerItemRow extends LitElement {
return html`
<ha-md-list-item type="text">
<div class="icon" slot="start">
<div slot="start">
${this.subEntry
? html`
<div class="horizontal-line-wrapper">
@@ -172,9 +172,7 @@ export class HaTargetPickerItemRow extends LitElement {
((entries && (showEntities || showDevices)) || this._domainName)
? html`
<div slot="end" class="summary">
${showEntities &&
!this.expand &&
entries?.referenced_entities.length
${showEntities && !this.expand
? html`<button class="main link" @click=${this._openDetails}>
${this.hass.localize(
"ui.components.target-picker.entities_count",
@@ -608,11 +606,6 @@ export class HaTargetPickerItemRow extends LitElement {
state-badge {
color: var(--ha-color-on-neutral-quiet);
}
.icon {
display: flex;
}
img {
width: 24px;
height: 24px;
@@ -636,6 +629,9 @@ export class HaTargetPickerItemRow extends LitElement {
font-size: var(--ha-font-size-s);
color: var(--secondary-text-color);
}
.domain {
font-family: var(--ha-font-family-code);
}
.entries-tree {
display: flex;

View File

@@ -520,7 +520,6 @@ export class HaTargetPickerSelector extends LitElement {
id=${`list-item-${index}`}
tabindex="-1"
.type=${type === "empty" ? "text" : "button"}
class=${type === "empty" ? "empty" : ""}
@click=${this._handlePickTarget}
.targetType=${type}
.targetId=${type !== "empty" ? item.id : undefined}
@@ -575,7 +574,9 @@ export class HaTargetPickerSelector extends LitElement {
})}
/>
`
: type === "floor"
: type === "area" &&
(item as FloorComboBoxItem).type === "floor" &&
(item as FloorComboBoxItem).floor
? html`<ha-floor-icon
slot="start"
.floor=${(item as FloorComboBoxItem).floor!}
@@ -835,7 +836,7 @@ export class HaTargetPickerSelector extends LitElement {
id: EMPTY_SEARCH,
primary: this.hass.localize(
"ui.components.target-picker.no_target_found",
{ term: html`<div><b>${searchTerm}</b></div>` }
{ term: html`<span class="search-term">"${searchTerm}"</span>` }
),
});
} else if (items.length === 0) {
@@ -1019,14 +1020,10 @@ export class HaTargetPickerSelector extends LitElement {
padding: var(--ha-space-1) var(--ha-space-2);
font-weight: var(--ha-font-weight-bold);
color: var(--secondary-text-color);
min-height: var(--ha-space-6);
display: flex;
align-items: center;
}
.title {
width: 100%;
min-height: var(--ha-space-8);
}
:host([mode="dialog"]) .title {
@@ -1058,6 +1055,7 @@ export class HaTargetPickerSelector extends LitElement {
.filter-header {
opacity: 0;
transition: opacity 300ms ease-in;
position: absolute;
top: 1px;
width: calc(100% - var(--ha-space-8));
@@ -1085,8 +1083,9 @@ export class HaTargetPickerSelector extends LitElement {
width: 100%;
}
.empty {
text-align: center;
.search-term {
color: var(--primary-color);
font-weight: var(--ha-font-weight-medium);
}
`,
];

View File

@@ -218,7 +218,6 @@ export const getAreasAndFloors = (
type: "floor",
primary: floorName,
floor: floor,
icon: floor.icon || undefined,
search_labels: [
floor.floor_id,
floorName,

View File

@@ -37,6 +37,7 @@
flex-direction: column;
justify-content: center;
align-items: center;
view-transition-name: layout-fade-out;
}
#ha-launch-screen svg {
width: 112px;

View File

@@ -61,6 +61,7 @@ class HassLoadingScreen extends LitElement {
display: block;
height: 100%;
background-color: var(--primary-background-color);
view-transition-name: layout-fade-out;
}
.toolbar {
display: flex;

View File

@@ -3,6 +3,7 @@ import { ReactiveElement } from "lit";
import { property } from "lit/decorators";
import memoizeOne from "memoize-one";
import { navigate } from "../common/navigate";
import { ViewTransitionMixin } from "../mixins/view-transition-mixin";
import type { Route } from "../types";
const extractPage = (path: string, defaultPage: string) => {
@@ -43,7 +44,7 @@ export interface RouterOptions {
// Time to wait for code to load before we show loading screen.
const LOADING_SCREEN_THRESHOLD = 400; // ms
export class HassRouterPage extends ReactiveElement {
export class HassRouterPage extends ViewTransitionMixin(ReactiveElement) {
@property({ attribute: false }) public route?: Route;
protected routerOptions!: RouterOptions;
@@ -310,16 +311,19 @@ export class HassRouterPage extends ReactiveElement {
page: string,
routeOptions: RouteOptions
) {
if (this.lastChild) {
this.removeChild(this.lastChild);
}
this.startViewTransition(() => {
if (this.lastChild) {
this.removeChild(this.lastChild);
}
const panelEl = this._cache[page] || this.createElement(routeOptions.tag);
this.updatePageEl(panelEl);
this.appendChild(panelEl);
const panelEl = this._cache[page] || this.createElement(routeOptions.tag);
(panelEl as HTMLElement).style.viewTransitionName = "layout-fade-in";
this.updatePageEl(panelEl);
this.appendChild(panelEl);
if (routerOptions.cacheAll || routeOptions.cache) {
this._cache[page] = panelEl;
}
if (routerOptions.cacheAll || routeOptions.cache) {
this._cache[page] = panelEl;
}
});
}
}

View File

@@ -1,15 +1,17 @@
import type { CSSResultGroup, TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, eventOptions, property } from "lit/decorators";
import { customElement, eventOptions, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { restoreScroll } from "../common/decorators/restore-scroll";
import { goBack } from "../common/navigate";
import "../components/ha-icon-button-arrow-prev";
import "../components/ha-menu-button";
import { haStyleScrollbar } from "../resources/styles";
import { ViewTransitionMixin } from "../mixins/view-transition-mixin";
import { haStyleScrollbar, haStyleViewTransitions } from "../resources/styles";
import type { HomeAssistant } from "../types";
@customElement("hass-subpage")
class HassSubpage extends LitElement {
class HassSubpage extends ViewTransitionMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public header?: string;
@@ -24,9 +26,18 @@ class HassSubpage extends LitElement {
@property({ type: Boolean }) public supervisor = false;
@state() private _loaded = false;
// @ts-ignore
@restoreScroll(".content") private _savedScrollPos?: number;
protected onLoadTransition(): void {
// Trigger the transition when content is slotted
this.startViewTransition(() => {
this._loaded = true;
});
}
protected render(): TemplateResult {
return html`
<div class="toolbar">
@@ -60,7 +71,14 @@ class HassSubpage extends LitElement {
<slot name="toolbar-icon"></slot>
</div>
</div>
<div class="content ha-scrollbar" @scroll=${this._saveScrollPos}>
<div
class=${classMap({
content: true,
"ha-scrollbar": true,
loading: !this._loaded,
})}
@scroll=${this._saveScrollPos}
>
<slot></slot>
</div>
<div id="fab">
@@ -85,6 +103,7 @@ class HassSubpage extends LitElement {
static get styles(): CSSResultGroup {
return [
haStyleScrollbar,
haStyleViewTransitions,
css`
:host {
display: block;
@@ -167,6 +186,10 @@ class HassSubpage extends LitElement {
overflow-y: auto;
overflow: auto;
-webkit-overflow-scrolling: touch;
view-transition-name: layout-fade-in;
}
.content.loading {
opacity: 0;
}
:host([narrow]) .content {
width: calc(

View File

@@ -11,7 +11,8 @@ import "../components/ha-icon-button-arrow-prev";
import "../components/ha-menu-button";
import "../components/ha-svg-icon";
import "../components/ha-tab";
import { haStyleScrollbar } from "../resources/styles";
import { ViewTransitionMixin } from "../mixins/view-transition-mixin";
import { haStyleScrollbar, haStyleViewTransitions } from "../resources/styles";
import type { HomeAssistant, Route } from "../types";
export interface PageNavigation {
@@ -29,7 +30,7 @@ export interface PageNavigation {
}
@customElement("hass-tabs-subpage")
class HassTabsSubpage extends LitElement {
class HassTabsSubpage extends ViewTransitionMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public supervisor = false;
@@ -61,9 +62,18 @@ class HassTabsSubpage extends LitElement {
@state() private _activeTab?: PageNavigation;
@state() private _loaded = false;
// @ts-ignore
@restoreScroll(".content") private _savedScrollPos?: number;
protected onLoadTransition(): void {
// Trigger the transition when content is slotted
this.startViewTransition(() => {
this._loaded = true;
});
}
private _getTabs = memoizeOne(
(
tabs: PageNavigation[],
@@ -185,7 +195,12 @@ class HassTabsSubpage extends LitElement {
</div>`
: nothing}
<div
class="content ha-scrollbar ${classMap({ tabs: showTabs })}"
class=${classMap({
content: true,
"ha-scrollbar": true,
tabs: showTabs,
loading: !this._loaded,
})}
@scroll=${this._saveScrollPos}
>
<slot></slot>
@@ -214,6 +229,7 @@ class HassTabsSubpage extends LitElement {
static get styles(): CSSResultGroup {
return [
haStyleScrollbar,
haStyleViewTransitions,
css`
:host {
display: block;
@@ -332,6 +348,10 @@ class HassTabsSubpage extends LitElement {
margin-bottom: var(--safe-area-inset-bottom);
overflow: auto;
-webkit-overflow-scrolling: touch;
view-transition-name: layout-fade-in;
}
.content.loading {
opacity: 0;
}
:host([narrow]) .content {
margin-left: var(--safe-area-inset-left);

View File

@@ -0,0 +1,94 @@
import type { PropertyValues, ReactiveElement } from "lit";
type AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
export const ViewTransitionMixin = <
T extends AbstractConstructor<ReactiveElement>,
>(
superClass: T
) => {
abstract class ViewTransitionClass extends superClass {
private _slot?: HTMLSlotElement;
private _transitionTriggered = false;
/**
* Trigger a view transition if supported by the browser
* @param updateCallback - Callback function that updates the DOM
* @returns Promise that resolves when the transition is complete
*/
protected async startViewTransition(
updateCallback: () => void | Promise<void>
): Promise<void> {
if (
!document.startViewTransition ||
window.matchMedia("(prefers-reduced-motion: reduce)").matches
) {
// Fallback: update without view transition
await updateCallback();
return;
}
const transition = document.startViewTransition(async () => {
await updateCallback();
});
try {
await transition.finished;
} catch (_error) {
// View transition skipped
}
}
/**
* Optional callback to execute during the load transition
*/
protected onLoadTransition?(): void;
/**
* Check if slot has content and trigger transition if it does
*/
private _checkSlotContent = (): void => {
// Guard against multiple slotchange events triggering the transition multiple times
if (this._transitionTriggered) {
return;
}
if (this._slot) {
const elements = this._slot.assignedElements();
if (elements.length > 0) {
this._transitionTriggered = true;
this.onLoadTransition?.();
}
}
};
/**
* Automatically apply view transition on first render
* @param changedProperties - Properties that changed
*/
protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);
// Wait for slotted content to be ready, then trigger transition
this._slot = this.shadowRoot?.querySelector(
"slot:not([name])"
) as HTMLSlotElement | undefined;
if (this._slot) {
this._checkSlotContent();
this._slot.addEventListener("slotchange", this._checkSlotContent);
} else {
// Start transition immediately if no slot is found
this.onLoadTransition?.();
}
}
override disconnectedCallback(): void {
super.disconnectedCallback();
if (this._slot) {
this._slot.removeEventListener("slotchange", this._checkSlotContent);
}
}
}
return ViewTransitionClass;
};

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { LitElement, html, nothing } from "lit";
@@ -115,9 +115,7 @@ export default class HaAutomationAction extends LitElement {
@click=${stopPropagation}
.index=${idx}
>
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
: nothing}

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
@@ -193,9 +193,7 @@ export default class HaAutomationCondition extends LitElement {
@click=${stopPropagation}
.index=${idx}
>
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
: nothing}

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
@@ -100,9 +100,7 @@ export default class HaAutomationOption extends LitElement {
@click=${stopPropagation}
.index=${idx}
>
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
: nothing}

View File

@@ -1,4 +1,4 @@
import { mdiDragHorizontalVariant, mdiPlus } from "@mdi/js";
import { mdiDrag, mdiPlus } from "@mdi/js";
import deepClone from "deep-clone-simple";
import type { PropertyValues } from "lit";
import { html, LitElement, nothing } from "lit";
@@ -110,9 +110,7 @@ export default class HaAutomationTrigger extends LitElement {
@click=${stopPropagation}
.index=${idx}
>
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
`
: nothing}

View File

@@ -244,8 +244,7 @@ class HaConfigBackupSettings extends LitElement {
`
: nothing}
</div>
${!this.cloudStatus?.logged_in &&
isComponentLoaded(this.hass, "cloud")
${!this.cloudStatus?.logged_in
? html`<ha-card class="cloud-info">
<div class="cloud-header">
<img
@@ -280,10 +279,7 @@ class HaConfigBackupSettings extends LitElement {
"ui.panel.config.voice_assistants.assistants.cloud.sign_in"
)}
</ha-button>
<ha-button
href="/config/cloud/register"
appearance="filled"
>
<ha-button href="/config/cloud/register">
${this.hass.localize(
"ui.panel.config.voice_assistants.assistants.cloud.try_one_month"
)}

View File

@@ -1,10 +1,4 @@
import {
mdiDelete,
mdiDevices,
mdiDragHorizontalVariant,
mdiPencil,
mdiPlus,
} from "@mdi/js";
import { mdiDelete, mdiDevices, mdiDrag, mdiPencil, mdiPlus } from "@mdi/js";
import type { CSSResultGroup, TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { repeat } from "lit/directives/repeat";
@@ -95,9 +89,7 @@ export class EnergyDeviceSettings extends LitElement {
(device) => html`
<div class="row" .device=${device}>
<div class="handle">
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
<span class="content"
>${device.name ||

View File

@@ -1,4 +1,4 @@
import { mdiDelete, mdiDragHorizontalVariant } from "@mdi/js";
import { mdiDelete, mdiDrag } from "@mdi/js";
import type { CSSResultGroup } from "lit";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -111,9 +111,7 @@ class HaInputSelectForm extends LitElement {
<ha-list-item class="option" hasMeta>
<div class="optioncontent">
<div class="handle">
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
${option}
</div>

View File

@@ -9,6 +9,7 @@ import {
import type { PropertyValues } from "lit";
import { LitElement, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import memoize from "memoize-one";
import { isComponentLoaded } from "../../../../common/config/is_component_loaded";
import { storage } from "../../../../common/decorators/storage";
@@ -61,7 +62,7 @@ type DataTableItem = Pick<
> & {
default: boolean;
filename: string;
type: string;
iconColor?: string;
};
@customElement("ha-config-lovelace-dashboards")
@@ -106,20 +107,6 @@ export class HaConfigLovelaceDashboards extends LitElement {
})
private _activeHiddenColumns?: string[];
@storage({
key: "lovelace-dashboards-table-grouping",
state: false,
subscribe: false,
})
private _activeGrouping?: string = "type";
@storage({
key: "lovelace-dashboards-table-collapsed",
state: false,
subscribe: false,
})
private _activeCollapsed: string[] = [];
public willUpdate() {
if (!this.hasUpdated) {
this.hass.loadFragmentTranslation("lovelace");
@@ -145,7 +132,15 @@ export class HaConfigLovelaceDashboards extends LitElement {
template: (dashboard) =>
dashboard.icon
? html`
<ha-icon slot="item-icon" .icon=${dashboard.icon}></ha-icon>
<ha-icon
slot="item-icon"
.icon=${dashboard.icon}
style=${ifDefined(
dashboard.iconColor
? `color: ${dashboard.iconColor}`
: undefined
)}
></ha-icon>
`
: nothing,
},
@@ -182,15 +177,6 @@ export class HaConfigLovelaceDashboards extends LitElement {
},
};
columns.type = {
title: localize(
"ui.panel.config.lovelace.dashboards.picker.headers.type"
),
sortable: true,
groupable: true,
filterable: true,
};
columns.mode = {
title: localize(
"ui.panel.config.lovelace.dashboards.picker.headers.conf_mode"
@@ -301,7 +287,7 @@ export class HaConfigLovelaceDashboards extends LitElement {
url_path: "lovelace",
mode: defaultMode,
filename: defaultMode === "yaml" ? "ui-lovelace.yaml" : "",
type: this._localizeType("built_in"),
iconColor: "var(--primary-color)",
},
];
if (isComponentLoaded(this.hass, "energy")) {
@@ -312,9 +298,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
mode: "storage",
url_path: "energy",
filename: "",
iconColor: "var(--orange-color)",
default: false,
require_admin: false,
type: this._localizeType("built_in"),
});
}
@@ -326,9 +312,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
mode: "storage",
url_path: "light",
filename: "",
iconColor: "var(--amber-color)",
default: false,
require_admin: false,
type: this._localizeType("built_in"),
});
}
@@ -340,9 +326,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
mode: "storage",
url_path: "safety",
filename: "",
iconColor: "var(--blue-grey-color)",
default: false,
require_admin: false,
type: this._localizeType("built_in"),
});
}
@@ -354,9 +340,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
mode: "storage",
url_path: "climate",
filename: "",
iconColor: "var(--deep-orange-color)",
default: false,
require_admin: false,
type: this._localizeType("built_in"),
});
}
@@ -365,25 +351,16 @@ export class HaConfigLovelaceDashboards extends LitElement {
.sort((a, b) =>
stringCompare(a.title, b.title, this.hass.locale.language)
)
.map(
(dashboard) =>
({
filename: "",
...dashboard,
default: defaultUrlPath === dashboard.url_path,
type: this._localizeType("user_created"),
}) satisfies DataTableItem
)
.map((dashboard) => ({
filename: "",
...dashboard,
default: defaultUrlPath === dashboard.url_path,
}))
);
return result;
}
);
private _localizeType = (type: "user_created" | "built_in") =>
this.hass.localize(
`ui.panel.config.lovelace.dashboards.picker.type.${type}`
);
protected render() {
if (!this.hass || this._dashboards === undefined) {
return html` <hass-loading-screen></hass-loading-screen> `;
@@ -403,13 +380,9 @@ export class HaConfigLovelaceDashboards extends LitElement {
this.hass.localize
)}
.data=${this._getItems(this._dashboards, this.hass.defaultPanel)}
.initialGroupColumn=${this._activeGrouping}
.initialCollapsedGroups=${this._activeCollapsed}
.initialSorting=${this._activeSorting}
.columnOrder=${this._activeColumnOrder}
.hiddenColumns=${this._activeHiddenColumns}
@grouping-changed=${this._handleGroupingChanged}
@collapsed-changed=${this._handleCollapseChanged}
@columns-changed=${this._handleColumnsChanged}
@sorting-changed=${this._handleSortingChanged}
.filter=${this._filter}
@@ -470,13 +443,13 @@ export class HaConfigLovelaceDashboards extends LitElement {
}
private _canDelete(urlPath: string) {
return !["lovelace", "energy", "light", "safety", "climate"].includes(
return !["lovelace", "energy", "light", "security", "climate"].includes(
urlPath
);
}
private _canEdit(urlPath: string) {
return !["light", "safety", "climate"].includes(urlPath);
return !["light", "security", "climate"].includes(urlPath);
}
private _handleDelete = async (item: DataTableItem) => {
@@ -598,14 +571,6 @@ export class HaConfigLovelaceDashboards extends LitElement {
this._activeColumnOrder = ev.detail.columnOrder;
this._activeHiddenColumns = ev.detail.hiddenColumns;
}
private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}
private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}
}
declare global {

View File

@@ -11,6 +11,7 @@ import { computeDomain } from "../../../common/entity/compute_domain";
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
import { stateActive } from "../../../common/entity/state_active";
import { stateColorCss } from "../../../common/entity/state_color";
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
import "../../../components/ha-badge";
import "../../../components/ha-ripple";
import "../../../components/ha-state-icon";
@@ -19,7 +20,6 @@ import { cameraUrlWithWidthHeight } from "../../../data/camera";
import type { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
import type { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { computeLovelaceEntityName } from "../common/entity/compute-lovelace-entity-name";
import { findEntities } from "../common/find-entities";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
@@ -162,7 +162,11 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
if (!stateObj) {
return html`
<ha-badge .label=${entityId} class="error">
<ha-svg-icon slot="icon" .path=${mdiAlertCircle}></ha-svg-icon>
<ha-svg-icon
slot="icon"
.hass=${this.hass}
.path=${mdiAlertCircle}
></ha-svg-icon>
${this.hass.localize("ui.badge.entity.not_found")}
</ha-badge>
`;
@@ -175,22 +179,22 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
"--badge-color": color,
};
const name = computeLovelaceEntityName(
this.hass,
stateObj,
this._config.name
);
const stateDisplay = html`
<state-display
.stateObj=${stateObj}
.hass=${this.hass}
.content=${this._config.state_content}
.name=${name}
.name=${this._config.name}
>
</state-display>
`;
const name = computeLovelaceEntityName(
this.hass,
stateObj,
this._config.name
);
const showState = this._config.show_state;
const showName = this._config.show_name;
const showIcon = this._config.show_icon;

View File

@@ -5,7 +5,7 @@ import {
mdiDelete,
mdiDeleteSweep,
mdiDotsVertical,
mdiDragHorizontalVariant,
mdiDrag,
mdiPlus,
mdiSort,
} from "@mdi/js";
@@ -522,7 +522,7 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard {
"ui.panel.lovelace.cards.todo-list.drag_and_drop"
)}
class="reorderButton handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
slot="meta"
>
</ha-svg-icon>

View File

@@ -1,4 +1,4 @@
import { mdiClose, mdiDragHorizontalVariant, mdiPencil } from "@mdi/js";
import { mdiClose, mdiDrag, mdiPencil } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
@@ -66,11 +66,7 @@ export class HuiEntityEditor extends LitElement {
return html`
<ha-md-list-item class="item">
<ha-svg-icon
class="handle"
.path=${mdiDragHorizontalVariant}
slot="start"
></ha-svg-icon>
<ha-svg-icon class="handle" .path=${mdiDrag} slot="start"></ha-svg-icon>
<div slot="headline" class="label">${primary}</div>
${secondary
@@ -156,9 +152,7 @@ export class HuiEntityEditor extends LitElement {
(entityConf, index) => html`
<div class="entity" data-entity-id=${entityConf.entity}>
<div class="handle">
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
<ha-entity-picker
.hass=${this.hass}

View File

@@ -1,4 +1,4 @@
import { mdiDelete, mdiDragHorizontalVariant, mdiPencil } from "@mdi/js";
import { mdiDelete, mdiDrag, mdiPencil } from "@mdi/js";
import type { CSSResultGroup, TemplateResult } from "lit";
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators";
@@ -31,7 +31,7 @@ export class HuiSectionEditMode extends LitElement {
<ha-svg-icon
aria-hidden="true"
class="handle"
.path=${mdiDragHorizontalVariant}
.path=${mdiDrag}
></ha-svg-icon>
<ha-icon-button
.label=${this.hass.localize("ui.common.edit")}

View File

@@ -1,9 +1,4 @@
import {
mdiDelete,
mdiDragHorizontalVariant,
mdiPencil,
mdiPlus,
} from "@mdi/js";
import { mdiDelete, mdiDrag, mdiPencil, mdiPlus } from "@mdi/js";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
@@ -350,9 +345,7 @@ export class HuiCardFeaturesEditor extends LitElement {
return html`
<div class="feature">
<div class="handle">
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
<div class="feature-content">
<div>

View File

@@ -1,10 +1,5 @@
import "@material/mwc-menu/mwc-menu-surface";
import {
mdiDelete,
mdiDragHorizontalVariant,
mdiPencil,
mdiPlus,
} from "@mdi/js";
import { mdiDelete, mdiDrag, mdiPencil, mdiPlus } from "@mdi/js";
import type { ComboBoxLightOpenedChangedEvent } from "@vaadin/combo-box/vaadin-combo-box-light";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
@@ -91,9 +86,7 @@ export class HuiHeadingBadgesEditor extends LitElement {
return html`
<div class="badge">
<div class="handle">
<ha-svg-icon
.path=${mdiDragHorizontalVariant}
></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
<div class="badge-content">
<span>${label}</span>

View File

@@ -1,4 +1,4 @@
import { mdiClose, mdiDragHorizontalVariant, mdiPencil } from "@mdi/js";
import { mdiClose, mdiDrag, mdiPencil } from "@mdi/js";
import { LitElement, css, html, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { repeat } from "lit/directives/repeat";
@@ -59,7 +59,7 @@ export class HuiEntitiesCardRowEditor extends LitElement {
(entityConf, index) => html`
<div class="entity">
<div class="handle">
<ha-svg-icon .path=${mdiDragHorizontalVariant}></ha-svg-icon>
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
</div>
${entityConf.type
? html`

View File

@@ -72,7 +72,8 @@ import {
} from "../../dialogs/quick-bar/show-dialog-quick-bar";
import { showShortcutsDialog } from "../../dialogs/shortcuts/show-shortcuts-dialog";
import { showVoiceCommandDialog } from "../../dialogs/voice-command-dialog/show-ha-voice-command-dialog";
import { haStyle } from "../../resources/styles";
import { ViewTransitionMixin } from "../../mixins/view-transition-mixin";
import { haStyle, haStyleViewTransitions } from "../../resources/styles";
import type { HomeAssistant, PanelInfo } from "../../types";
import { documentationUrl } from "../../util/documentation-url";
import { showToast } from "../../util/toast";
@@ -114,7 +115,7 @@ interface SubActionItem {
}
@customElement("hui-root")
class HUIRoot extends LitElement {
class HUIRoot extends ViewTransitionMixin(LitElement) {
@property({ attribute: false }) public panel?: PanelInfo<LovelacePanelConfig>;
@property({ attribute: false }) public hass!: HomeAssistant;
@@ -130,6 +131,8 @@ class HUIRoot extends LitElement {
@state() private _curView?: number | "hass-unused-entities";
@state() private _loaded = false;
private _viewCache?: Record<string, HUIView>;
private _viewScrollPositions: Record<string, number> = {};
@@ -153,6 +156,10 @@ class HUIRoot extends LitElement {
);
}
protected onLoadTransition(): void {
this._loaded = true;
}
private _renderActionItems(): TemplateResult {
const result: TemplateResult[] = [];
if (this._editMode) {
@@ -493,6 +500,7 @@ class HUIRoot extends LitElement {
class=${classMap({
"edit-mode": this._editMode,
narrow: this.narrow,
loading: !this._loaded,
})}
>
<div class="header">
@@ -1162,43 +1170,45 @@ class HUIRoot extends LitElement {
// Recreate a new element to clear the applied themes.
const root = this._viewRoot;
if (root.lastChild) {
root.removeChild(root.lastChild);
}
this.startViewTransition(() => {
if (root.lastChild) {
root.removeChild(root.lastChild);
}
if (viewIndex === "hass-unused-entities") {
const unusedEntities = document.createElement("hui-unused-entities");
// Wait for promise to resolve so that the element has been upgraded.
import("./editor/unused-entities/hui-unused-entities").then(() => {
unusedEntities.hass = this.hass!;
unusedEntities.lovelace = this.lovelace!;
unusedEntities.narrow = this.narrow;
});
root.appendChild(unusedEntities);
return;
}
if (viewIndex === "hass-unused-entities") {
const unusedEntities = document.createElement("hui-unused-entities");
// Wait for promise to resolve so that the element has been upgraded.
import("./editor/unused-entities/hui-unused-entities").then(() => {
unusedEntities.hass = this.hass!;
unusedEntities.lovelace = this.lovelace!;
unusedEntities.narrow = this.narrow;
});
root.appendChild(unusedEntities);
return;
}
let view;
const viewConfig = this.config.views[viewIndex];
let view;
const viewConfig = this.config.views[viewIndex];
if (!viewConfig) {
this.lovelace!.setEditMode(true);
return;
}
if (!viewConfig) {
this.lovelace!.setEditMode(true);
return;
}
if (!force && this._viewCache![viewIndex]) {
view = this._viewCache![viewIndex];
} else {
view = document.createElement("hui-view");
view.index = viewIndex;
this._viewCache![viewIndex] = view;
}
if (!force && this._viewCache![viewIndex]) {
view = this._viewCache![viewIndex];
} else {
view = document.createElement("hui-view");
view.index = viewIndex;
this._viewCache![viewIndex] = view;
}
view.lovelace = this.lovelace;
view.hass = this.hass;
view.narrow = this.narrow;
view.lovelace = this.lovelace;
view.hass = this.hass;
view.narrow = this.narrow;
root.appendChild(view);
root.appendChild(view);
});
}
private _openShortcutDialog(ev: Event) {
@@ -1209,12 +1219,21 @@ class HUIRoot extends LitElement {
static get styles(): CSSResultGroup {
return [
haStyle,
haStyleViewTransitions,
css`
:host {
-ms-user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
}
@media (prefers-reduced-motion: no-preference) {
::view-transition-new(hui-root-container) {
animation: fade-in var(--ha-animation-layout-duration) ease-out;
animation-delay: var(--ha-animation-layout-delay-base);
}
}
.header {
background-color: var(--app-header-background-color);
color: var(--app-header-text-color, white);
@@ -1403,6 +1422,10 @@ class HUIRoot extends LitElement {
padding-right: var(--safe-area-inset-right);
padding-inline-end: var(--safe-area-inset-right);
padding-bottom: var(--safe-area-inset-bottom);
view-transition-name: hui-root-container;
}
.loading hui-view-container {
opacity: 0;
}
.narrow hui-view-container {
padding-left: var(--safe-area-inset-left);
@@ -1411,6 +1434,7 @@ class HUIRoot extends LitElement {
hui-view-container > * {
flex: 1 1 100%;
max-width: 100%;
view-transition-name: layout-fade-in;
}
/**
* In edit mode we have the tab bar on a new line *

View File

@@ -1,12 +1,8 @@
import { css, LitElement, nothing } from "lit";
import type { PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators";
import { customElement, property } from "lit/decorators";
import type { HomeAssistant } from "../../../types";
import type { LovelaceViewBackgroundConfig } from "../../../data/lovelace/config/view";
import {
isMediaSourceContentId,
resolveMediaSource,
} from "../../../data/media_source";
@customElement("hui-view-background")
export class HUIViewBackground extends LitElement {
@@ -17,27 +13,10 @@ export class HUIViewBackground extends LitElement {
| LovelaceViewBackgroundConfig
| undefined;
@state({ attribute: false }) resolvedImage?: string;
protected render() {
return nothing;
}
private _fetchMedia() {
const backgroundImage =
typeof this.background === "string"
? this.background
: this.background?.image;
if (backgroundImage && isMediaSourceContentId(backgroundImage)) {
resolveMediaSource(this.hass, backgroundImage).then((result) => {
this.resolvedImage = result.url;
});
} else {
this.resolvedImage = undefined;
}
}
private _applyTheme() {
const computedStyles = getComputedStyle(this);
const themeBackground = computedStyles.getPropertyValue(
@@ -73,19 +52,13 @@ export class HUIViewBackground extends LitElement {
background?: string | LovelaceViewBackgroundConfig
) {
if (typeof background === "object" && background.image) {
if (isMediaSourceContentId(background.image) && !this.resolvedImage) {
return null;
}
const alignment = background.alignment ?? "center";
const size = background.size ?? "cover";
const repeat = background.repeat ?? "no-repeat";
return `${alignment} / ${size} ${repeat} url('${this.hass.hassUrl(this.resolvedImage || background.image)}')`;
return `${alignment} / ${size} ${repeat} url('${this.hass.hassUrl(background.image)}')`;
}
if (typeof background === "string") {
if (isMediaSourceContentId(background) && !this.resolvedImage) {
return null;
}
return this.resolvedImage || background;
return background;
}
return null;
}
@@ -117,10 +90,6 @@ export class HUIViewBackground extends LitElement {
if (changedProperties.has("background")) {
this._applyTheme();
this._fetchMedia();
}
if (changedProperties.has("resolvedImage")) {
this._applyTheme();
}
}

View File

@@ -199,3 +199,56 @@ export const baseEntrypointStyles = css`
width: 100vw;
}
`;
export const haStyleViewTransitions = css`
@keyframes fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
@media (prefers-reduced-motion: no-preference) {
/* Prevent root cross-fade during view transitions (pseudo-element) */
::view-transition-old(root) {
animation: none;
}
::view-transition-new(root) {
animation: none;
}
/* Elements leaving the view (loading screen) */
::view-transition-group(layout-fade-out) {
animation-duration: var(--ha-animation-layout-duration);
animation-timing-function: ease-out;
}
::view-transition-old(layout-fade-out) {
animation: fade-out var(--ha-animation-layout-duration) ease-out;
}
::view-transition-new(layout-fade-out) {
animation: none;
}
/* New content entering (panels, subpages)
Uses base delay to be less abrupt and allow for elements to render */
::view-transition-group(layout-fade-in) {
animation-duration: var(--ha-animation-layout-duration);
animation-timing-function: ease-out;
}
::view-transition-new(layout-fade-in) {
animation: fade-in var(--ha-animation-layout-duration) ease-out;
animation-delay: var(--ha-animation-layout-delay-base);
}
}
`;

View File

@@ -155,6 +155,7 @@ export const semanticColorStyles = css`
/* Surfaces */
--ha-color-surface-default: var(--ha-color-neutral-95);
--ha-color-on-surface-default: var(--ha-color-neutral-05);
}
`;
@@ -286,5 +287,6 @@ export const darkSemanticColorStyles = css`
/* Surfaces */
--ha-color-surface-default: var(--ha-color-neutral-10);
--ha-color-on-surface-default: var(--ha-color-neutral-95);
}
`;

View File

@@ -42,6 +42,17 @@ export const coreStyles = css`
--ha-space-18: 72px;
--ha-space-19: 76px;
--ha-space-20: 80px;
/* Animation timing */
--ha-animation-layout-duration: 350ms;
--ha-animation-layout-delay-base: 100ms;
}
@media (prefers-reduced-motion: reduce) {
html {
--ha-animation-layout-duration: 0ms;
--ha-animation-layout-delay-base: 0ms;
}
}
`;

View File

@@ -676,9 +676,6 @@
},
"entity-state-picker": {
"state": "State"
},
"entity-state-content-picker": {
"add": "Add"
}
},
"target-picker": {
@@ -3458,17 +3455,12 @@
"require_admin": "Admin only",
"sidebar": "In sidebar",
"filename": "Filename",
"url": "Open",
"type": "Type"
"url": "Open"
},
"open": "Open",
"edit": "Edit",
"delete": "Delete",
"add_dashboard": "Add dashboard",
"type": {
"user_created": "User created",
"built_in": "Built-in"
}
"add_dashboard": "Add dashboard"
},
"confirm_delete_title": "Delete {dashboard_title}?",
"confirm_delete_text": "This dashboard will be permanently deleted.",

View File

@@ -3,7 +3,20 @@ import { render } from "lit";
export const removeLaunchScreen = () => {
const launchScreenElement = document.getElementById("ha-launch-screen");
if (launchScreenElement) {
if (!launchScreenElement) {
return;
}
// Use View Transition API if available and user doesn't prefer reduced motion
if (
document.startViewTransition &&
!window.matchMedia("(prefers-reduced-motion: reduce)").matches
) {
document.startViewTransition(() => {
launchScreenElement.parentElement!.removeChild(launchScreenElement);
});
} else {
// Fallback: Direct removal without transition
launchScreenElement.parentElement!.removeChild(launchScreenElement);
}
};

View File

@@ -1284,15 +1284,15 @@ __metadata:
languageName: node
linkType: hard
"@codemirror/view@npm:6.38.6, @codemirror/view@npm:^6.0.0, @codemirror/view@npm:^6.17.0, @codemirror/view@npm:^6.23.0, @codemirror/view@npm:^6.27.0":
version: 6.38.6
resolution: "@codemirror/view@npm:6.38.6"
"@codemirror/view@npm:6.38.5, @codemirror/view@npm:^6.0.0, @codemirror/view@npm:^6.17.0, @codemirror/view@npm:^6.23.0, @codemirror/view@npm:^6.27.0":
version: 6.38.5
resolution: "@codemirror/view@npm:6.38.5"
dependencies:
"@codemirror/state": "npm:^6.5.0"
crelt: "npm:^1.0.6"
style-mod: "npm:^4.1.0"
w3c-keyname: "npm:^2.2.4"
checksum: 10/5a047337a98de111817ce8c8d39e6429c90ca0b0a4d2678d6e161e9e5961b1d476a891f447ab7a05cac395d4a93530e7c68bedd93191285265f0742a308ad00b
checksum: 10/2335b593770042eb3adfe369073432b07cd2d15f1e230ae4dc7be7a7b8edd74e57c13e59b92a11e7e5d59ae030aabf7f55478dfec1cf2a2fe3a1ef3f091676a4
languageName: node
linkType: hard
@@ -1942,9 +1942,9 @@ __metadata:
languageName: node
linkType: hard
"@home-assistant/webawesome@npm:3.0.0-beta.6.ha.5":
version: 3.0.0-beta.6.ha.5
resolution: "@home-assistant/webawesome@npm:3.0.0-beta.6.ha.5"
"@home-assistant/webawesome@npm:3.0.0-beta.6.ha.4":
version: 3.0.0-beta.6.ha.4
resolution: "@home-assistant/webawesome@npm:3.0.0-beta.6.ha.4"
dependencies:
"@ctrl/tinycolor": "npm:4.1.0"
"@floating-ui/dom": "npm:^1.6.13"
@@ -1955,7 +1955,7 @@ __metadata:
lit: "npm:^3.2.1"
nanoid: "npm:^5.1.5"
qr-creator: "npm:^1.0.0"
checksum: 10/6bfa5e06b91df06402c348bc19ec59a7fe6ed70080989d60a3c6519f99f5dc72da8b42c5dc2cad9d1ab211c51c4c67a74c0e22f21368da3c9f2565cbf8646a90
checksum: 10/d9072b321126ef458468ed2cf040e0b04cb2aff73336c6e742c0cfb25d9fb674b7672e7c9abcf5bcb0aa0b2fe953c20186f0910f485024c827bfe4cf399f10a4
languageName: node
linkType: hard
@@ -9255,7 +9255,7 @@ __metadata:
"@codemirror/legacy-modes": "npm:6.5.2"
"@codemirror/search": "npm:6.5.11"
"@codemirror/state": "npm:6.5.2"
"@codemirror/view": "npm:6.38.6"
"@codemirror/view": "npm:6.38.5"
"@date-fns/tz": "npm:1.4.1"
"@egjs/hammerjs": "npm:2.0.17"
"@formatjs/intl-datetimeformat": "npm:6.18.2"
@@ -9273,7 +9273,7 @@ __metadata:
"@fullcalendar/list": "npm:6.1.19"
"@fullcalendar/luxon3": "npm:6.1.19"
"@fullcalendar/timegrid": "npm:6.1.19"
"@home-assistant/webawesome": "npm:3.0.0-beta.6.ha.5"
"@home-assistant/webawesome": "npm:3.0.0-beta.6.ha.4"
"@lezer/highlight": "npm:1.2.1"
"@lit-labs/motion": "npm:1.0.9"
"@lit-labs/observers": "npm:2.0.6"