mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-22 09:17:15 +00:00
Compare commits
320 Commits
loading-an
...
update-dro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1be16f1b2c | ||
|
|
be319503f7 | ||
|
|
9b1fe28018 | ||
|
|
0595f722f3 | ||
|
|
1c0315854a | ||
|
|
3b73d7c298 | ||
|
|
2955cb4956 | ||
|
|
c679e312a0 | ||
|
|
37e12a83be | ||
|
|
755c6dbb93 | ||
|
|
4a90331ac7 | ||
|
|
7b264ae338 | ||
|
|
bb5fefce2b | ||
|
|
5703de9616 | ||
|
|
eee2c1e8fd | ||
|
|
d4c1642ccc | ||
|
|
0d693e692a | ||
|
|
c6091971b6 | ||
|
|
60229ceba0 | ||
|
|
e45b631e27 | ||
|
|
ea798cda90 | ||
|
|
259f4421db | ||
|
|
1ac3cf199f | ||
|
|
8d96679cc3 | ||
|
|
ba9c7f3012 | ||
|
|
f8923ed648 | ||
|
|
20d0548d33 | ||
|
|
04aaae20f5 | ||
|
|
852dbbeee0 | ||
|
|
d57367f62e | ||
|
|
47a107dd85 | ||
|
|
3573e823e4 | ||
|
|
1a8319a3ab | ||
|
|
ac23ce6300 | ||
|
|
fc38365958 | ||
|
|
b93bf3bc4b | ||
|
|
869ab6ffc4 | ||
|
|
effba9b918 | ||
|
|
c848673b1f | ||
|
|
074095d3dc | ||
|
|
1bd1e015ff | ||
|
|
7588490419 | ||
|
|
2e80a3ddab | ||
|
|
332694549c | ||
|
|
396ddef722 | ||
|
|
d02804449a | ||
|
|
4ab24cdc72 | ||
|
|
81c27090d2 | ||
|
|
09bdfd3ad7 | ||
|
|
97e49f751c | ||
|
|
e0d241a2db | ||
|
|
83e065ae98 | ||
|
|
a6ee670682 | ||
|
|
c457f92826 | ||
|
|
c73bd96a1f | ||
|
|
711f8e2fc3 | ||
|
|
91a0066544 | ||
|
|
aee7b8b8d4 | ||
|
|
d38d770e1a | ||
|
|
0036679553 | ||
|
|
2b85108242 | ||
|
|
c74320cb82 | ||
|
|
8ebe6e24d2 | ||
|
|
d3182da587 | ||
|
|
41fbc5e44b | ||
|
|
3fea41eb0e | ||
|
|
9a627bdea7 | ||
|
|
d9a67f603d | ||
|
|
5f37f8c0ab | ||
|
|
f222702abf | ||
|
|
2107b7c267 | ||
|
|
1c05afebd7 | ||
|
|
7179bb2d26 | ||
|
|
95cf1fdcf7 | ||
|
|
9617956cc6 | ||
|
|
65df464731 | ||
|
|
bd4e9a3d05 | ||
|
|
963fc13a99 | ||
|
|
ff614918d4 | ||
|
|
48aa5fb970 | ||
|
|
190af65756 | ||
|
|
76911e0e0d | ||
|
|
b8ec7c2e72 | ||
|
|
10e20c2272 | ||
|
|
2ec05aac2f | ||
|
|
61fbe5b53c | ||
|
|
5f3f1c7139 | ||
|
|
48f37b1b1e | ||
|
|
9091df9db5 | ||
|
|
1cd7a1cd78 | ||
|
|
ae5c7026b9 | ||
|
|
3900f3995a | ||
|
|
237f974ee8 | ||
|
|
b2ec4b7d2c | ||
|
|
b4c83d7877 | ||
|
|
22c53b6859 | ||
|
|
750b1e5e16 | ||
|
|
5801ce944c | ||
|
|
79ad9dbf44 | ||
|
|
9814533d47 | ||
|
|
bdb6c684c0 | ||
|
|
0046167f5c | ||
|
|
5266f0d761 | ||
|
|
cc5c0d04c4 | ||
|
|
7f3d5f557f | ||
|
|
9b48cd7737 | ||
|
|
11c6f6ec78 | ||
|
|
cb0f59b26d | ||
|
|
c89fc35578 | ||
|
|
f03cd9c239 | ||
|
|
19a4e37933 | ||
|
|
76514babd5 | ||
|
|
b6abbdafb8 | ||
|
|
d35e6c0092 | ||
|
|
5c2ee54dec | ||
|
|
1dfca76c81 | ||
|
|
fd7f028fbf | ||
|
|
3f7283b1af | ||
|
|
d35323ac52 | ||
|
|
06475382e8 | ||
|
|
b60dd7f15d | ||
|
|
b77e65fabd | ||
|
|
cea691a04e | ||
|
|
50df2a34cd | ||
|
|
e6c0a84994 | ||
|
|
b03fa4bdc5 | ||
|
|
058cecc124 | ||
|
|
a5f058a7eb | ||
|
|
655c2ff3c2 | ||
|
|
e1b0a3e737 | ||
|
|
d59d436080 | ||
|
|
0fe0bf12f2 | ||
|
|
f5a3877f47 | ||
|
|
31d04f5338 | ||
|
|
4f7d223aa7 | ||
|
|
484c60073d | ||
|
|
0e1ab1a60c | ||
|
|
cef11e0c18 | ||
|
|
55e75e80d2 | ||
|
|
126a78ec8a | ||
|
|
063af39f0f | ||
|
|
132c4c8201 | ||
|
|
4c08e960f1 | ||
|
|
a8020256de | ||
|
|
2ea57c33ae | ||
|
|
db1408666c | ||
|
|
260288a061 | ||
|
|
45fd685913 | ||
|
|
896d76b218 | ||
|
|
cec24117dc | ||
|
|
34006d268b | ||
|
|
54c03d91df | ||
|
|
52a56a1c4e | ||
|
|
e49feeb4aa | ||
|
|
a0c30e433a | ||
|
|
354ce027eb | ||
|
|
5c224a942d | ||
|
|
0efa4f81d4 | ||
|
|
3ad2f35f29 | ||
|
|
7a21d5f7bc | ||
|
|
33226587e6 | ||
|
|
bd2673f311 | ||
|
|
cecadde497 | ||
|
|
494b8811d0 | ||
|
|
4e0a49b3da | ||
|
|
3145fed5dc | ||
|
|
3dd040fdc7 | ||
|
|
e3abe9736c | ||
|
|
fe41e72774 | ||
|
|
7078ef52d4 | ||
|
|
f1c9802ee3 | ||
|
|
35697e3f94 | ||
|
|
8ea7ad3026 | ||
|
|
73747fbedc | ||
|
|
aaa92bd354 | ||
|
|
5f75fc5bcb | ||
|
|
5fa44548c3 | ||
|
|
1945c11621 | ||
|
|
930575d292 | ||
|
|
0147dbab00 | ||
|
|
13ace24b83 | ||
|
|
616333591a | ||
|
|
8f5875c30f | ||
|
|
517cd49f35 | ||
|
|
25d9fc94b2 | ||
|
|
7b188759e3 | ||
|
|
76772d1098 | ||
|
|
6052745ca0 | ||
|
|
89b9780345 | ||
|
|
a607edca96 | ||
|
|
52eb3d8063 | ||
|
|
1361fc36bf | ||
|
|
505ef2bd11 | ||
|
|
c0cc66c1ab | ||
|
|
7cfbc521c7 | ||
|
|
e064ce56cc | ||
|
|
8d688aa3a9 | ||
|
|
d122483449 | ||
|
|
f17bbc3f79 | ||
|
|
c88f8fcce0 | ||
|
|
8efabde916 | ||
|
|
e821e1ec83 | ||
|
|
dc7516da94 | ||
|
|
a545a377a7 | ||
|
|
3634dbcbbf | ||
|
|
75af4f939e | ||
|
|
453a2ac7f3 | ||
|
|
8fbd0226fc | ||
|
|
2a8d935601 | ||
|
|
a6328fb6d7 | ||
|
|
a78b61006f | ||
|
|
d506aa23b6 | ||
|
|
48b4df43ab | ||
|
|
8cdcd9cb55 | ||
|
|
a1e2ac1d99 | ||
|
|
8ecddbc42c | ||
|
|
6f70ef52a5 | ||
|
|
7dff02d7c8 | ||
|
|
8bbd7a6a06 | ||
|
|
5c73a06f76 | ||
|
|
9943dae82c | ||
|
|
70bf049df0 | ||
|
|
f9d9fbb7f0 | ||
|
|
9cb84d3f37 | ||
|
|
c1bcf27cf8 | ||
|
|
164ec2a9b5 | ||
|
|
20001a551c | ||
|
|
b7f85bf733 | ||
|
|
b303e9441b | ||
|
|
8f4bd0f620 | ||
|
|
596346bf59 | ||
|
|
769cea92aa | ||
|
|
f825016514 | ||
|
|
c6fd45bd6a | ||
|
|
6c4f4af75c | ||
|
|
cd5c3ef2f6 | ||
|
|
636a6fa02e | ||
|
|
21b83426d6 | ||
|
|
c139ec22f9 | ||
|
|
a6ef3a26da | ||
|
|
221ca56121 | ||
|
|
4e6e3629a8 | ||
|
|
fe94ae0243 | ||
|
|
8a1a22d4bd | ||
|
|
153a578986 | ||
|
|
04bb10d0a2 | ||
|
|
35e52de2c1 | ||
|
|
b0862fddaa | ||
|
|
77735f5310 | ||
|
|
e388756533 | ||
|
|
e9ca9bb781 | ||
|
|
e48918442c | ||
|
|
52f37f41f0 | ||
|
|
4687006fec | ||
|
|
aca4ca3066 | ||
|
|
3a2c00622a | ||
|
|
3e749ec085 | ||
|
|
ee2ec00069 | ||
|
|
0aa2941868 | ||
|
|
46cd1d5156 | ||
|
|
07a5c41fd4 | ||
|
|
4ad3c553d5 | ||
|
|
d40cc448a5 | ||
|
|
e2f3f9d348 | ||
|
|
98d44950f8 | ||
|
|
8ae9edb1ef | ||
|
|
84c4396c13 | ||
|
|
2b937a30e3 | ||
|
|
b7815bfd86 | ||
|
|
d94fa03411 | ||
|
|
0a7007ef9e | ||
|
|
dd12136dee | ||
|
|
6e2f89fe3d | ||
|
|
092085b9af | ||
|
|
1c06eb8661 | ||
|
|
c7e87b06b5 | ||
|
|
38c738c199 | ||
|
|
e899587307 | ||
|
|
c9feb0b75f | ||
|
|
10718c35d1 | ||
|
|
4dc6a37bad | ||
|
|
ac49fc7aba | ||
|
|
e4f008800b | ||
|
|
0b0ffd7bab | ||
|
|
dfa77526a2 | ||
|
|
9a3bd6c613 | ||
|
|
1161de5746 | ||
|
|
9df8e20391 | ||
|
|
11047a9c95 | ||
|
|
18fa66f61c | ||
|
|
758a048f34 | ||
|
|
ee0fc360b0 | ||
|
|
4012f95ec1 | ||
|
|
0336ce4606 | ||
|
|
9ba36ab7e2 | ||
|
|
fe7a08a1b0 | ||
|
|
87a8f9cedc | ||
|
|
01df7e20ca | ||
|
|
d181219522 | ||
|
|
6ae24b8135 | ||
|
|
8e009f24f9 | ||
|
|
53031f44ac | ||
|
|
af5a988457 | ||
|
|
bab0391a19 | ||
|
|
444123c47e | ||
|
|
f123d34046 | ||
|
|
1b40f99f68 | ||
|
|
b314b3ed2b | ||
|
|
59b8932969 | ||
|
|
107af753ec | ||
|
|
1f0acb3046 | ||
|
|
431e533929 | ||
|
|
02c845cbc6 | ||
|
|
628111ed20 | ||
|
|
e825a9c02f | ||
|
|
7a35bddf36 | ||
|
|
ad69270af8 | ||
|
|
404edf9483 | ||
|
|
a166b4e9b6 | ||
|
|
7a285f11db |
183
.github/copilot-instructions.md
vendored
183
.github/copilot-instructions.md
vendored
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
You are an assistant helping with development of the Home Assistant frontend. The frontend is built using Lit-based Web Components and TypeScript, providing a responsive and performant interface for home automation control.
|
You are an assistant helping with development of the Home Assistant frontend. The frontend is built using Lit-based Web Components and TypeScript, providing a responsive and performant interface for home automation control.
|
||||||
|
|
||||||
|
**Note**: This file contains high-level guidelines and references to implementation patterns. For detailed component documentation, API references, and usage examples, refer to the `gallery/` directory.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Quick Reference](#quick-reference)
|
- [Quick Reference](#quick-reference)
|
||||||
@@ -151,6 +153,10 @@ try {
|
|||||||
### Styling Guidelines
|
### Styling Guidelines
|
||||||
|
|
||||||
- **Use CSS custom properties**: Leverage the theme system
|
- **Use CSS custom properties**: Leverage the theme system
|
||||||
|
- **Use spacing tokens**: Prefer `--ha-space-*` tokens over hardcoded values for consistent spacing
|
||||||
|
- Spacing scale: `--ha-space-0` (0px) through `--ha-space-20` (80px) in 4px increments
|
||||||
|
- Defined in `src/resources/theme/core.globals.ts`
|
||||||
|
- Common values: `--ha-space-2` (8px), `--ha-space-4` (16px), `--ha-space-8` (32px)
|
||||||
- **Mobile-first responsive**: Design for mobile, enhance for desktop
|
- **Mobile-first responsive**: Design for mobile, enhance for desktop
|
||||||
- **Follow Material Design**: Use Material Web Components where appropriate
|
- **Follow Material Design**: Use Material Web Components where appropriate
|
||||||
- **Support RTL**: Ensure all layouts work in RTL languages
|
- **Support RTL**: Ensure all layouts work in RTL languages
|
||||||
@@ -159,21 +165,68 @@ try {
|
|||||||
static get styles() {
|
static get styles() {
|
||||||
return css`
|
return css`
|
||||||
:host {
|
:host {
|
||||||
--spacing: 16px;
|
padding: var(--ha-space-4);
|
||||||
padding: var(--spacing);
|
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
background-color: var(--card-background-color);
|
background-color: var(--card-background-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
gap: var(--ha-space-2);
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
:host {
|
:host {
|
||||||
--spacing: 8px;
|
padding: var(--ha-space-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### View Transitions
|
||||||
|
|
||||||
|
The View Transitions API creates smooth animations between DOM state changes. When implementing view transitions:
|
||||||
|
|
||||||
|
**Core Resources:**
|
||||||
|
|
||||||
|
- **Utility wrapper**: `src/common/util/view-transition.ts` - `withViewTransition()` function with graceful fallback
|
||||||
|
- **Real-world example**: `src/util/launch-screen.ts` - Launch screen fade pattern with browser support detection
|
||||||
|
- **Animation keyframes**: `src/resources/theme/animations.globals.ts` - Global `fade-in`, `fade-out`, `scale` animations
|
||||||
|
- **Animation duration**: `src/resources/theme/core.globals.ts` - `--ha-animation-base-duration` (350ms, respects `prefers-reduced-motion`)
|
||||||
|
|
||||||
|
**Implementation Guidelines:**
|
||||||
|
|
||||||
|
1. Always use `withViewTransition()` wrapper for automatic fallback
|
||||||
|
2. Keep transitions simple (subtle crossfades and fades work best)
|
||||||
|
3. Use `--ha-animation-base-duration` CSS variable for consistent timing
|
||||||
|
4. Assign unique `view-transition-name` to elements (must be unique at any given time)
|
||||||
|
5. For Lit components: Override `performUpdate()` or use `::part()` for internal elements
|
||||||
|
|
||||||
|
**Default Root Transition:**
|
||||||
|
|
||||||
|
By default, `:root` receives `view-transition-name: root`, creating a full-page crossfade. Target with [`::view-transition-group(root)`](https://developer.mozilla.org/en-US/docs/Web/CSS/::view-transition-group) to customize the default page transition.
|
||||||
|
|
||||||
|
**Important Constraints:**
|
||||||
|
|
||||||
|
- Each `view-transition-name` must be unique at any given time
|
||||||
|
- Only one view transition can run at a time
|
||||||
|
- **Shadow DOM incompatibility**: View transitions operate at document level and do not work within Shadow DOM due to style isolation ([spec discussion](https://github.com/w3c/csswg-drafts/issues/10303)). For web components, set `view-transition-name` on the `:host` element or use document-level transitions
|
||||||
|
|
||||||
|
**Current Usage & Planned Applications:**
|
||||||
|
|
||||||
|
- Launch screen fade out (implemented)
|
||||||
|
- Automation sidebar transitions (planned - #27238)
|
||||||
|
- More info dialog content changes (planned - #27672)
|
||||||
|
- Toolbar navigation, ha-spinner transitions (planned)
|
||||||
|
|
||||||
|
**Specification & Documentation:**
|
||||||
|
|
||||||
|
For browser support, API details, and current specifications, refer to these authoritative sources (note: check publication dates as specs evolve):
|
||||||
|
|
||||||
|
- [MDN: View Transition API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) - Comprehensive API reference
|
||||||
|
- [Chrome for Developers: View Transitions](https://developer.chrome.com/docs/web-platform/view-transitions) - Implementation guide and examples
|
||||||
|
- [W3C Draft Specification](https://drafts.csswg.org/css-view-transitions/) - Official specification (evolving)
|
||||||
|
|
||||||
### Performance Best Practices
|
### Performance Best Practices
|
||||||
|
|
||||||
- **Code split**: Split code at the panel/dialog level
|
- **Code split**: Split code at the panel/dialog level
|
||||||
@@ -195,8 +248,9 @@ static get styles() {
|
|||||||
|
|
||||||
**Available Dialog Types:**
|
**Available Dialog Types:**
|
||||||
|
|
||||||
- `ha-md-dialog` - Preferred for new code (Material Design 3)
|
- `ha-wa-dialog` - Preferred for new dialogs (Web Awesome based)
|
||||||
- `ha-dialog` - Legacy component still widely used
|
- `ha-md-dialog` - Material Design 3 dialog component
|
||||||
|
- `ha-dialog` - Legacy component (still widely used)
|
||||||
|
|
||||||
**Opening Dialogs (Fire Event Pattern - Recommended):**
|
**Opening Dialogs (Fire Event Pattern - Recommended):**
|
||||||
|
|
||||||
@@ -211,15 +265,45 @@ fireEvent(this, "show-dialog", {
|
|||||||
**Dialog Implementation Requirements:**
|
**Dialog Implementation Requirements:**
|
||||||
|
|
||||||
- Implement `HassDialog<T>` interface
|
- Implement `HassDialog<T>` interface
|
||||||
- Use `createCloseHeading()` for standard headers
|
- Use `@state() private _open = false` to control dialog visibility
|
||||||
- Import `haStyleDialog` for consistent styling
|
- Set `_open = true` in `showDialog()`, `_open = false` in `closeDialog()`
|
||||||
- Return `nothing` when no params (loading state)
|
- Return `nothing` when no params (loading state)
|
||||||
- Fire `dialog-closed` event when closing
|
- Fire `dialog-closed` event in `_dialogClosed()` handler
|
||||||
- Add `dialogInitialFocus` for accessibility
|
- Use `header-title` attribute for simple titles
|
||||||
|
- Use `header-subtitle` attribute for simple subtitles
|
||||||
|
- Use slots for custom content where the standard attributes are not enough
|
||||||
|
- Use `ha-dialog-footer` with `primaryAction`/`secondaryAction` slots for footer content
|
||||||
|
- Add `autofocus` to first focusable element (e.g., `<ha-form autofocus>`). The component may need to forward this attribute internally.
|
||||||
|
|
||||||
````
|
**Dialog Sizing:**
|
||||||
|
|
||||||
|
- Use `width` attribute with predefined sizes: `"small"` (320px), `"medium"` (560px - default), `"large"` (720px), or `"full"`
|
||||||
|
- Custom sizing is NOT recommended - use the standard width presets
|
||||||
|
- Example: `<ha-wa-dialog width="small">` for alert/confirmation dialogs
|
||||||
|
|
||||||
|
**Button Appearance Guidelines:**
|
||||||
|
|
||||||
|
- **Primary action buttons**: Default appearance (no appearance attribute) or omit for standard styling
|
||||||
|
- **Secondary action buttons**: Use `appearance="plain"` for cancel/dismiss actions
|
||||||
|
- **Destructive actions**: Use `appearance="filled"` for delete/remove operations (combined with appropriate semantic styling)
|
||||||
|
- **Button sizes**: Use `size="small"` (32px height) or default/medium (40px height)
|
||||||
|
- Always place primary action in `slot="primaryAction"` and secondary in `slot="secondaryAction"` within `ha-dialog-footer`
|
||||||
|
|
||||||
|
**Recent Examples:**
|
||||||
|
|
||||||
|
See these files for current patterns:
|
||||||
|
|
||||||
|
- `src/panels/config/repairs/dialog-repairs-issue.ts`
|
||||||
|
- `src/dialogs/restart/dialog-restart.ts`
|
||||||
|
- `src/panels/config/lovelace/resources/dialog-lovelace-resource-detail.ts`
|
||||||
|
|
||||||
|
**Gallery Documentation:**
|
||||||
|
|
||||||
|
- `gallery/src/pages/components/ha-wa-dialog.markdown`
|
||||||
|
- `gallery/src/pages/components/ha-dialogs.markdown`
|
||||||
|
|
||||||
### Form Component (ha-form)
|
### Form Component (ha-form)
|
||||||
|
|
||||||
- Schema-driven using `HaFormSchema[]`
|
- Schema-driven using `HaFormSchema[]`
|
||||||
- Supports entity, device, area, target, number, boolean, time, action, text, object, select, icon, media, location selectors
|
- Supports entity, device, area, target, number, boolean, time, action, text, object, select, icon, media, location selectors
|
||||||
- Built-in validation with error display
|
- Built-in validation with error display
|
||||||
@@ -235,7 +319,11 @@ fireEvent(this, "show-dialog", {
|
|||||||
.computeLabel=${(schema) => this.hass.localize(`ui.panel.${schema.name}`)}
|
.computeLabel=${(schema) => this.hass.localize(`ui.panel.${schema.name}`)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
````
|
```
|
||||||
|
|
||||||
|
**Gallery Documentation:**
|
||||||
|
|
||||||
|
- `gallery/src/pages/components/ha-form.markdown`
|
||||||
|
|
||||||
### Alert Component (ha-alert)
|
### Alert Component (ha-alert)
|
||||||
|
|
||||||
@@ -249,6 +337,35 @@ fireEvent(this, "show-dialog", {
|
|||||||
<ha-alert alert-type="success" dismissable>Success message</ha-alert>
|
<ha-alert alert-type="success" dismissable>Success message</ha-alert>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Gallery Documentation:**
|
||||||
|
|
||||||
|
- `gallery/src/pages/components/ha-alert.markdown`
|
||||||
|
|
||||||
|
### Keyboard Shortcuts (ShortcutManager)
|
||||||
|
|
||||||
|
The `ShortcutManager` class provides a unified way to register keyboard shortcuts with automatic input field protection.
|
||||||
|
|
||||||
|
**Key Features:**
|
||||||
|
|
||||||
|
- Automatically blocks shortcuts when input fields are focused
|
||||||
|
- Prevents shortcuts during text selection (configurable via `allowWhenTextSelected`)
|
||||||
|
- Supports both character-based and KeyCode-based shortcuts (for non-latin keyboards)
|
||||||
|
|
||||||
|
**Implementation:**
|
||||||
|
|
||||||
|
- **Class definition**: `src/common/keyboard/shortcuts.ts`
|
||||||
|
- **Real-world example**: `src/state/quick-bar-mixin.ts` - Global shortcuts (e, c, d, m, a, Shift+?) with non-latin keyboard fallbacks
|
||||||
|
|
||||||
|
### Tooltip Component (ha-tooltip)
|
||||||
|
|
||||||
|
The `ha-tooltip` component wraps Web Awesome tooltip with Home Assistant theming. Use for providing contextual help text on hover.
|
||||||
|
|
||||||
|
**Implementation:**
|
||||||
|
|
||||||
|
- **Component definition**: `src/components/ha-tooltip.ts`
|
||||||
|
- **Usage example**: `src/components/ha-label.ts`
|
||||||
|
- **Gallery documentation**: `gallery/src/pages/components/ha-tooltip.markdown`
|
||||||
|
|
||||||
## Common Patterns
|
## Common Patterns
|
||||||
|
|
||||||
### Creating a Panel
|
### Creating a Panel
|
||||||
@@ -289,11 +406,19 @@ export class DialogMyFeature
|
|||||||
@state()
|
@state()
|
||||||
private _params?: MyDialogParams;
|
private _params?: MyDialogParams;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _open = false;
|
||||||
|
|
||||||
public async showDialog(params: MyDialogParams): Promise<void> {
|
public async showDialog(params: MyDialogParams): Promise<void> {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
this._open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog(): void {
|
public closeDialog(): void {
|
||||||
|
this._open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dialogClosed(): void {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
@@ -304,23 +429,27 @@ export class DialogMyFeature
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-dialog
|
<ha-wa-dialog
|
||||||
open
|
.hass=${this.hass}
|
||||||
@closed=${this.closeDialog}
|
.open=${this._open}
|
||||||
.heading=${createCloseHeading(this.hass, this._params.title)}
|
header-title=${this._params.title}
|
||||||
|
header-subtitle=${this._params.subtitle}
|
||||||
|
@closed=${this._dialogClosed}
|
||||||
>
|
>
|
||||||
<!-- Dialog content -->
|
<p>Dialog content</p>
|
||||||
<ha-button
|
<ha-dialog-footer slot="footer">
|
||||||
appearance="plain"
|
<ha-button
|
||||||
@click=${this.closeDialog}
|
slot="secondaryAction"
|
||||||
slot="secondaryAction"
|
appearance="plain"
|
||||||
>
|
@click=${this.closeDialog}
|
||||||
${this.hass.localize("ui.common.cancel")}
|
>
|
||||||
</ha-button>
|
${this.hass.localize("ui.common.cancel")}
|
||||||
<ha-button @click=${this._submit} slot="primaryAction">
|
</ha-button>
|
||||||
${this.hass.localize("ui.common.save")}
|
<ha-button slot="primaryAction" @click=${this._submit}>
|
||||||
</ha-button>
|
${this.hass.localize("ui.common.save")}
|
||||||
</ha-dialog>
|
</ha-button>
|
||||||
|
</ha-dialog-footer>
|
||||||
|
</ha-wa-dialog>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/ci.yaml
vendored
4
.github/workflows/ci.yaml
vendored
@@ -89,7 +89,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
IS_TEST: "true"
|
IS_TEST: "true"
|
||||||
- name: Upload bundle stats
|
- name: Upload bundle stats
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: frontend-bundle-stats
|
name: frontend-bundle-stats
|
||||||
path: build/stats/*.json
|
path: build/stats/*.json
|
||||||
@@ -113,7 +113,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
IS_TEST: "true"
|
IS_TEST: "true"
|
||||||
- name: Upload bundle stats
|
- name: Upload bundle stats
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: supervisor-bundle-stats
|
name: supervisor-bundle-stats
|
||||||
path: build/stats/*.json
|
path: build/stats/*.json
|
||||||
|
|||||||
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -36,14 +36,14 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
uses: github/codeql-action/init@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
uses: github/codeql-action/autobuild@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -57,4 +57,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
|
uses: github/codeql-action/analyze@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
|
||||||
|
|||||||
4
.github/workflows/nightly.yaml
vendored
4
.github/workflows/nightly.yaml
vendored
@@ -57,14 +57,14 @@ jobs:
|
|||||||
run: tar -czvf translations.tar.gz translations
|
run: tar -czvf translations.tar.gz translations
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: wheels
|
name: wheels
|
||||||
path: dist/home_assistant_frontend*.whl
|
path: dist/home_assistant_frontend*.whl
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: Upload translations
|
- name: Upload translations
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||||
with:
|
with:
|
||||||
name: translations
|
name: translations
|
||||||
path: translations.tar.gz
|
path: translations.tar.gz
|
||||||
|
|||||||
2
.github/workflows/relative-ci.yaml
vendored
2
.github/workflows/relative-ci.yaml
vendored
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Send bundle stats and build information to RelativeCI
|
- name: Send bundle stats and build information to RelativeCI
|
||||||
uses: relative-ci/agent-action@8504826a02078b05756e4c07e380023cc2c4274a # v3.1.0
|
uses: relative-ci/agent-action@feb19ddc698445db27401f1490f6ac182da0816f # v3.2.0
|
||||||
with:
|
with:
|
||||||
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
key: ${{ secrets[format('RELATIVE_CI_KEY_{0}_{1}', matrix.bundle, matrix.build)] }}
|
||||||
token: ${{ github.token }}
|
token: ${{ github.token }}
|
||||||
|
|||||||
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
@@ -55,7 +55,7 @@ jobs:
|
|||||||
script/release
|
script/release
|
||||||
|
|
||||||
- name: Upload release assets
|
- name: Upload release assets
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
dist/*.whl
|
dist/*.whl
|
||||||
@@ -108,7 +108,7 @@ jobs:
|
|||||||
- name: Tar folder
|
- name: Tar folder
|
||||||
run: tar -czf landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz -C landing-page/dist .
|
run: tar -czf landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz -C landing-page/dist .
|
||||||
- name: Upload release asset
|
- name: Upload release asset
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz
|
files: landing-page/home_assistant_frontend_landingpage-${{ github.event.release.tag_name }}.tar.gz
|
||||||
|
|
||||||
@@ -137,6 +137,6 @@ jobs:
|
|||||||
- name: Tar folder
|
- name: Tar folder
|
||||||
run: tar -czf hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz -C hassio/build .
|
run: tar -czf hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz -C hassio/build .
|
||||||
- name: Upload release asset
|
- name: Upload release asset
|
||||||
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
|
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
||||||
with:
|
with:
|
||||||
files: hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz
|
files: hassio/home_assistant_frontend_supervisor-${{ github.event.release.tag_name }}.tar.gz
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -6,4 +6,4 @@ enableGlobalCache: false
|
|||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-4.10.3.cjs
|
yarnPath: .yarn/releases/yarn-4.11.0.cjs
|
||||||
|
|||||||
@@ -18,16 +18,16 @@ module.exports.sourceMapURL = () => {
|
|||||||
module.exports.ignorePackages = () => [];
|
module.exports.ignorePackages = () => [];
|
||||||
|
|
||||||
// Files from NPM packages that we should replace with empty file
|
// Files from NPM packages that we should replace with empty file
|
||||||
module.exports.emptyPackages = ({ isHassioBuild }) =>
|
module.exports.emptyPackages = ({ isHassioBuild, isLandingPageBuild }) =>
|
||||||
[
|
[
|
||||||
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
|
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
|
||||||
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
|
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
|
||||||
// Icons in supervisor conflict with icons in HA so we don't load.
|
// Icons in supervisor conflict with icons in HA so we don't load.
|
||||||
isHassioBuild &&
|
(isHassioBuild || isLandingPageBuild) &&
|
||||||
require.resolve(
|
require.resolve(
|
||||||
path.resolve(paths.root_dir, "src/components/ha-icon.ts")
|
path.resolve(paths.root_dir, "src/components/ha-icon.ts")
|
||||||
),
|
),
|
||||||
isHassioBuild &&
|
(isHassioBuild || isLandingPageBuild) &&
|
||||||
require.resolve(
|
require.resolve(
|
||||||
path.resolve(paths.root_dir, "src/components/ha-icon-picker.ts")
|
path.resolve(paths.root_dir, "src/components/ha-icon-picker.ts")
|
||||||
),
|
),
|
||||||
@@ -337,6 +337,7 @@ module.exports.config = {
|
|||||||
publicPath: publicPath(latestBuild),
|
publicPath: publicPath(latestBuild),
|
||||||
isProdBuild,
|
isProdBuild,
|
||||||
latestBuild,
|
latestBuild,
|
||||||
|
isLandingPageBuild: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const createRspackConfig = ({
|
|||||||
isStatsBuild,
|
isStatsBuild,
|
||||||
isTestBuild,
|
isTestBuild,
|
||||||
isHassioBuild,
|
isHassioBuild,
|
||||||
|
isLandingPageBuild,
|
||||||
dontHash,
|
dontHash,
|
||||||
}) => {
|
}) => {
|
||||||
if (!dontHash) {
|
if (!dontHash) {
|
||||||
@@ -168,7 +169,9 @@ const createRspackConfig = ({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new rspack.NormalModuleReplacementPlugin(
|
new rspack.NormalModuleReplacementPlugin(
|
||||||
new RegExp(bundle.emptyPackages({ isHassioBuild }).join("|")),
|
new RegExp(
|
||||||
|
bundle.emptyPackages({ isHassioBuild, isLandingPageBuild }).join("|")
|
||||||
|
),
|
||||||
path.resolve(paths.root_dir, "src/util/empty.js")
|
path.resolve(paths.root_dir, "src/util/empty.js")
|
||||||
),
|
),
|
||||||
!isProdBuild && new LogStartCompilePlugin(),
|
!isProdBuild && new LogStartCompilePlugin(),
|
||||||
@@ -257,7 +260,6 @@ const createRspackConfig = ({
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
experiments: {
|
experiments: {
|
||||||
layers: true,
|
|
||||||
outputModule: true,
|
outputModule: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import {
|
|||||||
} from "../../../../src/common/auth/token_storage";
|
} from "../../../../src/common/auth/token_storage";
|
||||||
import { atLeastVersion } from "../../../../src/common/config/version";
|
import { atLeastVersion } from "../../../../src/common/config/version";
|
||||||
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
|
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
|
||||||
|
import "../../../../src/components/ha-button";
|
||||||
import "../../../../src/components/ha-icon";
|
import "../../../../src/components/ha-icon";
|
||||||
import "../../../../src/components/ha-list";
|
import "../../../../src/components/ha-list";
|
||||||
import "../../../../src/components/ha-button";
|
|
||||||
import "../../../../src/components/ha-list-item";
|
import "../../../../src/components/ha-list-item";
|
||||||
import "../../../../src/components/ha-svg-icon";
|
import "../../../../src/components/ha-svg-icon";
|
||||||
import {
|
import {
|
||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
import { isStrategyDashboard } from "../../../../src/data/lovelace/config/types";
|
import { isStrategyDashboard } from "../../../../src/data/lovelace/config/types";
|
||||||
import type { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
import type { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
||||||
import "../../../../src/layouts/hass-loading-screen";
|
import "../../../../src/layouts/hass-loading-screen";
|
||||||
import { generateDefaultViewConfig } from "../../../../src/panels/lovelace/common/generate-lovelace-config";
|
|
||||||
import "./hc-layout";
|
import "./hc-layout";
|
||||||
|
|
||||||
@customElement("hc-cast")
|
@customElement("hc-cast")
|
||||||
@@ -96,7 +95,9 @@ class HcCast extends LitElement {
|
|||||||
<ha-list @action=${this._handlePickView} activatable>
|
<ha-list @action=${this._handlePickView} activatable>
|
||||||
${(
|
${(
|
||||||
this.lovelaceViews ?? [
|
this.lovelaceViews ?? [
|
||||||
generateDefaultViewConfig({}, {}, {}, {}, () => ""),
|
{
|
||||||
|
title: "Home",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
).map(
|
).map(
|
||||||
(view, idx) => html`
|
(view, idx) => html`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { css, html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import "../../../../src/components/ha-card";
|
import "../../../../src/components/ha-card";
|
||||||
import "../../../../src/components/ha-yaml-editor";
|
import "../../../../src/components/ha-yaml-editor";
|
||||||
import type { Trigger } from "../../../../src/data/automation";
|
import type { LegacyTrigger } from "../../../../src/data/automation";
|
||||||
import { describeTrigger } from "../../../../src/data/automation_i18n";
|
import { describeTrigger } from "../../../../src/data/automation_i18n";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
@@ -66,7 +66,7 @@ const triggers = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const initialTrigger: Trigger = {
|
const initialTrigger: LegacyTrigger = {
|
||||||
trigger: "state",
|
trigger: "state",
|
||||||
entity_id: "light.kitchen",
|
entity_id: "light.kitchen",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ subtitle: Dialogs provide important prompts in a user flow.
|
|||||||
|
|
||||||
# Material Design 3
|
# Material Design 3
|
||||||
|
|
||||||
Our dialogs are based on the latest version of Material Design. Please note that we have made some well-considered adjustments to these guideliness. Specs and guidelines can be found on its [website](https://m3.material.io/components/dialogs/overview).
|
Our dialogs are based on the latest version of Material Design. Please note that we have made some well-considered adjustments to these guidelines. Specs and guidelines can be found on its [website](https://m3.material.io/components/dialogs/overview).
|
||||||
|
|
||||||
# Guidelines
|
# Guidelines
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
- Dialogs have a max width of 560px. Alert and confirmation dialogs got a fixed width of 320px. If you need more width, consider a dedicated page instead.
|
- Dialogs have a max width of 560px. Alert and confirmation dialogs have a fixed width of 320px. If you need more width, consider a dedicated page instead.
|
||||||
- The close X-icon is on the top left, on all screen sizes. Except for alert and confirmation dialogs, they only have buttons and no X-icon. This is different compared to the Material guideliness.
|
- The close X-icon is on the top left, on all screen sizes. Except for alert and confirmation dialogs, they only have buttons and no X-icon. This is different compared to the Material guidelines.
|
||||||
- Dialogs can't be closed with ESC or clicked outside of the dialog when there is a form that the user needs to fill out. Instead it will animate "no" by a little shake.
|
- Dialogs can't be closed with ESC or clicked outside of the dialog when there is a form that the user needs to fill out. Instead it will animate "no" by a little shake.
|
||||||
- Extra icon buttons are on the top right, for example help, settings and expand dialog. More than 2 icon buttons, they will be in an overflow menu.
|
- Extra icon buttons are on the top right, for example help, settings and expand dialog. More than 2 icon buttons, they will be in an overflow menu.
|
||||||
- The submit button is grouped with a cancel button at the bottom right, on all screen sizes. Fullscreen mobile dialogs have them sticky at the bottom.
|
- The submit button is grouped with a cancel button at the bottom right, on all screen sizes. Fullscreen mobile dialogs have them sticky at the bottom.
|
||||||
@@ -26,7 +26,7 @@ Our dialogs are based on the latest version of Material Design. Please note that
|
|||||||
|
|
||||||
- A best practice is to always use a title, even if it is optional by Material guidelines.
|
- A best practice is to always use a title, even if it is optional by Material guidelines.
|
||||||
- People mainly read the title and a button. Put the most important information in those two.
|
- People mainly read the title and a button. Put the most important information in those two.
|
||||||
- Try to avoid user generated content in the title, this could make the title unreadable long.
|
- Try to avoid user generated content in the title, this could make the title unreadably long.
|
||||||
- If users become unsure, they read the description. Make sure this explains what will happen.
|
- If users become unsure, they read the description. Make sure this explains what will happen.
|
||||||
- Strive for minimalism.
|
- Strive for minimalism.
|
||||||
|
|
||||||
|
|||||||
55
gallery/src/pages/components/ha-dropdown.markdown
Normal file
55
gallery/src/pages/components/ha-dropdown.markdown
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
title: Dropdown
|
||||||
|
---
|
||||||
|
|
||||||
|
# Dropdown `<ha-dropdown>`
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
A compact, accessible dropdown menu for choosing actions or settings. `ha-dropdown` supports composed menu items (`<ha-dropdown-item>`) for icons, submenus, checkboxes, disabled entries, and destructive variants. Use composition with `slot="trigger"` to control the trigger button and use `<ha-dropdown-item>` for rich item content.
|
||||||
|
|
||||||
|
### Example usage (composition)
|
||||||
|
|
||||||
|
```html
|
||||||
|
<ha-dropdown open>
|
||||||
|
<ha-button slot="trigger" with-caret>Dropdown</ha-button>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon .path="mdiContentCut" slot="icon"></ha-svg-icon>
|
||||||
|
Cut
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon .path="mdiContentCopy" slot="icon"></ha-svg-icon>
|
||||||
|
Copy
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item disabled>
|
||||||
|
<ha-svg-icon .path="mdiContentPaste" slot="icon"></ha-svg-icon>
|
||||||
|
Paste
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
Show images
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-all-images"
|
||||||
|
>Show all images</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-thumbnails"
|
||||||
|
>Show thumbnails</ha-dropdown-item
|
||||||
|
>
|
||||||
|
</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item type="checkbox" checked>Emoji shortcuts</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item type="checkbox" checked>Word wrap</ha-dropdown-item>
|
||||||
|
|
||||||
|
<ha-dropdown-item variant="danger">
|
||||||
|
<ha-svg-icon .path="mdiDelete" slot="icon"></ha-svg-icon>
|
||||||
|
Delete
|
||||||
|
</ha-dropdown-item>
|
||||||
|
</ha-dropdown>
|
||||||
|
```
|
||||||
|
|
||||||
|
### API
|
||||||
|
|
||||||
|
This component is based on the webawesome dropdown component.
|
||||||
|
Check the [webawesome documentation](https://webawesome.com/docs/components/dropdown/) for more details.
|
||||||
133
gallery/src/pages/components/ha-dropdown.ts
Normal file
133
gallery/src/pages/components/ha-dropdown.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import "@home-assistant/webawesome/dist/components/button/button";
|
||||||
|
import "@home-assistant/webawesome/dist/components/dropdown/dropdown";
|
||||||
|
import "@home-assistant/webawesome/dist/components/icon/icon";
|
||||||
|
import "@home-assistant/webawesome/dist/components/popup/popup";
|
||||||
|
import {
|
||||||
|
mdiContentCopy,
|
||||||
|
mdiContentCut,
|
||||||
|
mdiContentPaste,
|
||||||
|
mdiDelete,
|
||||||
|
} from "@mdi/js";
|
||||||
|
import type { TemplateResult } from "lit";
|
||||||
|
import { css, html, LitElement } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element";
|
||||||
|
import "../../../../src/components/ha-button";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-dropdown";
|
||||||
|
import "../../../../src/components/ha-dropdown-item";
|
||||||
|
import "../../../../src/components/ha-icon-button";
|
||||||
|
import "../../../../src/components/ha-svg-icon";
|
||||||
|
|
||||||
|
@customElement("demo-components-ha-dropdown")
|
||||||
|
export class DemoHaDropdown extends LitElement {
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
${["light", "dark"].map(
|
||||||
|
(mode) => html`
|
||||||
|
<div class=${mode}>
|
||||||
|
<ha-card header="ha-button in ${mode}">
|
||||||
|
<div class="card-content">
|
||||||
|
<ha-dropdown open>
|
||||||
|
<ha-button slot="trigger" with-caret>Dropdown</ha-button>
|
||||||
|
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentCut}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Cut
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentCopy}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Copy
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item disabled>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiContentPaste}
|
||||||
|
slot="icon"
|
||||||
|
></ha-svg-icon>
|
||||||
|
Paste
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item>
|
||||||
|
Show images
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-all-images"
|
||||||
|
>Show All Images</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item slot="submenu" value="show-thumbnails"
|
||||||
|
>Show Thumbnails</ha-dropdown-item
|
||||||
|
>
|
||||||
|
</ha-dropdown-item>
|
||||||
|
<ha-dropdown-item type="checkbox" checked
|
||||||
|
>Emoji Shortcuts</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item type="checkbox" checked
|
||||||
|
>Word Wrap</ha-dropdown-item
|
||||||
|
>
|
||||||
|
<ha-dropdown-item variant="danger">
|
||||||
|
<ha-svg-icon .path=${mdiDelete} slot="icon"></ha-svg-icon>
|
||||||
|
Delete
|
||||||
|
</ha-dropdown-item>
|
||||||
|
</ha-dropdown>
|
||||||
|
</div>
|
||||||
|
</ha-card>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
firstUpdated(changedProps) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
applyThemesOnElement(
|
||||||
|
this.shadowRoot!.querySelector(".dark"),
|
||||||
|
{
|
||||||
|
default_theme: "default",
|
||||||
|
default_dark_theme: "default",
|
||||||
|
themes: {},
|
||||||
|
darkMode: true,
|
||||||
|
theme: "default",
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.dark,
|
||||||
|
.light {
|
||||||
|
display: block;
|
||||||
|
background-color: var(--primary-background-color);
|
||||||
|
padding: 0 50px;
|
||||||
|
}
|
||||||
|
.button {
|
||||||
|
padding: unset;
|
||||||
|
}
|
||||||
|
ha-card {
|
||||||
|
margin: 24px auto;
|
||||||
|
}
|
||||||
|
.card-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
.card-content div {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-components-ha-dropdown": DemoHaDropdown;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ const SENSOR_DEVICE_CLASSES = [
|
|||||||
"pm1",
|
"pm1",
|
||||||
"pm10",
|
"pm10",
|
||||||
"pm25",
|
"pm25",
|
||||||
|
"pm4",
|
||||||
"power_factor",
|
"power_factor",
|
||||||
"power",
|
"power",
|
||||||
"precipitation",
|
"precipitation",
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
import "@material/mwc-linear-progress";
|
import "@material/mwc-linear-progress";
|
||||||
import { type PropertyValues, css, html, nothing } from "lit";
|
import { mdiOpenInNew } from "@mdi/js";
|
||||||
|
import { css, html, nothing, type PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { extractSearchParam } from "../../src/common/url/search-params";
|
||||||
import "../../src/components/ha-alert";
|
import "../../src/components/ha-alert";
|
||||||
|
import "../../src/components/ha-button";
|
||||||
import "../../src/components/ha-fade-in";
|
import "../../src/components/ha-fade-in";
|
||||||
import "../../src/components/ha-spinner";
|
import "../../src/components/ha-spinner";
|
||||||
import { haStyle } from "../../src/resources/styles";
|
import "../../src/components/ha-svg-icon";
|
||||||
import "../../src/onboarding/onboarding-welcome-links";
|
|
||||||
import "./components/landing-page-network";
|
|
||||||
import "./components/landing-page-logs";
|
|
||||||
import { extractSearchParam } from "../../src/common/url/search-params";
|
|
||||||
import { onBoardingStyles } from "../../src/onboarding/styles";
|
|
||||||
import { makeDialogManager } from "../../src/dialogs/make-dialog-manager";
|
import { makeDialogManager } from "../../src/dialogs/make-dialog-manager";
|
||||||
import { LandingPageBaseElement } from "./landing-page-base-element";
|
import "../../src/onboarding/onboarding-welcome-links";
|
||||||
|
import { onBoardingStyles } from "../../src/onboarding/styles";
|
||||||
|
import { haStyle } from "../../src/resources/styles";
|
||||||
|
import "./components/landing-page-logs";
|
||||||
|
import "./components/landing-page-network";
|
||||||
import {
|
import {
|
||||||
getSupervisorNetworkInfo,
|
getSupervisorNetworkInfo,
|
||||||
pingSupervisor,
|
pingSupervisor,
|
||||||
type NetworkInfo,
|
type NetworkInfo,
|
||||||
} from "./data/supervisor";
|
} from "./data/supervisor";
|
||||||
|
import { LandingPageBaseElement } from "./landing-page-base-element";
|
||||||
|
|
||||||
export const ASSUME_CORE_START_SECONDS = 60;
|
export const ASSUME_CORE_START_SECONDS = 60;
|
||||||
const SCHEDULE_CORE_CHECK_SECONDS = 1;
|
const SCHEDULE_CORE_CHECK_SECONDS = 1;
|
||||||
@@ -94,16 +97,21 @@ class HaLandingPage extends LandingPageBaseElement {
|
|||||||
<ha-language-picker
|
<ha-language-picker
|
||||||
.value=${this.language}
|
.value=${this.language}
|
||||||
.label=${""}
|
.label=${""}
|
||||||
|
button-style
|
||||||
native-name
|
native-name
|
||||||
@value-changed=${this._languageChanged}
|
@value-changed=${this._languageChanged}
|
||||||
inline-arrow
|
inline-arrow
|
||||||
></ha-language-picker>
|
></ha-language-picker>
|
||||||
<a
|
<ha-button
|
||||||
|
appearance="plain"
|
||||||
|
variant="neutral"
|
||||||
href="https://www.home-assistant.io/getting-started/onboarding/"
|
href="https://www.home-assistant.io/getting-started/onboarding/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
>${this.localize("ui.panel.page-onboarding.help")}</a
|
|
||||||
>
|
>
|
||||||
|
${this.localize("ui.panel.page-onboarding.help")}
|
||||||
|
<ha-svg-icon slot="end" .path=${mdiOpenInNew}></ha-svg-icon>
|
||||||
|
</ha-button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -218,26 +226,8 @@ class HaLandingPage extends LandingPageBaseElement {
|
|||||||
ha-alert p {
|
ha-alert p {
|
||||||
text-align: unset;
|
text-align: unset;
|
||||||
}
|
}
|
||||||
ha-language-picker {
|
.footer ha-svg-icon {
|
||||||
display: block;
|
--mdc-icon-size: var(--ha-space-5);
|
||||||
width: 200px;
|
|
||||||
border-radius: var(--ha-border-radius-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
--ha-select-height: 40px;
|
|
||||||
--mdc-select-fill-color: none;
|
|
||||||
--mdc-select-label-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-idle-line-color: transparent;
|
|
||||||
--mdc-select-hover-line-color: transparent;
|
|
||||||
--mdc-select-dropdown-icon-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-shape-small: 0;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
margin-right: 16px;
|
|
||||||
margin-inline-end: 16px;
|
|
||||||
margin-inline-start: initial;
|
|
||||||
}
|
}
|
||||||
ha-fade-in {
|
ha-fade-in {
|
||||||
min-height: calc(100vh - 64px - 88px);
|
min-height: calc(100vh - 64px - 88px);
|
||||||
|
|||||||
68
package.json
68
package.json
@@ -28,8 +28,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "7.28.4",
|
"@babel/runtime": "7.28.4",
|
||||||
"@braintree/sanitize-url": "7.1.1",
|
"@braintree/sanitize-url": "7.1.1",
|
||||||
"@codemirror/autocomplete": "6.19.0",
|
"@codemirror/autocomplete": "6.19.1",
|
||||||
"@codemirror/commands": "6.9.0",
|
"@codemirror/commands": "6.10.0",
|
||||||
"@codemirror/language": "6.11.3",
|
"@codemirror/language": "6.11.3",
|
||||||
"@codemirror/legacy-modes": "6.5.2",
|
"@codemirror/legacy-modes": "6.5.2",
|
||||||
"@codemirror/search": "6.5.11",
|
"@codemirror/search": "6.5.11",
|
||||||
@@ -52,8 +52,8 @@
|
|||||||
"@fullcalendar/list": "6.1.19",
|
"@fullcalendar/list": "6.1.19",
|
||||||
"@fullcalendar/luxon3": "6.1.19",
|
"@fullcalendar/luxon3": "6.1.19",
|
||||||
"@fullcalendar/timegrid": "6.1.19",
|
"@fullcalendar/timegrid": "6.1.19",
|
||||||
"@home-assistant/webawesome": "3.0.0-beta.6.ha.5",
|
"@home-assistant/webawesome": "3.0.0",
|
||||||
"@lezer/highlight": "1.2.2",
|
"@lezer/highlight": "1.2.3",
|
||||||
"@lit-labs/motion": "1.0.9",
|
"@lit-labs/motion": "1.0.9",
|
||||||
"@lit-labs/observers": "2.0.6",
|
"@lit-labs/observers": "2.0.6",
|
||||||
"@lit-labs/virtualizer": "2.1.1",
|
"@lit-labs/virtualizer": "2.1.1",
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
"@material/mwc-top-app-bar": "0.27.0",
|
"@material/mwc-top-app-bar": "0.27.0",
|
||||||
"@material/mwc-top-app-bar-fixed": "0.27.0",
|
"@material/mwc-top-app-bar-fixed": "0.27.0",
|
||||||
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
|
"@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0",
|
||||||
"@material/web": "2.4.0",
|
"@material/web": "2.4.1",
|
||||||
"@mdi/js": "7.4.47",
|
"@mdi/js": "7.4.47",
|
||||||
"@mdi/svg": "7.4.47",
|
"@mdi/svg": "7.4.47",
|
||||||
"@replit/codemirror-indentation-markers": "6.5.3",
|
"@replit/codemirror-indentation-markers": "6.5.3",
|
||||||
@@ -89,8 +89,8 @@
|
|||||||
"@thomasloven/round-slider": "0.6.0",
|
"@thomasloven/round-slider": "0.6.0",
|
||||||
"@tsparticles/engine": "3.9.1",
|
"@tsparticles/engine": "3.9.1",
|
||||||
"@tsparticles/preset-links": "3.2.0",
|
"@tsparticles/preset-links": "3.2.0",
|
||||||
"@vaadin/combo-box": "24.9.2",
|
"@vaadin/combo-box": "24.9.5",
|
||||||
"@vaadin/vaadin-themable-mixin": "24.9.2",
|
"@vaadin/vaadin-themable-mixin": "24.9.5",
|
||||||
"@vibrant/color": "4.0.0",
|
"@vibrant/color": "4.0.0",
|
||||||
"@vue/web-component-wrapper": "1.3.0",
|
"@vue/web-component-wrapper": "1.3.0",
|
||||||
"@webcomponents/scoped-custom-element-registry": "0.0.10",
|
"@webcomponents/scoped-custom-element-registry": "0.0.10",
|
||||||
@@ -111,18 +111,18 @@
|
|||||||
"fuse.js": "7.1.0",
|
"fuse.js": "7.1.0",
|
||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"gulp-zopfli-green": "6.0.2",
|
"gulp-zopfli-green": "6.0.2",
|
||||||
"hls.js": "1.6.13",
|
"hls.js": "1.6.14",
|
||||||
"home-assistant-js-websocket": "9.5.0",
|
"home-assistant-js-websocket": "9.5.0",
|
||||||
"idb-keyval": "6.2.2",
|
"idb-keyval": "6.2.2",
|
||||||
"intl-messageformat": "10.7.18",
|
"intl-messageformat": "10.7.18",
|
||||||
"js-yaml": "4.1.0",
|
"js-yaml": "4.1.1",
|
||||||
"leaflet": "1.9.4",
|
"leaflet": "1.9.4",
|
||||||
"leaflet-draw": "patch:leaflet-draw@npm%3A1.0.4#./.yarn/patches/leaflet-draw-npm-1.0.4-0ca0ebcf65.patch",
|
"leaflet-draw": "patch:leaflet-draw@npm%3A1.0.4#./.yarn/patches/leaflet-draw-npm-1.0.4-0ca0ebcf65.patch",
|
||||||
"leaflet.markercluster": "1.5.3",
|
"leaflet.markercluster": "1.5.3",
|
||||||
"lit": "3.3.1",
|
"lit": "3.3.1",
|
||||||
"lit-html": "3.3.1",
|
"lit-html": "3.3.1",
|
||||||
"luxon": "3.7.2",
|
"luxon": "3.7.2",
|
||||||
"marked": "16.4.1",
|
"marked": "17.0.0",
|
||||||
"memoize-one": "6.0.0",
|
"memoize-one": "6.0.0",
|
||||||
"node-vibrant": "4.0.3",
|
"node-vibrant": "4.0.3",
|
||||||
"object-hash": "3.0.0",
|
"object-hash": "3.0.0",
|
||||||
@@ -148,17 +148,17 @@
|
|||||||
"xss": "1.0.15"
|
"xss": "1.0.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.28.4",
|
"@babel/core": "7.28.5",
|
||||||
"@babel/helper-define-polyfill-provider": "0.6.5",
|
"@babel/helper-define-polyfill-provider": "0.6.5",
|
||||||
"@babel/plugin-transform-runtime": "7.28.3",
|
"@babel/plugin-transform-runtime": "7.28.5",
|
||||||
"@babel/preset-env": "7.28.3",
|
"@babel/preset-env": "7.28.5",
|
||||||
"@bundle-stats/plugin-webpack-filter": "4.21.5",
|
"@bundle-stats/plugin-webpack-filter": "4.21.6",
|
||||||
"@lokalise/node-api": "15.3.1",
|
"@lokalise/node-api": "15.3.1",
|
||||||
"@octokit/auth-oauth-device": "8.0.2",
|
"@octokit/auth-oauth-device": "8.0.3",
|
||||||
"@octokit/plugin-retry": "8.0.2",
|
"@octokit/plugin-retry": "8.0.3",
|
||||||
"@octokit/rest": "22.0.0",
|
"@octokit/rest": "22.0.1",
|
||||||
"@rsdoctor/rspack-plugin": "1.3.3",
|
"@rsdoctor/rspack-plugin": "1.3.8",
|
||||||
"@rspack/core": "1.5.8",
|
"@rspack/core": "1.6.1",
|
||||||
"@rspack/dev-server": "1.1.4",
|
"@rspack/dev-server": "1.1.4",
|
||||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||||
"@types/chromecast-caf-receiver": "6.0.22",
|
"@types/chromecast-caf-receiver": "6.0.22",
|
||||||
@@ -173,17 +173,17 @@
|
|||||||
"@types/lodash.merge": "4.6.9",
|
"@types/lodash.merge": "4.6.9",
|
||||||
"@types/luxon": "3.7.1",
|
"@types/luxon": "3.7.1",
|
||||||
"@types/mocha": "10.0.10",
|
"@types/mocha": "10.0.10",
|
||||||
"@types/qrcode": "1.5.5",
|
"@types/qrcode": "1.5.6",
|
||||||
"@types/sortablejs": "1.15.8",
|
"@types/sortablejs": "1.15.9",
|
||||||
"@types/tar": "6.1.13",
|
"@types/tar": "6.1.13",
|
||||||
"@types/ua-parser-js": "0.7.39",
|
"@types/ua-parser-js": "0.7.39",
|
||||||
"@types/webspeechapi": "0.0.29",
|
"@types/webspeechapi": "0.0.29",
|
||||||
"@vitest/coverage-v8": "3.2.4",
|
"@vitest/coverage-v8": "4.0.8",
|
||||||
"babel-loader": "10.0.0",
|
"babel-loader": "10.0.0",
|
||||||
"babel-plugin-template-html-minifier": "4.1.0",
|
"babel-plugin-template-html-minifier": "4.1.0",
|
||||||
"browserslist-useragent-regexp": "4.1.3",
|
"browserslist-useragent-regexp": "4.1.3",
|
||||||
"del": "8.0.1",
|
"del": "8.0.1",
|
||||||
"eslint": "9.38.0",
|
"eslint": "9.39.1",
|
||||||
"eslint-config-airbnb-base": "15.0.0",
|
"eslint-config-airbnb-base": "15.0.0",
|
||||||
"eslint-config-prettier": "10.1.8",
|
"eslint-config-prettier": "10.1.8",
|
||||||
"eslint-import-resolver-webpack": "0.13.10",
|
"eslint-import-resolver-webpack": "0.13.10",
|
||||||
@@ -194,16 +194,16 @@
|
|||||||
"eslint-plugin-wc": "3.0.2",
|
"eslint-plugin-wc": "3.0.2",
|
||||||
"fancy-log": "2.0.0",
|
"fancy-log": "2.0.0",
|
||||||
"fs-extra": "11.3.2",
|
"fs-extra": "11.3.2",
|
||||||
"glob": "11.0.3",
|
"glob": "12.0.0",
|
||||||
"gulp": "5.0.1",
|
"gulp": "5.0.1",
|
||||||
"gulp-brotli": "3.0.0",
|
"gulp-brotli": "3.0.0",
|
||||||
"gulp-json-transform": "0.5.0",
|
"gulp-json-transform": "0.5.0",
|
||||||
"gulp-rename": "2.1.0",
|
"gulp-rename": "2.1.0",
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
"husky": "9.1.7",
|
"husky": "9.1.7",
|
||||||
"jsdom": "27.0.1",
|
"jsdom": "27.1.0",
|
||||||
"jszip": "3.10.1",
|
"jszip": "3.10.1",
|
||||||
"lint-staged": "16.2.4",
|
"lint-staged": "16.2.6",
|
||||||
"lit-analyzer": "2.0.3",
|
"lit-analyzer": "2.0.3",
|
||||||
"lodash.merge": "4.6.2",
|
"lodash.merge": "4.6.2",
|
||||||
"lodash.template": "4.5.0",
|
"lodash.template": "4.5.0",
|
||||||
@@ -213,13 +213,13 @@
|
|||||||
"rspack-manifest-plugin": "5.1.0",
|
"rspack-manifest-plugin": "5.1.0",
|
||||||
"serve": "14.2.5",
|
"serve": "14.2.5",
|
||||||
"sinon": "21.0.0",
|
"sinon": "21.0.0",
|
||||||
"tar": "7.5.1",
|
"tar": "7.5.2",
|
||||||
"terser-webpack-plugin": "5.3.14",
|
"terser-webpack-plugin": "5.3.14",
|
||||||
"ts-lit-plugin": "2.0.2",
|
"ts-lit-plugin": "2.0.2",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"typescript-eslint": "8.46.1",
|
"typescript-eslint": "8.46.3",
|
||||||
"vite-tsconfig-paths": "5.1.4",
|
"vite-tsconfig-paths": "5.1.4",
|
||||||
"vitest": "3.2.4",
|
"vitest": "4.0.8",
|
||||||
"webpack-stats-plugin": "1.1.3",
|
"webpack-stats-plugin": "1.1.3",
|
||||||
"webpackbar": "7.0.0",
|
"webpackbar": "7.0.0",
|
||||||
"workbox-build": "patch:workbox-build@npm%3A7.1.1#~/.yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch"
|
"workbox-build": "patch:workbox-build@npm%3A7.1.1#~/.yarn/patches/workbox-build-npm-7.1.1-a854f3faae.patch"
|
||||||
@@ -231,9 +231,13 @@
|
|||||||
"clean-css": "5.3.3",
|
"clean-css": "5.3.3",
|
||||||
"@lit/reactive-element": "2.1.1",
|
"@lit/reactive-element": "2.1.1",
|
||||||
"@fullcalendar/daygrid": "6.1.19",
|
"@fullcalendar/daygrid": "6.1.19",
|
||||||
"globals": "16.4.0",
|
"globals": "16.5.0",
|
||||||
"tslib": "2.8.1",
|
"tslib": "2.8.1",
|
||||||
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch"
|
"@material/mwc-list@^0.27.0": "patch:@material/mwc-list@npm%3A0.27.0#~/.yarn/patches/@material-mwc-list-npm-0.27.0-5344fc9de4.patch",
|
||||||
|
"glob@^10.2.2": "^10.5.0"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.10.3"
|
"packageManager": "yarn@4.11.0",
|
||||||
|
"volta": {
|
||||||
|
"node": "22.21.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20250924.0"
|
version = "20251029.0"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
license-files = ["LICENSE*"]
|
license-files = ["LICENSE*"]
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ export class HaAuthFlow extends LitElement {
|
|||||||
willUpdate(changedProps: PropertyValues) {
|
willUpdate(changedProps: PropertyValues) {
|
||||||
super.willUpdate(changedProps);
|
super.willUpdate(changedProps);
|
||||||
|
|
||||||
if (!this.hasUpdated) {
|
if (!this.hasUpdated && this.clientId === genClientId()) {
|
||||||
|
// Preselect store token when logging in to own instance
|
||||||
this._storeToken = this.initStoreToken;
|
this._storeToken = this.initStoreToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable lit/prefer-static-styles */
|
/* eslint-disable lit/prefer-static-styles */
|
||||||
|
import { mdiOpenInNew } from "@mdi/js";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@@ -6,6 +7,8 @@ import punycode from "punycode";
|
|||||||
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../common/dom/apply_themes_on_element";
|
||||||
import { extractSearchParamsObject } from "../common/url/search-params";
|
import { extractSearchParamsObject } from "../common/url/search-params";
|
||||||
import "../components/ha-alert";
|
import "../components/ha-alert";
|
||||||
|
import "../components/ha-button";
|
||||||
|
import "../components/ha-svg-icon";
|
||||||
import type { AuthProvider, AuthUrlSearchParams } from "../data/auth";
|
import type { AuthProvider, AuthUrlSearchParams } from "../data/auth";
|
||||||
import { fetchAuthProviders } from "../data/auth";
|
import { fetchAuthProviders } from "../data/auth";
|
||||||
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
import { litLocalizeLiteMixin } from "../mixins/lit-localize-lite-mixin";
|
||||||
@@ -133,25 +136,8 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
ha-language-picker {
|
.footer ha-svg-icon {
|
||||||
width: 200px;
|
--mdc-icon-size: var(--ha-space-5);
|
||||||
border-radius: var(--ha-border-radius-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
--ha-select-height: 40px;
|
|
||||||
--mdc-select-fill-color: none;
|
|
||||||
--mdc-select-label-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-ink-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-select-idle-line-color: transparent;
|
|
||||||
--mdc-select-hover-line-color: transparent;
|
|
||||||
--mdc-select-dropdown-icon-color: var(--primary-text-color, #212121);
|
|
||||||
--mdc-shape-small: 0;
|
|
||||||
}
|
|
||||||
.footer a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
margin-right: 16px;
|
|
||||||
margin-inline-end: 16px;
|
|
||||||
margin-inline-start: initial;
|
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
font-size: var(--ha-font-size-3xl);
|
font-size: var(--ha-font-size-3xl);
|
||||||
@@ -205,16 +191,21 @@ export class HaAuthorize extends litLocalizeLiteMixin(LitElement) {
|
|||||||
<ha-language-picker
|
<ha-language-picker
|
||||||
.value=${this.language}
|
.value=${this.language}
|
||||||
.label=${""}
|
.label=${""}
|
||||||
|
button-style
|
||||||
native-name
|
native-name
|
||||||
@value-changed=${this._languageChanged}
|
@value-changed=${this._languageChanged}
|
||||||
inline-arrow
|
inline-arrow
|
||||||
></ha-language-picker>
|
></ha-language-picker>
|
||||||
<a
|
<ha-button
|
||||||
|
appearance="plain"
|
||||||
|
variant="neutral"
|
||||||
href="https://www.home-assistant.io/docs/authentication/"
|
href="https://www.home-assistant.io/docs/authentication/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
>${this.localize("ui.panel.page-authorize.help")}</a
|
|
||||||
>
|
>
|
||||||
|
${this.localize("ui.panel.page-authorize.help")}
|
||||||
|
<ha-svg-icon slot="end" .path=${mdiOpenInNew}></ha-svg-icon>
|
||||||
|
</ha-button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/common/areas/areas-floor-hierarchy.ts
Normal file
53
src/common/areas/areas-floor-hierarchy.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import type { AreaRegistryEntry } from "../../data/area_registry";
|
||||||
|
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
|
|
||||||
|
export interface AreasFloorHierarchy {
|
||||||
|
floors: {
|
||||||
|
id: string;
|
||||||
|
areas: string[];
|
||||||
|
}[];
|
||||||
|
areas: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAreasFloorHierarchy = (
|
||||||
|
floors: FloorRegistryEntry[],
|
||||||
|
areas: AreaRegistryEntry[]
|
||||||
|
): AreasFloorHierarchy => {
|
||||||
|
const floorAreas = new Map<string, string[]>();
|
||||||
|
const unassignedAreas: string[] = [];
|
||||||
|
|
||||||
|
for (const area of areas) {
|
||||||
|
if (area.floor_id) {
|
||||||
|
if (!floorAreas.has(area.floor_id)) {
|
||||||
|
floorAreas.set(area.floor_id, []);
|
||||||
|
}
|
||||||
|
floorAreas.get(area.floor_id)!.push(area.area_id);
|
||||||
|
} else {
|
||||||
|
unassignedAreas.push(area.area_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hierarchy: AreasFloorHierarchy = {
|
||||||
|
floors: floors.map((floor) => ({
|
||||||
|
id: floor.floor_id,
|
||||||
|
areas: floorAreas.get(floor.floor_id) || [],
|
||||||
|
})),
|
||||||
|
areas: unassignedAreas,
|
||||||
|
};
|
||||||
|
|
||||||
|
return hierarchy;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getAreasOrder = (hierarchy: AreasFloorHierarchy): string[] => {
|
||||||
|
const order: string[] = [];
|
||||||
|
|
||||||
|
for (const floor of hierarchy.floors) {
|
||||||
|
order.push(...floor.areas);
|
||||||
|
}
|
||||||
|
order.push(...hierarchy.areas);
|
||||||
|
|
||||||
|
return order;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getFloorOrder = (hierarchy: AreasFloorHierarchy): string[] =>
|
||||||
|
hierarchy.floors.map((floor) => floor.id);
|
||||||
36
src/common/condition/extract.ts
Normal file
36
src/common/condition/extract.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import type {
|
||||||
|
Condition,
|
||||||
|
TimeCondition,
|
||||||
|
} from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract media queries from conditions recursively
|
||||||
|
*/
|
||||||
|
export function extractMediaQueries(conditions: Condition[]): string[] {
|
||||||
|
return conditions.reduce<string[]>((array, c) => {
|
||||||
|
if ("conditions" in c && c.conditions) {
|
||||||
|
array.push(...extractMediaQueries(c.conditions));
|
||||||
|
}
|
||||||
|
if (c.condition === "screen" && c.media_query) {
|
||||||
|
array.push(c.media_query);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract time conditions from conditions recursively
|
||||||
|
*/
|
||||||
|
export function extractTimeConditions(
|
||||||
|
conditions: Condition[]
|
||||||
|
): TimeCondition[] {
|
||||||
|
return conditions.reduce<TimeCondition[]>((array, c) => {
|
||||||
|
if ("conditions" in c && c.conditions) {
|
||||||
|
array.push(...extractTimeConditions(c.conditions));
|
||||||
|
}
|
||||||
|
if (c.condition === "time") {
|
||||||
|
array.push(c);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
89
src/common/condition/listeners.ts
Normal file
89
src/common/condition/listeners.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { listenMediaQuery } from "../dom/media_query";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { Condition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
import { checkConditionsMet } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
import { extractMediaQueries, extractTimeConditions } from "./extract";
|
||||||
|
import { calculateNextTimeUpdate } from "./time-calculator";
|
||||||
|
|
||||||
|
/** Maximum delay for setTimeout (2^31 - 1 milliseconds, ~24.8 days)
|
||||||
|
* Values exceeding this will overflow and execute immediately
|
||||||
|
*
|
||||||
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value
|
||||||
|
*/
|
||||||
|
const MAX_TIMEOUT_DELAY = 2147483647;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to setup media query listeners for conditional visibility
|
||||||
|
*/
|
||||||
|
export function setupMediaQueryListeners(
|
||||||
|
conditions: Condition[],
|
||||||
|
hass: HomeAssistant,
|
||||||
|
addListener: (unsub: () => void) => void,
|
||||||
|
onUpdate: (conditionsMet: boolean) => void
|
||||||
|
): void {
|
||||||
|
const mediaQueries = extractMediaQueries(conditions);
|
||||||
|
|
||||||
|
if (mediaQueries.length === 0) return;
|
||||||
|
|
||||||
|
// Optimization for single media query
|
||||||
|
const hasOnlyMediaQuery =
|
||||||
|
conditions.length === 1 &&
|
||||||
|
conditions[0].condition === "screen" &&
|
||||||
|
!!conditions[0].media_query;
|
||||||
|
|
||||||
|
mediaQueries.forEach((mediaQuery) => {
|
||||||
|
const unsub = listenMediaQuery(mediaQuery, (matches) => {
|
||||||
|
if (hasOnlyMediaQuery) {
|
||||||
|
onUpdate(matches);
|
||||||
|
} else {
|
||||||
|
const conditionsMet = checkConditionsMet(conditions, hass);
|
||||||
|
onUpdate(conditionsMet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addListener(unsub);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to setup time-based listeners for conditional visibility
|
||||||
|
*/
|
||||||
|
export function setupTimeListeners(
|
||||||
|
conditions: Condition[],
|
||||||
|
hass: HomeAssistant,
|
||||||
|
addListener: (unsub: () => void) => void,
|
||||||
|
onUpdate: (conditionsMet: boolean) => void
|
||||||
|
): void {
|
||||||
|
const timeConditions = extractTimeConditions(conditions);
|
||||||
|
|
||||||
|
if (timeConditions.length === 0) return;
|
||||||
|
|
||||||
|
timeConditions.forEach((timeCondition) => {
|
||||||
|
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
|
||||||
|
const scheduleUpdate = () => {
|
||||||
|
const delay = calculateNextTimeUpdate(hass, timeCondition);
|
||||||
|
|
||||||
|
if (delay === undefined) return;
|
||||||
|
|
||||||
|
// Cap delay to prevent setTimeout overflow
|
||||||
|
const cappedDelay = Math.min(delay, MAX_TIMEOUT_DELAY);
|
||||||
|
|
||||||
|
timeoutId = setTimeout(() => {
|
||||||
|
if (delay <= MAX_TIMEOUT_DELAY) {
|
||||||
|
const conditionsMet = checkConditionsMet(conditions, hass);
|
||||||
|
onUpdate(conditionsMet);
|
||||||
|
}
|
||||||
|
scheduleUpdate();
|
||||||
|
}, cappedDelay);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register cleanup function once, outside of scheduleUpdate
|
||||||
|
addListener(() => {
|
||||||
|
if (timeoutId !== undefined) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
scheduleUpdate();
|
||||||
|
});
|
||||||
|
}
|
||||||
73
src/common/condition/time-calculator.ts
Normal file
73
src/common/condition/time-calculator.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { TZDate } from "@date-fns/tz";
|
||||||
|
import {
|
||||||
|
startOfDay,
|
||||||
|
addDays,
|
||||||
|
addMinutes,
|
||||||
|
differenceInMilliseconds,
|
||||||
|
} from "date-fns";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { TimeZone } from "../../data/translation";
|
||||||
|
import { parseTimeString } from "../datetime/check_time";
|
||||||
|
import type { TimeCondition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate milliseconds until next time boundary for a time condition
|
||||||
|
* @param hass Home Assistant object
|
||||||
|
* @param timeCondition Time condition to calculate next update for
|
||||||
|
* @returns Milliseconds until next boundary, or undefined if no boundaries
|
||||||
|
*/
|
||||||
|
export function calculateNextTimeUpdate(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
{ after, before, weekdays }: Omit<TimeCondition, "condition">
|
||||||
|
): number | undefined {
|
||||||
|
const timezone =
|
||||||
|
hass.locale.time_zone === TimeZone.server
|
||||||
|
? hass.config.time_zone
|
||||||
|
: Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
const updates: Date[] = [];
|
||||||
|
|
||||||
|
// Calculate next occurrence of after time
|
||||||
|
if (after) {
|
||||||
|
let afterDate = parseTimeString(after, timezone);
|
||||||
|
if (afterDate <= now) {
|
||||||
|
// If time has passed today, schedule for tomorrow
|
||||||
|
afterDate = addDays(afterDate, 1);
|
||||||
|
}
|
||||||
|
updates.push(afterDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate next occurrence of before time
|
||||||
|
if (before) {
|
||||||
|
let beforeDate = parseTimeString(before, timezone);
|
||||||
|
if (beforeDate <= now) {
|
||||||
|
// If time has passed today, schedule for tomorrow
|
||||||
|
beforeDate = addDays(beforeDate, 1);
|
||||||
|
}
|
||||||
|
updates.push(beforeDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If weekdays are specified, check for midnight (weekday transition)
|
||||||
|
if (weekdays && weekdays.length > 0 && weekdays.length < 7) {
|
||||||
|
// Calculate next midnight using startOfDay + addDays
|
||||||
|
const tomorrow = addDays(now, 1);
|
||||||
|
const midnight = startOfDay(tomorrow);
|
||||||
|
updates.push(midnight);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the soonest update time
|
||||||
|
const nextUpdate = updates.reduce((soonest, current) =>
|
||||||
|
current < soonest ? current : soonest
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add 1 minute buffer to ensure we're past the boundary
|
||||||
|
const updateWithBuffer = addMinutes(nextUpdate, 1);
|
||||||
|
|
||||||
|
// Calculate difference in milliseconds
|
||||||
|
return differenceInMilliseconds(updateWithBuffer, now);
|
||||||
|
}
|
||||||
131
src/common/datetime/check_time.ts
Normal file
131
src/common/datetime/check_time.ts
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
import { TZDate } from "@date-fns/tz";
|
||||||
|
import { isBefore, isAfter, isWithinInterval } from "date-fns";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { TimeZone } from "../../data/translation";
|
||||||
|
import { WEEKDAY_MAP } from "./weekday";
|
||||||
|
import type { TimeCondition } from "../../panels/lovelace/common/validate-condition";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a time string format and value ranges without creating Date objects
|
||||||
|
* @param timeString Time string to validate (HH:MM or HH:MM:SS)
|
||||||
|
* @returns true if valid, false otherwise
|
||||||
|
*/
|
||||||
|
export function isValidTimeString(timeString: string): boolean {
|
||||||
|
// Reject empty strings
|
||||||
|
if (!timeString || timeString.trim() === "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = timeString.split(":");
|
||||||
|
|
||||||
|
if (parts.length < 2 || parts.length > 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure each part contains only digits (and optional leading zeros)
|
||||||
|
// This prevents "8:00 AM" from passing validation
|
||||||
|
if (!parts.every((part) => /^\d+$/.test(part))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hours = parseInt(parts[0], 10);
|
||||||
|
const minutes = parseInt(parts[1], 10);
|
||||||
|
const seconds = parts.length === 3 ? parseInt(parts[2], 10) : 0;
|
||||||
|
|
||||||
|
if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
hours >= 0 &&
|
||||||
|
hours <= 23 &&
|
||||||
|
minutes >= 0 &&
|
||||||
|
minutes <= 59 &&
|
||||||
|
seconds >= 0 &&
|
||||||
|
seconds <= 59
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a time string (HH:MM or HH:MM:SS) and set it on today's date in the given timezone
|
||||||
|
*
|
||||||
|
* Note: This function assumes the time string has already been validated by
|
||||||
|
* isValidTimeString() at configuration time. It does not re-validate at runtime
|
||||||
|
* for consistency with other condition types (screen, user, location, etc.)
|
||||||
|
*
|
||||||
|
* @param timeString The time string to parse (must be pre-validated)
|
||||||
|
* @param timezone The timezone to use
|
||||||
|
* @returns The Date object
|
||||||
|
*/
|
||||||
|
export const parseTimeString = (timeString: string, timezone: string): Date => {
|
||||||
|
const parts = timeString.split(":");
|
||||||
|
const hours = parseInt(parts[0], 10);
|
||||||
|
const minutes = parseInt(parts[1], 10);
|
||||||
|
const seconds = parts.length === 3 ? parseInt(parts[2], 10) : 0;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
const dateWithTime = new TZDate(
|
||||||
|
now.getFullYear(),
|
||||||
|
now.getMonth(),
|
||||||
|
now.getDate(),
|
||||||
|
hours,
|
||||||
|
minutes,
|
||||||
|
seconds,
|
||||||
|
0,
|
||||||
|
timezone
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Date(dateWithTime.getTime());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current time matches the time condition (after/before/weekday)
|
||||||
|
* @param hass Home Assistant object
|
||||||
|
* @param timeCondition Time condition to check
|
||||||
|
* @returns true if current time matches the condition
|
||||||
|
*/
|
||||||
|
export const checkTimeInRange = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
{ after, before, weekdays }: Omit<TimeCondition, "condition">
|
||||||
|
): boolean => {
|
||||||
|
const timezone =
|
||||||
|
hass.locale.time_zone === TimeZone.server
|
||||||
|
? hass.config.time_zone
|
||||||
|
: Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
|
||||||
|
const now = new TZDate(new Date(), timezone);
|
||||||
|
|
||||||
|
// Check weekday condition
|
||||||
|
if (weekdays && weekdays.length > 0) {
|
||||||
|
const currentWeekday = WEEKDAY_MAP[now.getDay()];
|
||||||
|
if (!weekdays.includes(currentWeekday)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check time conditions
|
||||||
|
if (!after && !before) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const afterDate = after ? parseTimeString(after, timezone) : undefined;
|
||||||
|
const beforeDate = before ? parseTimeString(before, timezone) : undefined;
|
||||||
|
|
||||||
|
if (afterDate && beforeDate) {
|
||||||
|
if (isBefore(beforeDate, afterDate)) {
|
||||||
|
// Crosses midnight (e.g., 22:00 to 06:00)
|
||||||
|
return !isBefore(now, afterDate) || !isAfter(now, beforeDate);
|
||||||
|
}
|
||||||
|
return isWithinInterval(now, { start: afterDate, end: beforeDate });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (afterDate) {
|
||||||
|
return !isBefore(now, afterDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (beforeDate) {
|
||||||
|
return !isAfter(now, beforeDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
@@ -1,18 +1,7 @@
|
|||||||
import { getWeekStartByLocale } from "weekstart";
|
import { getWeekStartByLocale } from "weekstart";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { FirstWeekday } from "../../data/translation";
|
import { FirstWeekday } from "../../data/translation";
|
||||||
|
import { WEEKDAYS_LONG, type WeekdayIndex } from "./weekday";
|
||||||
export const weekdays = [
|
|
||||||
"sunday",
|
|
||||||
"monday",
|
|
||||||
"tuesday",
|
|
||||||
"wednesday",
|
|
||||||
"thursday",
|
|
||||||
"friday",
|
|
||||||
"saturday",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
||||||
|
|
||||||
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
||||||
if (locale.first_weekday === FirstWeekday.language) {
|
if (locale.first_weekday === FirstWeekday.language) {
|
||||||
@@ -23,12 +12,12 @@ export const firstWeekdayIndex = (locale: FrontendLocaleData): WeekdayIndex => {
|
|||||||
}
|
}
|
||||||
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
return (getWeekStartByLocale(locale.language) % 7) as WeekdayIndex;
|
||||||
}
|
}
|
||||||
return weekdays.includes(locale.first_weekday)
|
return WEEKDAYS_LONG.includes(locale.first_weekday)
|
||||||
? (weekdays.indexOf(locale.first_weekday) as WeekdayIndex)
|
? (WEEKDAYS_LONG.indexOf(locale.first_weekday) as WeekdayIndex)
|
||||||
: 1;
|
: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const firstWeekday = (locale: FrontendLocaleData) => {
|
export const firstWeekday = (locale: FrontendLocaleData) => {
|
||||||
const index = firstWeekdayIndex(locale);
|
const index = firstWeekdayIndex(locale);
|
||||||
return weekdays[index];
|
return WEEKDAYS_LONG[index];
|
||||||
};
|
};
|
||||||
|
|||||||
59
src/common/datetime/weekday.ts
Normal file
59
src/common/datetime/weekday.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
export type WeekdayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
|
|
||||||
|
export type WeekdayShort =
|
||||||
|
| "sun"
|
||||||
|
| "mon"
|
||||||
|
| "tue"
|
||||||
|
| "wed"
|
||||||
|
| "thu"
|
||||||
|
| "fri"
|
||||||
|
| "sat";
|
||||||
|
|
||||||
|
export type WeekdayLong =
|
||||||
|
| "sunday"
|
||||||
|
| "monday"
|
||||||
|
| "tuesday"
|
||||||
|
| "wednesday"
|
||||||
|
| "thursday"
|
||||||
|
| "friday"
|
||||||
|
| "saturday";
|
||||||
|
|
||||||
|
export const WEEKDAYS_SHORT = [
|
||||||
|
"sun",
|
||||||
|
"mon",
|
||||||
|
"tue",
|
||||||
|
"wed",
|
||||||
|
"thu",
|
||||||
|
"fri",
|
||||||
|
"sat",
|
||||||
|
] as const satisfies readonly WeekdayShort[];
|
||||||
|
|
||||||
|
export const WEEKDAYS_LONG = [
|
||||||
|
"sunday",
|
||||||
|
"monday",
|
||||||
|
"tuesday",
|
||||||
|
"wednesday",
|
||||||
|
"thursday",
|
||||||
|
"friday",
|
||||||
|
"saturday",
|
||||||
|
] as const satisfies readonly WeekdayLong[];
|
||||||
|
|
||||||
|
export const WEEKDAY_MAP = {
|
||||||
|
0: "sun",
|
||||||
|
1: "mon",
|
||||||
|
2: "tue",
|
||||||
|
3: "wed",
|
||||||
|
4: "thu",
|
||||||
|
5: "fri",
|
||||||
|
6: "sat",
|
||||||
|
} as const satisfies Record<WeekdayIndex, WeekdayShort>;
|
||||||
|
|
||||||
|
export const WEEKDAY_SHORT_TO_LONG = {
|
||||||
|
sun: "sunday",
|
||||||
|
mon: "monday",
|
||||||
|
tue: "tuesday",
|
||||||
|
wed: "wednesday",
|
||||||
|
thu: "thursday",
|
||||||
|
fri: "friday",
|
||||||
|
sat: "saturday",
|
||||||
|
} as const satisfies Record<WeekdayShort, WeekdayLong>;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ThemeVars } from "../../data/ws-themes";
|
import type { ThemeVars } from "../../data/ws-themes";
|
||||||
import { darkColorVariables } from "../../resources/theme/color";
|
import { darkColorVariables } from "../../resources/theme/color";
|
||||||
|
import { darkSemanticVariables } from "../../resources/theme/semantic.globals";
|
||||||
import { derivedStyles } from "../../resources/theme/theme";
|
import { derivedStyles } from "../../resources/theme/theme";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import {
|
import {
|
||||||
@@ -52,7 +53,7 @@ export const applyThemesOnElement = (
|
|||||||
|
|
||||||
if (themeToApply && darkMode) {
|
if (themeToApply && darkMode) {
|
||||||
cacheKey = `${cacheKey}__dark`;
|
cacheKey = `${cacheKey}__dark`;
|
||||||
themeRules = { ...darkColorVariables };
|
themeRules = { ...darkSemanticVariables, ...darkColorVariables };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (themeToApply === "default") {
|
if (themeToApply === "default") {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ type EntityCategory = "none" | "config" | "diagnostic";
|
|||||||
export interface EntityFilter {
|
export interface EntityFilter {
|
||||||
domain?: string | string[];
|
domain?: string | string[];
|
||||||
device_class?: string | string[];
|
device_class?: string | string[];
|
||||||
device?: string | string[];
|
device?: string | null | (string | null)[];
|
||||||
area?: string | string[];
|
area?: string | null | (string | null)[];
|
||||||
floor?: string | string[];
|
floor?: string | null | (string | null)[];
|
||||||
label?: string | string[];
|
label?: string | string[];
|
||||||
entity_category?: EntityCategory | EntityCategory[];
|
entity_category?: EntityCategory | EntityCategory[];
|
||||||
hidden_platform?: string | string[];
|
hidden_platform?: string | string[];
|
||||||
@@ -19,6 +19,18 @@ export interface EntityFilter {
|
|||||||
|
|
||||||
export type EntityFilterFunc = (entityId: string) => boolean;
|
export type EntityFilterFunc = (entityId: string) => boolean;
|
||||||
|
|
||||||
|
const normalizeFilterArray = <T>(
|
||||||
|
value: T | null | T[] | (T | null)[] | undefined
|
||||||
|
): Set<T | null> | undefined => {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (value === null) {
|
||||||
|
return new Set([null]);
|
||||||
|
}
|
||||||
|
return new Set(ensureArray(value));
|
||||||
|
};
|
||||||
|
|
||||||
export const generateEntityFilter = (
|
export const generateEntityFilter = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
filter: EntityFilter
|
filter: EntityFilter
|
||||||
@@ -29,11 +41,9 @@ export const generateEntityFilter = (
|
|||||||
const deviceClasses = filter.device_class
|
const deviceClasses = filter.device_class
|
||||||
? new Set(ensureArray(filter.device_class))
|
? new Set(ensureArray(filter.device_class))
|
||||||
: undefined;
|
: undefined;
|
||||||
const floors = filter.floor ? new Set(ensureArray(filter.floor)) : undefined;
|
const floors = normalizeFilterArray(filter.floor);
|
||||||
const areas = filter.area ? new Set(ensureArray(filter.area)) : undefined;
|
const areas = normalizeFilterArray(filter.area);
|
||||||
const devices = filter.device
|
const devices = normalizeFilterArray(filter.device);
|
||||||
? new Set(ensureArray(filter.device))
|
|
||||||
: undefined;
|
|
||||||
const entityCategories = filter.entity_category
|
const entityCategories = filter.entity_category
|
||||||
? new Set(ensureArray(filter.entity_category))
|
? new Set(ensureArray(filter.entity_category))
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -73,23 +83,20 @@ export const generateEntityFilter = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (floors) {
|
if (floors) {
|
||||||
if (!floor || !floors.has(floor.floor_id)) {
|
const floorId = floor?.floor_id ?? null;
|
||||||
|
if (!floors.has(floorId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (areas) {
|
if (areas) {
|
||||||
if (!area) {
|
const areaId = area?.area_id ?? null;
|
||||||
return false;
|
if (!areas.has(areaId)) {
|
||||||
}
|
|
||||||
if (!areas.has(area.area_id)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (devices) {
|
if (devices) {
|
||||||
if (!device) {
|
const deviceId = device?.id ?? null;
|
||||||
return false;
|
if (!devices.has(deviceId)) {
|
||||||
}
|
|
||||||
if (!devices.has(device.id)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ const FIXED_DOMAIN_ATTRIBUTE_STATES = {
|
|||||||
"pm1",
|
"pm1",
|
||||||
"pm10",
|
"pm10",
|
||||||
"pm25",
|
"pm25",
|
||||||
|
"pm4",
|
||||||
"power_factor",
|
"power_factor",
|
||||||
"power",
|
"power",
|
||||||
"pressure",
|
"pressure",
|
||||||
|
|||||||
67
src/common/keyboard/shortcuts.ts
Normal file
67
src/common/keyboard/shortcuts.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { tinykeys } from "tinykeys";
|
||||||
|
import { canOverrideAlphanumericInput } from "../dom/can-override-input";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function to handle a keyboard shortcut.
|
||||||
|
*/
|
||||||
|
export type ShortcutHandler = (event: KeyboardEvent) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for a keyboard shortcut.
|
||||||
|
*/
|
||||||
|
export interface ShortcutConfig {
|
||||||
|
handler: ShortcutHandler;
|
||||||
|
/**
|
||||||
|
* If true, allows shortcuts even when text is selected.
|
||||||
|
* Default is false to avoid interrupting copy/paste.
|
||||||
|
*/
|
||||||
|
allowWhenTextSelected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register keyboard shortcuts using tinykeys.
|
||||||
|
* Automatically blocks shortcuts in input fields and during text selection.
|
||||||
|
*/
|
||||||
|
function registerShortcuts(
|
||||||
|
shortcuts: Record<string, ShortcutConfig>
|
||||||
|
): () => void {
|
||||||
|
const wrappedShortcuts: Record<string, ShortcutHandler> = {};
|
||||||
|
|
||||||
|
Object.entries(shortcuts).forEach(([key, config]) => {
|
||||||
|
wrappedShortcuts[key] = (event: KeyboardEvent) => {
|
||||||
|
if (!canOverrideAlphanumericInput(event.composedPath())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!config.allowWhenTextSelected && window.getSelection()?.toString()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
config.handler(event);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return tinykeys(window, wrappedShortcuts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages keyboard shortcuts registration and cleanup.
|
||||||
|
*/
|
||||||
|
export class ShortcutManager {
|
||||||
|
private _disposer?: () => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register keyboard shortcuts.
|
||||||
|
* Uses tinykeys syntax: https://github.com/jamiebuilds/tinykeys#usage
|
||||||
|
*/
|
||||||
|
public add(shortcuts: Record<string, ShortcutConfig>) {
|
||||||
|
this._disposer?.();
|
||||||
|
this._disposer = registerShortcuts(shortcuts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all registered shortcuts.
|
||||||
|
*/
|
||||||
|
public remove() {
|
||||||
|
this._disposer?.();
|
||||||
|
this._disposer = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/common/util/parse-animation-duration.ts
Normal file
36
src/common/util/parse-animation-duration.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Parses a CSS duration string (e.g., "300ms", "3s") and returns the duration in milliseconds.
|
||||||
|
*
|
||||||
|
* @param duration - A CSS duration string (e.g., "300ms", "3s", "0.5s")
|
||||||
|
* @returns The duration in milliseconds, or 0 if the input is invalid
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* parseAnimationDuration("300ms") // Returns 300
|
||||||
|
* parseAnimationDuration("3s") // Returns 3000
|
||||||
|
* parseAnimationDuration("0.5s") // Returns 500
|
||||||
|
* parseAnimationDuration("invalid") // Returns 0
|
||||||
|
*/
|
||||||
|
export const parseAnimationDuration = (duration: string): number => {
|
||||||
|
const trimmed = duration.trim();
|
||||||
|
|
||||||
|
let value: number;
|
||||||
|
let multiplier: number;
|
||||||
|
|
||||||
|
if (trimmed.endsWith("ms")) {
|
||||||
|
value = parseFloat(trimmed.slice(0, -2));
|
||||||
|
multiplier = 1;
|
||||||
|
} else if (trimmed.endsWith("s")) {
|
||||||
|
value = parseFloat(trimmed.slice(0, -1));
|
||||||
|
multiplier = 1000;
|
||||||
|
} else {
|
||||||
|
// No recognized unit, try parsing as number (assume ms)
|
||||||
|
value = parseFloat(trimmed);
|
||||||
|
multiplier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isFinite(value) || value < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value * multiplier;
|
||||||
|
};
|
||||||
@@ -119,8 +119,8 @@ type Thresholds = Record<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
export const DEFAULT_THRESHOLDS: Thresholds = {
|
export const DEFAULT_THRESHOLDS: Thresholds = {
|
||||||
second: 45, // seconds to minute
|
second: 59, // seconds to minute
|
||||||
minute: 45, // minutes to hour
|
minute: 59, // minutes to hour
|
||||||
hour: 22, // hour to day
|
hour: 22, // hour to day
|
||||||
day: 5, // day to week
|
day: 5, // day to week
|
||||||
week: 4, // week to months
|
week: 4, // week to months
|
||||||
|
|||||||
116
src/common/util/swipe-gesture-recognizer.ts
Normal file
116
src/common/util/swipe-gesture-recognizer.ts
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
export interface SwipeGestureResult {
|
||||||
|
velocity: number;
|
||||||
|
delta: number;
|
||||||
|
isSwipe: boolean;
|
||||||
|
isDownwardSwipe: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SwipeGestureConfig {
|
||||||
|
velocitySwipeThreshold?: number;
|
||||||
|
movementTimeThreshold?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const VELOCITY_SWIPE_THRESHOLD = 0.5; // px/ms
|
||||||
|
const MOVEMENT_TIME_THRESHOLD = 100; // ms
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recognizes swipe gestures and calculates velocity for touch interactions.
|
||||||
|
* Tracks touch movement and provides velocity-based and position-based gesture detection.
|
||||||
|
*/
|
||||||
|
export class SwipeGestureRecognizer {
|
||||||
|
private _startY = 0;
|
||||||
|
|
||||||
|
private _delta = 0;
|
||||||
|
|
||||||
|
private _startTime = 0;
|
||||||
|
|
||||||
|
private _lastY = 0;
|
||||||
|
|
||||||
|
private _lastTime = 0;
|
||||||
|
|
||||||
|
private _velocityThreshold: number;
|
||||||
|
|
||||||
|
private _movementTimeThreshold: number;
|
||||||
|
|
||||||
|
constructor(config: SwipeGestureConfig = {}) {
|
||||||
|
this._velocityThreshold =
|
||||||
|
config.velocitySwipeThreshold ?? VELOCITY_SWIPE_THRESHOLD; // px/ms
|
||||||
|
this._movementTimeThreshold =
|
||||||
|
config.movementTimeThreshold ?? MOVEMENT_TIME_THRESHOLD; // ms
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize gesture tracking with starting touch position
|
||||||
|
*/
|
||||||
|
public start(clientY: number): void {
|
||||||
|
const now = Date.now();
|
||||||
|
this._startY = clientY;
|
||||||
|
this._startTime = now;
|
||||||
|
this._lastY = clientY;
|
||||||
|
this._lastTime = now;
|
||||||
|
this._delta = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update gesture state during movement
|
||||||
|
* Returns the current delta (negative when dragging down)
|
||||||
|
*/
|
||||||
|
public move(clientY: number): number {
|
||||||
|
const now = Date.now();
|
||||||
|
this._delta = this._startY - clientY;
|
||||||
|
this._lastY = clientY;
|
||||||
|
this._lastTime = now;
|
||||||
|
return this._delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate final gesture result when touch ends
|
||||||
|
*/
|
||||||
|
public end(): SwipeGestureResult {
|
||||||
|
const velocity = this.getVelocity();
|
||||||
|
const hasSignificantVelocity = Math.abs(velocity) > this._velocityThreshold;
|
||||||
|
|
||||||
|
return {
|
||||||
|
velocity,
|
||||||
|
delta: this._delta,
|
||||||
|
isSwipe: hasSignificantVelocity,
|
||||||
|
isDownwardSwipe: velocity > 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current drag delta (negative when dragging down)
|
||||||
|
*/
|
||||||
|
public getDelta(): number {
|
||||||
|
return this._delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate velocity based on recent movement
|
||||||
|
* Returns 0 if no recent movement detected
|
||||||
|
* Positive velocity means downward swipe
|
||||||
|
*/
|
||||||
|
public getVelocity(): number {
|
||||||
|
const now = Date.now();
|
||||||
|
const timeSinceLastMove = now - this._lastTime;
|
||||||
|
|
||||||
|
// Only consider velocity if the last movement was recent
|
||||||
|
if (timeSinceLastMove >= this._movementTimeThreshold) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeDelta = this._lastTime - this._startTime;
|
||||||
|
return timeDelta > 0 ? (this._lastY - this._startY) / timeDelta : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset all tracking state
|
||||||
|
*/
|
||||||
|
public reset(): void {
|
||||||
|
this._startY = 0;
|
||||||
|
this._delta = 0;
|
||||||
|
this._startTime = 0;
|
||||||
|
this._lastY = 0;
|
||||||
|
this._lastTime = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/common/util/view-transition.ts
Normal file
30
src/common/util/view-transition.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Executes a callback within a View Transition if supported, otherwise runs it directly.
|
||||||
|
*
|
||||||
|
* @param callback - Function to execute. Can be synchronous or return a Promise. The callback will be passed a boolean indicating whether the view transition is available.
|
||||||
|
* @returns Promise that resolves when the transition completes (or immediately if not supported)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```typescript
|
||||||
|
* // Synchronous callback
|
||||||
|
* withViewTransition(() => {
|
||||||
|
* this.large = !this.large;
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* // Async callback
|
||||||
|
* await withViewTransition(async () => {
|
||||||
|
* await this.updateData();
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export const withViewTransition = (
|
||||||
|
callback: (viewTransitionAvailable: boolean) => void | Promise<void>
|
||||||
|
): Promise<void> => {
|
||||||
|
if (document.startViewTransition) {
|
||||||
|
return document.startViewTransition(() => callback(true)).finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: Execute callback directly without transition
|
||||||
|
const result = callback(false);
|
||||||
|
return result instanceof Promise ? result : Promise.resolve();
|
||||||
|
};
|
||||||
@@ -6,7 +6,8 @@ export function downSampleLineData<
|
|||||||
data: T[] | undefined,
|
data: T[] | undefined,
|
||||||
maxDetails: number,
|
maxDetails: number,
|
||||||
minX?: number,
|
minX?: number,
|
||||||
maxX?: number
|
maxX?: number,
|
||||||
|
useMean = false
|
||||||
): T[] {
|
): T[] {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return [];
|
return [];
|
||||||
@@ -17,15 +18,13 @@ export function downSampleLineData<
|
|||||||
const min = minX ?? getPointData(data[0]!)[0];
|
const min = minX ?? getPointData(data[0]!)[0];
|
||||||
const max = maxX ?? getPointData(data[data.length - 1]!)[0];
|
const max = maxX ?? getPointData(data[data.length - 1]!)[0];
|
||||||
const step = Math.ceil((max - min) / Math.floor(maxDetails));
|
const step = Math.ceil((max - min) / Math.floor(maxDetails));
|
||||||
const frames = new Map<
|
|
||||||
number,
|
|
||||||
{
|
|
||||||
min: { point: (typeof data)[number]; x: number; y: number };
|
|
||||||
max: { point: (typeof data)[number]; x: number; y: number };
|
|
||||||
}
|
|
||||||
>();
|
|
||||||
|
|
||||||
// Group points into frames
|
// Group points into frames
|
||||||
|
const frames = new Map<
|
||||||
|
number,
|
||||||
|
{ point: (typeof data)[number]; x: number; y: number }[]
|
||||||
|
>();
|
||||||
|
|
||||||
for (const point of data) {
|
for (const point of data) {
|
||||||
const pointData = getPointData(point);
|
const pointData = getPointData(point);
|
||||||
if (!Array.isArray(pointData)) continue;
|
if (!Array.isArray(pointData)) continue;
|
||||||
@@ -36,28 +35,53 @@ export function downSampleLineData<
|
|||||||
const frameIndex = Math.floor((x - min) / step);
|
const frameIndex = Math.floor((x - min) / step);
|
||||||
const frame = frames.get(frameIndex);
|
const frame = frames.get(frameIndex);
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
frames.set(frameIndex, { min: { point, x, y }, max: { point, x, y } });
|
frames.set(frameIndex, [{ point, x, y }]);
|
||||||
} else {
|
} else {
|
||||||
if (frame.min.y > y) {
|
frame.push({ point, x, y });
|
||||||
frame.min = { point, x, y };
|
|
||||||
}
|
|
||||||
if (frame.max.y < y) {
|
|
||||||
frame.max = { point, x, y };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert frames back to points
|
// Convert frames back to points
|
||||||
const result: T[] = [];
|
const result: T[] = [];
|
||||||
for (const [_i, frame] of frames) {
|
|
||||||
// Use min/max points to preserve visual accuracy
|
if (useMean) {
|
||||||
// The order of the data must be preserved so max may be before min
|
// Use mean values for each frame
|
||||||
if (frame.min.x > frame.max.x) {
|
for (const [_i, framePoints] of frames) {
|
||||||
result.push(frame.max.point);
|
const sumY = framePoints.reduce((acc, p) => acc + p.y, 0);
|
||||||
|
const meanY = sumY / framePoints.length;
|
||||||
|
const sumX = framePoints.reduce((acc, p) => acc + p.x, 0);
|
||||||
|
const meanX = sumX / framePoints.length;
|
||||||
|
|
||||||
|
const firstPoint = framePoints[0].point;
|
||||||
|
const pointData = getPointData(firstPoint);
|
||||||
|
const meanPoint = (
|
||||||
|
Array.isArray(pointData) ? [meanX, meanY] : { value: [meanX, meanY] }
|
||||||
|
) as T;
|
||||||
|
result.push(meanPoint);
|
||||||
}
|
}
|
||||||
result.push(frame.min.point);
|
} else {
|
||||||
if (frame.min.x < frame.max.x) {
|
// Use min/max values for each frame
|
||||||
result.push(frame.max.point);
|
for (const [_i, framePoints] of frames) {
|
||||||
|
let minPoint = framePoints[0];
|
||||||
|
let maxPoint = framePoints[0];
|
||||||
|
|
||||||
|
for (const p of framePoints) {
|
||||||
|
if (p.y < minPoint.y) {
|
||||||
|
minPoint = p;
|
||||||
|
}
|
||||||
|
if (p.y > maxPoint.y) {
|
||||||
|
maxPoint = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The order of the data must be preserved so max may be before min
|
||||||
|
if (minPoint.x > maxPoint.x) {
|
||||||
|
result.push(maxPoint.point);
|
||||||
|
}
|
||||||
|
result.push(minPoint.point);
|
||||||
|
if (minPoint.x < maxPoint.x) {
|
||||||
|
result.push(maxPoint.point);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,9 +88,21 @@ export class HaChartBase extends LitElement {
|
|||||||
|
|
||||||
private _lastTapTime?: number;
|
private _lastTapTime?: number;
|
||||||
|
|
||||||
|
private _shouldResizeChart = false;
|
||||||
|
|
||||||
|
private _resizeAnimationDuration?: number;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
private _resizeController = new ResizeController(this, {
|
private _resizeController = new ResizeController(this, {
|
||||||
callback: () => this.chart?.resize(),
|
callback: () => {
|
||||||
|
if (this.chart) {
|
||||||
|
if (!this.chart.getZr().animation.isFinished()) {
|
||||||
|
this._shouldResizeChart = true;
|
||||||
|
} else {
|
||||||
|
this.chart.resize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
private _loading = false;
|
private _loading = false;
|
||||||
@@ -195,6 +207,16 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
if (changedProps.has("options")) {
|
if (changedProps.has("options")) {
|
||||||
chartOptions = { ...chartOptions, ...this._createOptions() };
|
chartOptions = { ...chartOptions, ...this._createOptions() };
|
||||||
|
if (
|
||||||
|
this._compareCustomLegendOptions(
|
||||||
|
changedProps.get("options"),
|
||||||
|
this.options
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
// custom legend changes may require a resize to layout properly
|
||||||
|
this._shouldResizeChart = true;
|
||||||
|
this._resizeAnimationDuration = 250;
|
||||||
|
}
|
||||||
} else if (this._isTouchDevice && changedProps.has("_isZoomed")) {
|
} else if (this._isTouchDevice && changedProps.has("_isZoomed")) {
|
||||||
chartOptions.dataZoom = this._getDataZoomConfig();
|
chartOptions.dataZoom = this._getDataZoomConfig();
|
||||||
}
|
}
|
||||||
@@ -286,7 +308,7 @@ export class HaChartBase extends LitElement {
|
|||||||
itemStyle = {
|
itemStyle = {
|
||||||
color: dataset?.color as string,
|
color: dataset?.color as string,
|
||||||
...(dataset?.itemStyle as { borderColor?: string }),
|
...(dataset?.itemStyle as { borderColor?: string }),
|
||||||
itemStyle,
|
...itemStyle,
|
||||||
};
|
};
|
||||||
const color = itemStyle?.color as string;
|
const color = itemStyle?.color as string;
|
||||||
const borderColor = itemStyle?.borderColor as string;
|
const borderColor = itemStyle?.borderColor as string;
|
||||||
@@ -366,6 +388,7 @@ export class HaChartBase extends LitElement {
|
|||||||
if (!this.options?.dataZoom) {
|
if (!this.options?.dataZoom) {
|
||||||
this.chart.getZr().on("dblclick", this._handleClickZoom);
|
this.chart.getZr().on("dblclick", this._handleClickZoom);
|
||||||
}
|
}
|
||||||
|
this.chart.on("finished", this._handleChartRenderFinished);
|
||||||
if (this._isTouchDevice) {
|
if (this._isTouchDevice) {
|
||||||
this.chart.getZr().on("click", (e: ECElementEvent) => {
|
this.chart.getZr().on("click", (e: ECElementEvent) => {
|
||||||
if (!e.zrByTouch) {
|
if (!e.zrByTouch) {
|
||||||
@@ -404,6 +427,7 @@ export class HaChartBase extends LitElement {
|
|||||||
...axis.axisPointer?.handle,
|
...axis.axisPointer?.handle,
|
||||||
show: true,
|
show: true,
|
||||||
},
|
},
|
||||||
|
label: { show: false },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: axis
|
: axis
|
||||||
@@ -497,6 +521,7 @@ export class HaChartBase extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.requestUpdate("_hiddenDatasets");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getDataZoomConfig(): DataZoomComponentOption | undefined {
|
private _getDataZoomConfig(): DataZoomComponentOption | undefined {
|
||||||
@@ -572,10 +597,15 @@ export class HaChartBase extends LitElement {
|
|||||||
aria: { show: true },
|
aria: { show: true },
|
||||||
dataZoom: this._getDataZoomConfig(),
|
dataZoom: this._getDataZoomConfig(),
|
||||||
toolbox: {
|
toolbox: {
|
||||||
top: Infinity,
|
top: Number.MAX_SAFE_INTEGER,
|
||||||
left: Infinity,
|
left: Number.MAX_SAFE_INTEGER,
|
||||||
feature: {
|
feature: {
|
||||||
dataZoom: { show: true, yAxisIndex: false, filterMode: "none" },
|
dataZoom: {
|
||||||
|
show: true,
|
||||||
|
yAxisIndex: false,
|
||||||
|
filterMode: "none",
|
||||||
|
showTitle: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
iconStyle: { opacity: 0 },
|
iconStyle: { opacity: 0 },
|
||||||
},
|
},
|
||||||
@@ -603,6 +633,10 @@ export class HaChartBase extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createTheme(style: CSSStyleDeclaration) {
|
private _createTheme(style: CSSStyleDeclaration) {
|
||||||
|
const textBorderColor =
|
||||||
|
style.getPropertyValue("--ha-card-background") ||
|
||||||
|
style.getPropertyValue("--card-background-color");
|
||||||
|
const textBorderWidth = 2;
|
||||||
return {
|
return {
|
||||||
color: getAllGraphColors(style),
|
color: getAllGraphColors(style),
|
||||||
backgroundColor: "transparent",
|
backgroundColor: "transparent",
|
||||||
@@ -626,15 +660,22 @@ export class HaChartBase extends LitElement {
|
|||||||
graph: {
|
graph: {
|
||||||
label: {
|
label: {
|
||||||
color: style.getPropertyValue("--primary-text-color"),
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
textBorderColor,
|
||||||
textBorderWidth: 2,
|
textBorderWidth,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pie: {
|
||||||
|
label: {
|
||||||
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
|
textBorderColor,
|
||||||
|
textBorderWidth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sankey: {
|
sankey: {
|
||||||
label: {
|
label: {
|
||||||
color: style.getPropertyValue("--primary-text-color"),
|
color: style.getPropertyValue("--primary-text-color"),
|
||||||
textBorderColor: style.getPropertyValue("--primary-background-color"),
|
textBorderColor,
|
||||||
textBorderWidth: 2,
|
textBorderWidth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
categoryAxis: {
|
categoryAxis: {
|
||||||
@@ -945,6 +986,36 @@ export class HaChartBase extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleChartRenderFinished = () => {
|
||||||
|
if (this._shouldResizeChart) {
|
||||||
|
this.chart?.resize({
|
||||||
|
animation:
|
||||||
|
this._reducedMotion ||
|
||||||
|
typeof this._resizeAnimationDuration !== "number"
|
||||||
|
? undefined
|
||||||
|
: { duration: this._resizeAnimationDuration },
|
||||||
|
});
|
||||||
|
this._shouldResizeChart = false;
|
||||||
|
this._resizeAnimationDuration = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _compareCustomLegendOptions(
|
||||||
|
oldOptions: ECOption | undefined,
|
||||||
|
newOptions: ECOption | undefined
|
||||||
|
): boolean {
|
||||||
|
const oldLegends = ensureArray(
|
||||||
|
oldOptions?.legend || []
|
||||||
|
) as LegendComponentOption[];
|
||||||
|
const newLegends = ensureArray(
|
||||||
|
newOptions?.legend || []
|
||||||
|
) as LegendComponentOption[];
|
||||||
|
return (
|
||||||
|
oldLegends.some((l) => l.show && l.type === "custom") !==
|
||||||
|
newLegends.some((l) => l.show && l.type === "custom")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ import type { EChartsType } from "echarts/core";
|
|||||||
import type { GraphSeriesOption } from "echarts/charts";
|
import type { GraphSeriesOption } from "echarts/charts";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state, query } from "lit/decorators";
|
import { customElement, property, state, query } from "lit/decorators";
|
||||||
import type { TopLevelFormatterParams } from "echarts/types/dist/shared";
|
import type {
|
||||||
|
CallbackDataParams,
|
||||||
|
TopLevelFormatterParams,
|
||||||
|
} from "echarts/types/dist/shared";
|
||||||
import { mdiFormatTextVariant, mdiGoogleCirclesGroup } from "@mdi/js";
|
import { mdiFormatTextVariant, mdiGoogleCirclesGroup } from "@mdi/js";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { listenMediaQuery } from "../../common/dom/media_query";
|
import { listenMediaQuery } from "../../common/dom/media_query";
|
||||||
@@ -16,6 +19,7 @@ import { deepEqual } from "../../common/util/deep-equal";
|
|||||||
export interface NetworkNode {
|
export interface NetworkNode {
|
||||||
id: string;
|
id: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
context?: string;
|
||||||
category?: number;
|
category?: number;
|
||||||
value?: number;
|
value?: number;
|
||||||
symbolSize?: number;
|
symbolSize?: number;
|
||||||
@@ -184,10 +188,30 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
|||||||
layout: physicsEnabled ? "force" : "none",
|
layout: physicsEnabled ? "force" : "none",
|
||||||
draggable: true,
|
draggable: true,
|
||||||
roam: true,
|
roam: true,
|
||||||
|
roamTrigger: "global",
|
||||||
selectedMode: "single",
|
selectedMode: "single",
|
||||||
label: {
|
label: {
|
||||||
show: showLabels,
|
show: showLabels,
|
||||||
position: "right",
|
position: "right",
|
||||||
|
formatter: (params: CallbackDataParams) => {
|
||||||
|
const node = params.data as NetworkNode;
|
||||||
|
if (node.context) {
|
||||||
|
return `{primary|${node.name ?? ""}}\n{secondary|${node.context}}`;
|
||||||
|
}
|
||||||
|
return node.name ?? "";
|
||||||
|
},
|
||||||
|
rich: {
|
||||||
|
primary: {
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
fontSize: 12,
|
||||||
|
color: getComputedStyle(document.body).getPropertyValue(
|
||||||
|
"--secondary-text-color"
|
||||||
|
),
|
||||||
|
lineHeight: 16,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emphasis: {
|
emphasis: {
|
||||||
focus: isMobile ? "none" : "adjacency",
|
focus: isMobile ? "none" : "adjacency",
|
||||||
@@ -225,6 +249,7 @@ export class HaNetworkGraph extends SubscribeMixin(LitElement) {
|
|||||||
({
|
({
|
||||||
id: node.id,
|
id: node.id,
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
context: node.context,
|
||||||
category: node.category,
|
category: node.category,
|
||||||
value: node.value,
|
value: node.value,
|
||||||
symbolSize: node.symbolSize || 30,
|
symbolSize: node.symbolSize || 30,
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
|
|
||||||
private _previousYAxisLabelValue = 0;
|
private _previousYAxisLabelValue = 0;
|
||||||
|
|
||||||
|
private _yAxisMaximumFractionDigits = 0;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-chart-base
|
<ha-chart-base
|
||||||
@@ -757,8 +759,12 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1))
|
Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
this._yAxisMaximumFractionDigits = Math.max(
|
||||||
|
this._yAxisMaximumFractionDigits,
|
||||||
|
maximumFractionDigits
|
||||||
|
);
|
||||||
const label = formatNumber(value, this.hass.locale, {
|
const label = formatNumber(value, this.hass.locale, {
|
||||||
maximumFractionDigits,
|
maximumFractionDigits: this._yAxisMaximumFractionDigits,
|
||||||
});
|
});
|
||||||
const width = measureTextWidth(label, 12) + 5;
|
const width = measureTextWidth(label, 12) + 5;
|
||||||
if (width > this._yWidth) {
|
if (width > this._yWidth) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export class HaFilterChip extends FilterChip {
|
|||||||
var(--rgb-primary-text-color),
|
var(--rgb-primary-text-color),
|
||||||
0.15
|
0.15
|
||||||
);
|
);
|
||||||
|
--_label-text-font: var(--ha-font-family-body);
|
||||||
border-radius: var(--ha-border-radius-md);
|
border-radius: var(--ha-border-radius-md);
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class HaDataTableLabels extends LitElement {
|
|||||||
@click=${clickAction ? this._labelClicked : undefined}
|
@click=${clickAction ? this._labelClicked : undefined}
|
||||||
@keydown=${clickAction ? this._labelClicked : undefined}
|
@keydown=${clickAction ? this._labelClicked : undefined}
|
||||||
style=${color ? `--color: ${color}` : ""}
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
>
|
>
|
||||||
${label?.icon
|
${label?.icon
|
||||||
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
? html`<ha-icon slot="icon" .icon=${label.icon}></ha-icon>`
|
||||||
|
|||||||
@@ -298,6 +298,18 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (properties.has("data")) {
|
if (properties.has("data")) {
|
||||||
|
// Clean up checked rows that no longer exist in the data
|
||||||
|
if (this._checkedRows.length) {
|
||||||
|
const validIds = new Set(this.data.map((row) => String(row[this.id])));
|
||||||
|
const validCheckedRows = this._checkedRows.filter((id) =>
|
||||||
|
validIds.has(id)
|
||||||
|
);
|
||||||
|
if (validCheckedRows.length !== this._checkedRows.length) {
|
||||||
|
this._checkedRows = validCheckedRows;
|
||||||
|
this._checkedRowsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._checkableRowsCount = this.data.filter(
|
this._checkableRowsCount = this.data.filter(
|
||||||
(row) => row.selectable !== false
|
(row) => row.selectable !== false
|
||||||
).length;
|
).length;
|
||||||
|
|||||||
@@ -197,9 +197,6 @@ export class HaDevicePicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.device-picker.placeholder");
|
this.hass.localize("ui.components.device-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.device-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
const valueRenderer = this._valueRenderer(this._configEntryLookup);
|
const valueRenderer = this._valueRenderer(this._configEntryLookup);
|
||||||
|
|
||||||
@@ -209,7 +206,10 @@ export class HaDevicePicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.searchLabel=${this.searchLabel}
|
.searchLabel=${this.searchLabel}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.device-picker.no_devices"
|
||||||
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
@@ -233,6 +233,11 @@ export class HaDevicePicker extends LitElement {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.device-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
1
src/components/entity/const.ts
Normal file
1
src/components/entity/const.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const ANY_STATE_VALUE = "__ANY_STATE_IGNORE_ATTRIBUTES__";
|
||||||
@@ -147,6 +147,7 @@ class HaEntitiesPicker extends LitElement {
|
|||||||
.createDomains=${this.createDomains}
|
.createDomains=${this.createDomains}
|
||||||
.required=${this.required && !currentEntities.length}
|
.required=${this.required && !currentEntities.length}
|
||||||
@value-changed=${this._addEntity}
|
@value-changed=${this._addEntity}
|
||||||
|
.addButton=${currentEntities.length > 0}
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ export class HaEntityNamePicker extends LitElement {
|
|||||||
private _toValue = memoizeOne(
|
private _toValue = memoizeOne(
|
||||||
(items: EntityNameItem[]): typeof this.value => {
|
(items: EntityNameItem[]): typeof this.value => {
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return "";
|
return undefined;
|
||||||
}
|
}
|
||||||
if (items.length === 1) {
|
if (items.length === 1) {
|
||||||
const item = items[0];
|
const item = items[0];
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ export class HaEntityPicker extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
|
@property({ attribute: "add-button", type: Boolean })
|
||||||
|
public addButton = false;
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
protected firstUpdated(changedProperties: PropertyValues): void {
|
||||||
@@ -266,9 +269,6 @@ export class HaEntityPicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.entity.entity-picker.placeholder");
|
this.hass.localize("ui.components.entity.entity-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.entity.entity-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
@@ -279,9 +279,9 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.searchLabel=${this.searchLabel}
|
.searchLabel=${this.searchLabel}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.addButton ? undefined : this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
@@ -289,6 +289,9 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.searchFn=${this._searchFn}
|
.searchFn=${this._searchFn}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
|
.addButtonLabel=${this.addButton
|
||||||
|
? this.hass.localize("ui.components.entity.entity-picker.add")
|
||||||
|
: undefined}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
`;
|
`;
|
||||||
@@ -350,6 +353,11 @@ export class HaEntityPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.entity.entity-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -1,23 +1,39 @@
|
|||||||
import { mdiDragHorizontalVariant } from "@mdi/js";
|
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 type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import type { PropertyValues } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { stopPropagation } from "../../common/dom/stop_propagation";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import {
|
import {
|
||||||
STATE_DISPLAY_SPECIAL_CONTENT,
|
STATE_DISPLAY_SPECIAL_CONTENT,
|
||||||
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS,
|
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS,
|
||||||
} from "../../state-display/state-display";
|
} from "../../state-display/state-display";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../../types";
|
||||||
import "../ha-combo-box";
|
import "../chips/ha-assist-chip";
|
||||||
import "../ha-sortable";
|
|
||||||
import "../chips/ha-input-chip";
|
|
||||||
import "../chips/ha-chip-set";
|
import "../chips/ha-chip-set";
|
||||||
|
import "../chips/ha-input-chip";
|
||||||
|
import "../ha-combo-box";
|
||||||
import type { HaComboBox } from "../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>
|
||||||
|
`;
|
||||||
|
|
||||||
const HIDDEN_ATTRIBUTES = [
|
const HIDDEN_ATTRIBUTES = [
|
||||||
"access_token",
|
"access_token",
|
||||||
@@ -74,7 +90,7 @@ const HIDDEN_ATTRIBUTES = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
@customElement("ha-entity-state-content-picker")
|
@customElement("ha-entity-state-content-picker")
|
||||||
class HaEntityStatePicker extends LitElement {
|
export class HaStateContentPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public entityId?: string;
|
@property({ attribute: false }) public entityId?: string;
|
||||||
@@ -95,26 +111,28 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
|
|
||||||
@property() public helper?: string;
|
@property() public helper?: string;
|
||||||
|
|
||||||
@state() private _opened = false;
|
@query(".container", true) private _container?: HTMLDivElement;
|
||||||
|
|
||||||
@query("ha-combo-box", true) private _comboBox!: HaComboBox;
|
@query("ha-combo-box", true) private _comboBox!: HaComboBox;
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues) {
|
@state() private _opened = false;
|
||||||
return !(!changedProps.has("_opened") && this._opened);
|
|
||||||
}
|
|
||||||
|
|
||||||
private options = memoizeOne(
|
private _editIndex?: number;
|
||||||
|
|
||||||
|
private _options = memoizeOne(
|
||||||
(entityId?: string, stateObj?: HassEntity, allowName?: boolean) => {
|
(entityId?: string, stateObj?: HassEntity, allowName?: boolean) => {
|
||||||
const domain = entityId ? computeDomain(entityId) : undefined;
|
const domain = entityId ? computeDomain(entityId) : undefined;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: this.hass.localize("ui.components.state-content-picker.state"),
|
primary: this.hass.localize(
|
||||||
|
"ui.components.state-content-picker.state"
|
||||||
|
),
|
||||||
value: "state",
|
value: "state",
|
||||||
},
|
},
|
||||||
...(allowName
|
...(allowName
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
label: this.hass.localize(
|
primary: this.hass.localize(
|
||||||
"ui.components.state-content-picker.name"
|
"ui.components.state-content-picker.name"
|
||||||
),
|
),
|
||||||
value: "name",
|
value: "name",
|
||||||
@@ -122,13 +140,13 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
{
|
{
|
||||||
label: this.hass.localize(
|
primary: this.hass.localize(
|
||||||
"ui.components.state-content-picker.last_changed"
|
"ui.components.state-content-picker.last_changed"
|
||||||
),
|
),
|
||||||
value: "last_changed",
|
value: "last_changed",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.hass.localize(
|
primary: this.hass.localize(
|
||||||
"ui.components.state-content-picker.last_updated"
|
"ui.components.state-content-picker.last_updated"
|
||||||
),
|
),
|
||||||
value: "last_updated",
|
value: "last_updated",
|
||||||
@@ -137,7 +155,7 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
? STATE_DISPLAY_SPECIAL_CONTENT.filter((content) =>
|
? STATE_DISPLAY_SPECIAL_CONTENT.filter((content) =>
|
||||||
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS[domain]?.includes(content)
|
STATE_DISPLAY_SPECIAL_CONTENT_DOMAINS[domain]?.includes(content)
|
||||||
).map((content) => ({
|
).map((content) => ({
|
||||||
label: this.hass.localize(
|
primary: this.hass.localize(
|
||||||
`ui.components.state-content-picker.${content}`
|
`ui.components.state-content-picker.${content}`
|
||||||
),
|
),
|
||||||
value: content,
|
value: content,
|
||||||
@@ -146,108 +164,201 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
...Object.keys(stateObj?.attributes ?? {})
|
...Object.keys(stateObj?.attributes ?? {})
|
||||||
.filter((a) => !HIDDEN_ATTRIBUTES.includes(a))
|
.filter((a) => !HIDDEN_ATTRIBUTES.includes(a))
|
||||||
.map((attribute) => ({
|
.map((attribute) => ({
|
||||||
|
primary: this.hass.formatEntityAttributeName(stateObj!, attribute),
|
||||||
value: attribute,
|
value: attribute,
|
||||||
label: this.hass.formatEntityAttributeName(stateObj!, attribute),
|
|
||||||
})),
|
})),
|
||||||
];
|
] satisfies StateContentOption[];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
private _filter = "";
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.hass) {
|
|
||||||
return nothing;
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = this._value;
|
const value = this._value;
|
||||||
|
|
||||||
const stateObj = this.entityId
|
const stateObj = this.entityId
|
||||||
? this.hass.states[this.entityId]
|
? this.hass.states[this.entityId]
|
||||||
: undefined;
|
: 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`
|
return html`
|
||||||
${value?.length
|
${this.label ? html`<label>${this.label}</label>` : nothing}
|
||||||
? html`
|
<div class="container ${this.disabled ? "disabled" : ""}">
|
||||||
<ha-sortable
|
<ha-sortable
|
||||||
no-style
|
no-style
|
||||||
@item-moved=${this._moveItem}
|
@item-moved=${this._moveItem}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
handle-selector="button.primary.action"
|
handle-selector="button.primary.action"
|
||||||
>
|
filter=".add"
|
||||||
<ha-chip-set>
|
>
|
||||||
${repeat(
|
<ha-chip-set>
|
||||||
this._value,
|
${repeat(
|
||||||
(item) => item,
|
this._value,
|
||||||
(item, idx) => {
|
(item) => item,
|
||||||
const label =
|
(item: string, idx) => {
|
||||||
options.find((option) => option.value === item)?.label ||
|
const label = options.find((o) => o.value === item)?.primary;
|
||||||
item;
|
const isValid = !!label;
|
||||||
return html`
|
return html`
|
||||||
<ha-input-chip
|
<ha-input-chip
|
||||||
.idx=${idx}
|
data-idx=${idx}
|
||||||
@remove=${this._removeItem}
|
@remove=${this._removeItem}
|
||||||
.label=${label}
|
@click=${this._editItem}
|
||||||
selected
|
.label=${label || item}
|
||||||
>
|
.selected=${!this.disabled}
|
||||||
<ha-svg-icon
|
.disabled=${this.disabled}
|
||||||
slot="icon"
|
class=${!isValid ? "invalid" : ""}
|
||||||
.path=${mdiDragHorizontalVariant}
|
>
|
||||||
></ha-svg-icon>
|
<ha-svg-icon
|
||||||
${label}
|
slot="icon"
|
||||||
</ha-input-chip>
|
.path=${mdiDragHorizontalVariant}
|
||||||
`;
|
></ha-svg-icon>
|
||||||
}
|
</ha-input-chip>
|
||||||
)}
|
`;
|
||||||
</ha-chip-set>
|
}
|
||||||
</ha-sortable>
|
)}
|
||||||
`
|
${this.disabled
|
||||||
: nothing}
|
? 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>
|
||||||
|
|
||||||
<ha-combo-box
|
<mwc-menu-surface
|
||||||
item-value-path="value"
|
.open=${this._opened}
|
||||||
item-label-path="label"
|
@closed=${this._onClosed}
|
||||||
.hass=${this.hass}
|
@opened=${this._onOpened}
|
||||||
.label=${this.label}
|
@input=${stopPropagation}
|
||||||
.helper=${this.helper}
|
.anchor=${this._container}
|
||||||
.disabled=${this.disabled}
|
>
|
||||||
.required=${this.required && !value.length}
|
<ha-combo-box
|
||||||
.value=${""}
|
.hass=${this.hass}
|
||||||
.items=${optionItems}
|
.value=${""}
|
||||||
allow-custom-value
|
.autofocus=${this.autofocus}
|
||||||
@filter-changed=${this._filterChanged}
|
.disabled=${this.disabled || !this.entityId}
|
||||||
@value-changed=${this._comboBoxValueChanged}
|
.required=${this.required && !value.length}
|
||||||
@opened-changed=${this._openedChanged}
|
.helper=${this.helper}
|
||||||
></ha-combo-box>
|
.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>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private get _value() {
|
||||||
return !this.value ? [] : ensureArray(this.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>) {
|
private _openedChanged(ev: ValueChangedEvent<boolean>) {
|
||||||
this._opened = ev.detail.value;
|
const open = ev.detail.value;
|
||||||
this._comboBox.filteredItems = this._comboBox.items;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filterChanged(ev?: CustomEvent): void {
|
private _filterSelectedOptions = (
|
||||||
this._filter = ev?.detail.value || "";
|
options: StateContentOption[],
|
||||||
|
current?: string
|
||||||
|
) => {
|
||||||
|
const value = this._value;
|
||||||
|
|
||||||
const filteredItems = this._comboBox.items?.filter((item) => {
|
return options.filter(
|
||||||
const label = item.label || item.value;
|
(option) => !value.includes(option.value) || option.value === current
|
||||||
return label.toLowerCase().includes(this._filter?.toLowerCase());
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
if (this._filter) {
|
private _filterChanged(ev: ValueChangedEvent<string>) {
|
||||||
filteredItems?.unshift({ label: this._filter, value: this._filter });
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
this._comboBox.filteredItems = filteredItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,43 +371,40 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
newValue.splice(newIndex, 0, element);
|
newValue.splice(newIndex, 0, element);
|
||||||
this._setValue(newValue);
|
this._setValue(newValue);
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
this._filterChanged();
|
this._filterChanged({ detail: { value: "" } } as ValueChangedEvent<string>);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _removeItem(ev) {
|
private async _removeItem(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value: string[] = [...this._value];
|
const value = [...this._value];
|
||||||
value.splice(ev.target.idx, 1);
|
const idx = parseInt(ev.target.dataset.idx, 10);
|
||||||
|
value.splice(idx, 1);
|
||||||
this._setValue(value);
|
this._setValue(value);
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
this._filterChanged();
|
this._filterChanged({ detail: { value: "" } } as ValueChangedEvent<string>);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _comboBoxValueChanged(ev: CustomEvent): void {
|
private _comboBoxValueChanged(ev: ValueChangedEvent<string>): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const newValue = ev.detail.value;
|
const value = ev.detail.value;
|
||||||
|
|
||||||
if (this.disabled || newValue === "") {
|
if (this.disabled || value === "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentValue = this._value;
|
const newValue = [...this._value];
|
||||||
|
|
||||||
if (currentValue.includes(newValue)) {
|
if (this._editIndex != null) {
|
||||||
return;
|
newValue[this._editIndex] = value;
|
||||||
|
} else {
|
||||||
|
newValue.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
this._setValue(newValue);
|
||||||
this._filterChanged();
|
|
||||||
this._comboBox.setInputValue("");
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
this._setValue([...currentValue, newValue]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue(value: string[]) {
|
private _setValue(value: string[]) {
|
||||||
const newValue =
|
const newValue = this._toValue(value);
|
||||||
value.length === 0 ? undefined : value.length === 1 ? value[0] : value;
|
|
||||||
this.value = newValue;
|
this.value = newValue;
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: newValue,
|
value: newValue,
|
||||||
@@ -306,10 +414,64 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
static styles = css`
|
static styles = css`
|
||||||
:host {
|
:host {
|
||||||
position: relative;
|
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 {
|
ha-chip-set {
|
||||||
padding: 8px 0;
|
padding: var(--ha-space-2) var(--ha-space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.invalid {
|
||||||
|
text-decoration: line-through;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sortable-fallback {
|
.sortable-fallback {
|
||||||
@@ -329,6 +491,6 @@ class HaEntityStatePicker extends LitElement {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
"ha-entity-state-content-picker": HaEntityStatePicker;
|
"ha-entity-state-content-picker": HaStateContentPicker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { customElement, property } from "lit/decorators";
|
|||||||
import { keyed } from "lit/directives/keyed";
|
import { keyed } from "lit/directives/keyed";
|
||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { ANY_STATE_VALUE } from "./const";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "./ha-entity-state-picker";
|
import "./ha-entity-state-picker";
|
||||||
@@ -57,6 +58,7 @@ export class HaEntityStatesPicker extends LitElement {
|
|||||||
|
|
||||||
const value = this.value || [];
|
const value = this.value || [];
|
||||||
const hide = [...(this.hideStates || []), ...value];
|
const hide = [...(this.hideStates || []), ...value];
|
||||||
|
const hideValue = value.includes(ANY_STATE_VALUE);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
${repeat(
|
||||||
@@ -84,7 +86,7 @@ export class HaEntityStatesPicker extends LitElement {
|
|||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
<div>
|
<div>
|
||||||
${this.disabled && value.length
|
${(this.disabled && value.length) || hideValue
|
||||||
? nothing
|
? nothing
|
||||||
: keyed(
|
: keyed(
|
||||||
value.length,
|
value.length,
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import "../ha-combo-box-item";
|
|||||||
import "../ha-generic-picker";
|
import "../ha-generic-picker";
|
||||||
import type { HaGenericPicker } from "../ha-generic-picker";
|
import type { HaGenericPicker } from "../ha-generic-picker";
|
||||||
import "../ha-icon-button";
|
import "../ha-icon-button";
|
||||||
import "../ha-input-helper-text";
|
|
||||||
import type {
|
import type {
|
||||||
PickerComboBoxItem,
|
PickerComboBoxItem,
|
||||||
PickerComboBoxSearchFn,
|
PickerComboBoxSearchFn,
|
||||||
@@ -271,7 +270,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(isRTL ? " ◂ " : " ▸ ");
|
.join(isRTL ? " ◂ " : " ▸ ");
|
||||||
const a11yLabel = [deviceName, entityName].filter(Boolean).join(" - ");
|
|
||||||
|
|
||||||
const sortingPrefix = `${TYPE_ORDER.indexOf("entity")}`;
|
const sortingPrefix = `${TYPE_ORDER.indexOf("entity")}`;
|
||||||
output.push({
|
output.push({
|
||||||
@@ -279,7 +277,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
statistic_id: id,
|
statistic_id: id,
|
||||||
primary,
|
primary,
|
||||||
secondary,
|
secondary,
|
||||||
a11y_label: a11yLabel,
|
|
||||||
stateObj: stateObj,
|
stateObj: stateObj,
|
||||||
type: "entity",
|
type: "entity",
|
||||||
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
||||||
@@ -458,9 +455,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ??
|
this.placeholder ??
|
||||||
this.hass.localize("ui.components.statistic-picker.placeholder");
|
this.hass.localize("ui.components.statistic-picker.placeholder");
|
||||||
const notFoundLabel = this.hass.localize(
|
|
||||||
"ui.components.statistic-picker.no_match"
|
|
||||||
);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
@@ -468,7 +462,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.allowCustomValue=${this.allowCustomEntity}
|
.allowCustomValue=${this.allowCustomEntity}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${notFoundLabel}
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.statistic-picker.no_statistics"
|
||||||
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
@@ -477,6 +474,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.hideClearIcon=${this.hideClearIcon}
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
.searchFn=${this._searchFn}
|
.searchFn=${this._searchFn}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
|
.helper=${this.helper}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -521,6 +519,11 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
await this._picker?.open();
|
await this._picker?.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.statistic-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class HaAnalytics extends LitElement {
|
|||||||
</span>
|
</span>
|
||||||
<ha-switch
|
<ha-switch
|
||||||
@change=${this._handleRowClick}
|
@change=${this._handleRowClick}
|
||||||
.checked=${baseEnabled}
|
.checked=${!!baseEnabled}
|
||||||
.preference=${"base"}
|
.preference=${"base"}
|
||||||
.disabled=${loading}
|
.disabled=${loading}
|
||||||
name="base"
|
name="base"
|
||||||
@@ -70,7 +70,7 @@ export class HaAnalytics extends LitElement {
|
|||||||
<ha-switch
|
<ha-switch
|
||||||
.id="switch-${preference}"
|
.id="switch-${preference}"
|
||||||
@change=${this._handleRowClick}
|
@change=${this._handleRowClick}
|
||||||
.checked=${this.analytics?.preferences[preference]}
|
.checked=${!!this.analytics?.preferences[preference]}
|
||||||
.preference=${preference}
|
.preference=${preference}
|
||||||
name=${preference}
|
name=${preference}
|
||||||
>
|
>
|
||||||
@@ -102,7 +102,7 @@ export class HaAnalytics extends LitElement {
|
|||||||
</span>
|
</span>
|
||||||
<ha-switch
|
<ha-switch
|
||||||
@change=${this._handleRowClick}
|
@change=${this._handleRowClick}
|
||||||
.checked=${this.analytics?.preferences.diagnostics}
|
.checked=${!!this.analytics?.preferences.diagnostics}
|
||||||
.preference=${"diagnostics"}
|
.preference=${"diagnostics"}
|
||||||
.disabled=${loading}
|
.disabled=${loading}
|
||||||
name="diagnostics"
|
name="diagnostics"
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export class HaAreaPicker extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
|
|
||||||
|
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||||
|
|
||||||
public async open() {
|
public async open() {
|
||||||
@@ -367,14 +369,16 @@ export class HaAreaPicker extends LitElement {
|
|||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.area-picker.no_match"
|
.emptyLabel=${this.hass.localize("ui.components.area-picker.no_areas")}
|
||||||
)}
|
.disabled=${this.disabled}
|
||||||
|
.required=${this.required}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
|
.addButtonLabel=${this.addButtonLabel}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -422,6 +426,11 @@ export class HaAreaPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.area-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import type { HomeAssistant } from "../types";
|
|||||||
import { AudioRecorder } from "../util/audio-recorder";
|
import { AudioRecorder } from "../util/audio-recorder";
|
||||||
import { documentationUrl } from "../util/documentation-url";
|
import { documentationUrl } from "../util/documentation-url";
|
||||||
import "./ha-alert";
|
import "./ha-alert";
|
||||||
|
import "./ha-markdown";
|
||||||
import "./ha-textfield";
|
import "./ha-textfield";
|
||||||
import type { HaTextField } from "./ha-textfield";
|
import type { HaTextField } from "./ha-textfield";
|
||||||
|
|
||||||
@@ -40,7 +41,11 @@ export class HaAssistChat extends LitElement {
|
|||||||
|
|
||||||
@query("#message-input") private _messageInput!: HaTextField;
|
@query("#message-input") private _messageInput!: HaTextField;
|
||||||
|
|
||||||
@query("#scroll-container") private _scrollContainer!: HTMLDivElement;
|
@query(".message:last-child")
|
||||||
|
private _lastChatMessage!: LitElement;
|
||||||
|
|
||||||
|
@query(".message:last-child img:last-of-type")
|
||||||
|
private _lastChatMessageImage: HTMLImageElement | undefined;
|
||||||
|
|
||||||
@state() private _conversation: AssistMessage[] = [];
|
@state() private _conversation: AssistMessage[] = [];
|
||||||
|
|
||||||
@@ -92,10 +97,7 @@ export class HaAssistChat extends LitElement {
|
|||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
this._audioRecorder?.close();
|
this._audioRecorder?.close();
|
||||||
this._audioRecorder = undefined;
|
|
||||||
this._unloadAudio();
|
this._unloadAudio();
|
||||||
this._conversation = [];
|
|
||||||
this._conversationId = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@@ -112,7 +114,7 @@ export class HaAssistChat extends LitElement {
|
|||||||
const supportsSTT = this.pipeline?.stt_engine && !this.disableSpeech;
|
const supportsSTT = this.pipeline?.stt_engine && !this.disableSpeech;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="messages" id="scroll-container">
|
<div class="messages">
|
||||||
${controlHA
|
${controlHA
|
||||||
? nothing
|
? nothing
|
||||||
: html`
|
: html`
|
||||||
@@ -124,11 +126,18 @@ export class HaAssistChat extends LitElement {
|
|||||||
`}
|
`}
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
${this._conversation!.map(
|
${this._conversation!.map(
|
||||||
// New lines matter for messages
|
|
||||||
// prettier-ignore
|
|
||||||
(message) => html`
|
(message) => html`
|
||||||
<div class="message ${classMap({ error: !!message.error, [message.who]: true })}">${message.text}</div>
|
<ha-markdown
|
||||||
`
|
class="message ${classMap({
|
||||||
|
error: !!message.error,
|
||||||
|
[message.who]: true,
|
||||||
|
})}"
|
||||||
|
breaks
|
||||||
|
cache
|
||||||
|
.content=${message.text}
|
||||||
|
>
|
||||||
|
</ha-markdown>
|
||||||
|
`
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div class="input" slot="primaryAction">
|
<div class="input" slot="primaryAction">
|
||||||
@@ -189,12 +198,28 @@ export class HaAssistChat extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _scrollMessagesBottom() {
|
private async _scrollMessagesBottom() {
|
||||||
const scrollContainer = this._scrollContainer;
|
const lastChatMessage = this._lastChatMessage;
|
||||||
if (!scrollContainer) {
|
if (!lastChatMessage.hasUpdated) {
|
||||||
return;
|
await lastChatMessage.updateComplete;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
this._lastChatMessageImage &&
|
||||||
|
!this._lastChatMessageImage.naturalHeight
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
await this._lastChatMessageImage.decode();
|
||||||
|
} catch (err: any) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn("Failed to decode image:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const isLastMessageFullyVisible =
|
||||||
|
lastChatMessage.getBoundingClientRect().y <
|
||||||
|
this.getBoundingClientRect().top + 24;
|
||||||
|
if (!isLastMessageFullyVisible) {
|
||||||
|
lastChatMessage.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||||
}
|
}
|
||||||
scrollContainer.scrollTo(0, scrollContainer.scrollHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleKeyUp(ev: KeyboardEvent) {
|
private _handleKeyUp(ev: KeyboardEvent) {
|
||||||
@@ -586,42 +611,31 @@ export class HaAssistChat extends LitElement {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
.message {
|
.message {
|
||||||
white-space: pre-line;
|
|
||||||
font-size: var(--ha-font-size-l);
|
font-size: var(--ha-font-size-l);
|
||||||
clear: both;
|
clear: both;
|
||||||
|
max-width: -webkit-fill-available;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
scroll-margin-top: 24px;
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border-radius: var(--ha-border-radius-xl);
|
border-radius: var(--ha-border-radius-xl);
|
||||||
}
|
}
|
||||||
.message:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media all and (max-width: 450px), all and (max-height: 500px) {
|
@media all and (max-width: 450px), all and (max-height: 500px) {
|
||||||
.message {
|
.message {
|
||||||
font-size: var(--ha-font-size-l);
|
font-size: var(--ha-font-size-l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.message p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
.message p:not(:last-child) {
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message.user {
|
.message.user {
|
||||||
margin-left: 24px;
|
margin-left: 24px;
|
||||||
margin-inline-start: 24px;
|
margin-inline-start: 24px;
|
||||||
margin-inline-end: initial;
|
margin-inline-end: initial;
|
||||||
align-self: flex-end;
|
align-self: flex-end;
|
||||||
text-align: right;
|
|
||||||
border-bottom-right-radius: 0px;
|
border-bottom-right-radius: 0px;
|
||||||
|
--markdown-link-color: var(--text-primary-color);
|
||||||
background-color: var(--chat-background-color-user, var(--primary-color));
|
background-color: var(--chat-background-color-user, var(--primary-color));
|
||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
.message.hass {
|
.message.hass {
|
||||||
margin-right: 24px;
|
margin-right: 24px;
|
||||||
margin-inline-end: 24px;
|
margin-inline-end: 24px;
|
||||||
@@ -636,20 +650,21 @@ export class HaAssistChat extends LitElement {
|
|||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
.message.user a {
|
|
||||||
color: var(--text-primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.message.hass a {
|
|
||||||
color: var(--primary-text-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.message.error {
|
.message.error {
|
||||||
background-color: var(--error-color);
|
background-color: var(--error-color);
|
||||||
color: var(--text-primary-color);
|
color: var(--text-primary-color);
|
||||||
}
|
}
|
||||||
|
ha-markdown {
|
||||||
|
--markdown-image-border-radius: calc(var(--ha-border-radius-xl) / 2);
|
||||||
|
--markdown-table-border-color: var(--divider-color);
|
||||||
|
--markdown-code-background-color: var(--primary-background-color);
|
||||||
|
--markdown-code-text-color: var(--primary-text-color);
|
||||||
|
&:not(:has(ha-markdown-element)) {
|
||||||
|
min-height: 1lh;
|
||||||
|
min-width: 1lh;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
.bouncer {
|
.bouncer {
|
||||||
width: 48px;
|
width: 48px;
|
||||||
height: 48px;
|
height: 48px;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export class HaAutomationRow extends LitElement {
|
|||||||
}
|
}
|
||||||
.row {
|
.row {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-0) var(--ha-space-2);
|
||||||
min-height: 48px;
|
min-height: 48px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -134,12 +134,12 @@ export class HaAutomationRow extends LitElement {
|
|||||||
.expand-button {
|
.expand-button {
|
||||||
transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
color: var(--ha-color-on-neutral-quiet);
|
color: var(--ha-color-on-neutral-quiet);
|
||||||
margin-left: -8px;
|
margin-left: calc(var(--ha-space-2) * -1);
|
||||||
}
|
}
|
||||||
:host([building-block]) .leading-icon-wrapper {
|
:host([building-block]) .leading-icon-wrapper {
|
||||||
background-color: var(--ha-color-fill-neutral-loud-resting);
|
background-color: var(--ha-color-fill-neutral-loud-resting);
|
||||||
border-radius: var(--ha-border-radius-md);
|
border-radius: var(--ha-border-radius-md);
|
||||||
padding: 4px;
|
padding: var(--ha-space-1);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -149,7 +149,7 @@ export class HaAutomationRow extends LitElement {
|
|||||||
color: var(--ha-color-on-neutral-quiet);
|
color: var(--ha-color-on-neutral-quiet);
|
||||||
}
|
}
|
||||||
:host([building-block]) ::slotted([slot="leading-icon"]) {
|
:host([building-block]) ::slotted([slot="leading-icon"]) {
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: var(--ha-space-5);
|
||||||
color: var(--white-color);
|
color: var(--white-color);
|
||||||
transform: rotate(-45deg);
|
transform: rotate(-45deg);
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ export class HaAutomationRow extends LitElement {
|
|||||||
::slotted([slot="header"]) {
|
::slotted([slot="header"]) {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
margin: 0 12px;
|
margin: var(--ha-space-0) var(--ha-space-3);
|
||||||
}
|
}
|
||||||
:host([sort-selected]) .row {
|
:host([sort-selected]) .row {
|
||||||
outline: solid;
|
outline: solid;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import "@home-assistant/webawesome/dist/components/drawer/drawer";
|
import "@home-assistant/webawesome/dist/components/drawer/drawer";
|
||||||
import { css, html, LitElement, type PropertyValues } from "lit";
|
import { css, html, LitElement, type PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
|
import { SwipeGestureRecognizer } from "../common/util/swipe-gesture-recognizer";
|
||||||
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
|
|
||||||
export const BOTTOM_SHEET_ANIMATION_DURATION_MS = 300;
|
export const BOTTOM_SHEET_ANIMATION_DURATION_MS = 300;
|
||||||
|
|
||||||
@@ -13,6 +15,12 @@ export class HaBottomSheet extends LitElement {
|
|||||||
|
|
||||||
@state() private _drawerOpen = false;
|
@state() private _drawerOpen = false;
|
||||||
|
|
||||||
|
@query("#drawer") private _drawer!: HTMLElement;
|
||||||
|
|
||||||
|
private _gestureRecognizer = new SwipeGestureRecognizer();
|
||||||
|
|
||||||
|
private _isDragging = false;
|
||||||
|
|
||||||
private _handleAfterHide() {
|
private _handleAfterHide() {
|
||||||
this.open = false;
|
this.open = false;
|
||||||
const ev = new Event("closed", {
|
const ev = new Event("closed", {
|
||||||
@@ -32,54 +40,186 @@ export class HaBottomSheet extends LitElement {
|
|||||||
render() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<wa-drawer
|
<wa-drawer
|
||||||
|
id="drawer"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
.open=${this._drawerOpen}
|
.open=${this._drawerOpen}
|
||||||
@wa-after-hide=${this._handleAfterHide}
|
@wa-after-hide=${this._handleAfterHide}
|
||||||
without-header
|
without-header
|
||||||
|
@touchstart=${this._handleTouchStart}
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot name="header"></slot>
|
||||||
|
<div id="body" class="body ha-scrollbar">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
</wa-drawer>
|
</wa-drawer>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
private _handleTouchStart = (ev: TouchEvent) => {
|
||||||
wa-drawer {
|
// Check if any element inside drawer in the composed path has scrollTop > 0
|
||||||
--wa-color-surface-raised: transparent;
|
for (const path of ev.composedPath()) {
|
||||||
--spacing: 0;
|
const el = path as HTMLElement;
|
||||||
--size: var(--ha-bottom-sheet-height, auto);
|
if (el === this._drawer) {
|
||||||
--show-duration: ${BOTTOM_SHEET_ANIMATION_DURATION_MS}ms;
|
break;
|
||||||
--hide-duration: ${BOTTOM_SHEET_ANIMATION_DURATION_MS}ms;
|
}
|
||||||
}
|
if (el.scrollTop > 0) {
|
||||||
wa-drawer::part(dialog) {
|
return;
|
||||||
max-height: var(--ha-bottom-sheet-max-height, 90vh);
|
}
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
wa-drawer::part(body) {
|
|
||||||
max-width: var(--ha-bottom-sheet-max-width);
|
|
||||||
width: 100%;
|
|
||||||
border-top-left-radius: var(
|
|
||||||
--ha-bottom-sheet-border-radius,
|
|
||||||
var(--ha-dialog-border-radius, var(--ha-border-radius-2xl))
|
|
||||||
);
|
|
||||||
border-top-right-radius: var(
|
|
||||||
--ha-bottom-sheet-border-radius,
|
|
||||||
var(--ha-dialog-border-radius, var(--ha-border-radius-2xl))
|
|
||||||
);
|
|
||||||
background-color: var(
|
|
||||||
--ha-bottom-sheet-surface-background,
|
|
||||||
var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)),
|
|
||||||
);
|
|
||||||
padding: var(
|
|
||||||
--ha-bottom-sheet-padding,
|
|
||||||
0 var(--safe-area-inset-right) var(--safe-area-inset-bottom)
|
|
||||||
var(--safe-area-inset-left)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([flexcontent]) wa-drawer::part(body) {
|
this._startResizing(ev.touches[0].clientY);
|
||||||
display: flex;
|
};
|
||||||
|
|
||||||
|
private _startResizing(clientY: number) {
|
||||||
|
// register event listeners for drag handling
|
||||||
|
document.addEventListener("touchmove", this._handleTouchMove, {
|
||||||
|
passive: false,
|
||||||
|
});
|
||||||
|
document.addEventListener("touchend", this._handleTouchEnd);
|
||||||
|
document.addEventListener("touchcancel", this._handleTouchEnd);
|
||||||
|
|
||||||
|
this._gestureRecognizer.start(clientY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleTouchMove = (ev: TouchEvent) => {
|
||||||
|
const currentY = ev.touches[0].clientY;
|
||||||
|
const delta = this._gestureRecognizer.move(currentY);
|
||||||
|
|
||||||
|
if (delta < 0) {
|
||||||
|
ev.preventDefault();
|
||||||
|
this._isDragging = true;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (this._isDragging) {
|
||||||
|
this.style.setProperty(
|
||||||
|
"--dialog-transform",
|
||||||
|
`translateY(${delta * -1}px)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
`;
|
};
|
||||||
|
|
||||||
|
private _animateSnapBack() {
|
||||||
|
// Add transition for smooth animation
|
||||||
|
this.style.setProperty(
|
||||||
|
"--dialog-transition",
|
||||||
|
`transform ${BOTTOM_SHEET_ANIMATION_DURATION_MS}ms ease-out`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reset transform to snap back
|
||||||
|
this.style.removeProperty("--dialog-transform");
|
||||||
|
|
||||||
|
// Remove transition after animation completes
|
||||||
|
setTimeout(() => {
|
||||||
|
this.style.removeProperty("--dialog-transition");
|
||||||
|
}, BOTTOM_SHEET_ANIMATION_DURATION_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleTouchEnd = () => {
|
||||||
|
this._unregisterResizeHandlers();
|
||||||
|
|
||||||
|
this._isDragging = false;
|
||||||
|
|
||||||
|
const result = this._gestureRecognizer.end();
|
||||||
|
|
||||||
|
// If velocity exceeds threshold, use velocity direction to determine action
|
||||||
|
if (result.isSwipe) {
|
||||||
|
if (result.isDownwardSwipe) {
|
||||||
|
// Downward swipe - close the bottom sheet
|
||||||
|
this._drawerOpen = false;
|
||||||
|
} else {
|
||||||
|
// Upward swipe - keep open and animate back
|
||||||
|
this._animateSnapBack();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If velocity is below threshold, use position-based logic
|
||||||
|
// Get the drawer height to calculate 50% threshold
|
||||||
|
const drawerBody = this._drawer.shadowRoot?.querySelector(
|
||||||
|
'[part="body"]'
|
||||||
|
) as HTMLElement;
|
||||||
|
const drawerHeight = drawerBody?.offsetHeight || 0;
|
||||||
|
|
||||||
|
// delta is negative when dragging down
|
||||||
|
// Close if dragged down past 50% of the drawer height
|
||||||
|
if (
|
||||||
|
drawerHeight > 0 &&
|
||||||
|
result.delta < 0 &&
|
||||||
|
Math.abs(result.delta) > drawerHeight * 0.5
|
||||||
|
) {
|
||||||
|
this._drawerOpen = false;
|
||||||
|
} else {
|
||||||
|
this._animateSnapBack();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _unregisterResizeHandlers = () => {
|
||||||
|
document.removeEventListener("touchmove", this._handleTouchMove);
|
||||||
|
document.removeEventListener("touchend", this._handleTouchEnd);
|
||||||
|
document.removeEventListener("touchcancel", this._handleTouchEnd);
|
||||||
|
};
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this._unregisterResizeHandlers();
|
||||||
|
this._isDragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = [
|
||||||
|
haStyleScrollbar,
|
||||||
|
css`
|
||||||
|
wa-drawer {
|
||||||
|
--wa-color-surface-raised: transparent;
|
||||||
|
--spacing: 0;
|
||||||
|
--size: var(--ha-bottom-sheet-height, auto);
|
||||||
|
--show-duration: ${BOTTOM_SHEET_ANIMATION_DURATION_MS}ms;
|
||||||
|
--hide-duration: ${BOTTOM_SHEET_ANIMATION_DURATION_MS}ms;
|
||||||
|
}
|
||||||
|
wa-drawer::part(dialog) {
|
||||||
|
max-height: var(--ha-bottom-sheet-max-height, 90vh);
|
||||||
|
align-items: center;
|
||||||
|
transform: var(--dialog-transform);
|
||||||
|
transition: var(--dialog-transition);
|
||||||
|
}
|
||||||
|
wa-drawer::part(body) {
|
||||||
|
max-width: var(--ha-bottom-sheet-max-width);
|
||||||
|
width: 100%;
|
||||||
|
border-top-left-radius: var(
|
||||||
|
--ha-bottom-sheet-border-radius,
|
||||||
|
var(--ha-dialog-border-radius, var(--ha-border-radius-2xl))
|
||||||
|
);
|
||||||
|
border-top-right-radius: var(
|
||||||
|
--ha-bottom-sheet-border-radius,
|
||||||
|
var(--ha-dialog-border-radius, var(--ha-border-radius-2xl))
|
||||||
|
);
|
||||||
|
background-color: var(
|
||||||
|
--ha-bottom-sheet-surface-background,
|
||||||
|
var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)),
|
||||||
|
);
|
||||||
|
padding: var(
|
||||||
|
--ha-bottom-sheet-padding,
|
||||||
|
0 var(--safe-area-inset-right) var(--safe-area-inset-bottom)
|
||||||
|
var(--safe-area-inset-left)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
:host([flexcontent]) wa-drawer::part(body) {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
:host([flexcontent]) .body {
|
||||||
|
flex: 1;
|
||||||
|
max-width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: var(
|
||||||
|
--ha-bottom-sheet-padding,
|
||||||
|
0 var(--safe-area-inset-right) var(--safe-area-inset-bottom)
|
||||||
|
var(--safe-area-inset-left)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ export class HaButtonToggleGroup extends LitElement {
|
|||||||
@property({ type: Boolean, reflect: true, attribute: "no-wrap" })
|
@property({ type: Boolean, reflect: true, attribute: "no-wrap" })
|
||||||
public nowrap = false;
|
public nowrap = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true, attribute: "full-width" })
|
||||||
|
public fullWidth = false;
|
||||||
|
|
||||||
@property() public variant:
|
@property() public variant:
|
||||||
| "brand"
|
| "brand"
|
||||||
| "neutral"
|
| "neutral"
|
||||||
@@ -38,6 +41,13 @@ export class HaButtonToggleGroup extends LitElement {
|
|||||||
| "warning"
|
| "warning"
|
||||||
| "danger" = "brand";
|
| "danger" = "brand";
|
||||||
|
|
||||||
|
@property({ attribute: "active-variant" }) public activeVariant?:
|
||||||
|
| "brand"
|
||||||
|
| "neutral"
|
||||||
|
| "success"
|
||||||
|
| "warning"
|
||||||
|
| "danger";
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<wa-button-group childSelector="ha-button">
|
<wa-button-group childSelector="ha-button">
|
||||||
@@ -46,7 +56,9 @@ export class HaButtonToggleGroup extends LitElement {
|
|||||||
html`<ha-button
|
html`<ha-button
|
||||||
iconTag="ha-svg-icon"
|
iconTag="ha-svg-icon"
|
||||||
class="icon"
|
class="icon"
|
||||||
.variant=${this.variant}
|
.variant=${this.active !== button.value || !this.activeVariant
|
||||||
|
? this.variant
|
||||||
|
: this.activeVariant}
|
||||||
.size=${this.size}
|
.size=${this.size}
|
||||||
.value=${button.value}
|
.value=${button.value}
|
||||||
@click=${this._handleClick}
|
@click=${this._handleClick}
|
||||||
@@ -78,6 +90,19 @@ export class HaButtonToggleGroup extends LitElement {
|
|||||||
:host([no-wrap]) wa-button-group::part(base) {
|
:host([no-wrap]) wa-button-group::part(base) {
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wa-button-group {
|
||||||
|
padding: var(--ha-button-toggle-group-padding);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([full-width]) wa-button-group,
|
||||||
|
:host([full-width]) wa-button-group::part(base) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([full-width]) ha-button {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export class HaButton extends Button {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
|
||||||
transition: background-color 0.15s ease-in-out;
|
transition: background-color 0.15s ease-in-out;
|
||||||
|
text-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([size="small"]) .button {
|
:host([size="small"]) .button {
|
||||||
|
|||||||
@@ -44,26 +44,26 @@ export class HaCard extends LitElement {
|
|||||||
font-size: var(--ha-card-header-font-size, var(--ha-font-size-2xl));
|
font-size: var(--ha-card-header-font-size, var(--ha-font-size-2xl));
|
||||||
letter-spacing: -0.012em;
|
letter-spacing: -0.012em;
|
||||||
line-height: var(--ha-line-height-expanded);
|
line-height: var(--ha-line-height-expanded);
|
||||||
padding: 12px 16px 16px;
|
padding: var(--ha-space-3) var(--ha-space-4) var(--ha-space-4);
|
||||||
display: block;
|
display: block;
|
||||||
margin-block-start: 0px;
|
margin-block-start: var(--ha-space-0);
|
||||||
margin-block-end: 0px;
|
margin-block-end: var(--ha-space-0);
|
||||||
font-weight: var(--ha-font-weight-normal);
|
font-weight: var(--ha-font-weight-normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::slotted(.card-content:not(:first-child)),
|
:host ::slotted(.card-content:not(:first-child)),
|
||||||
slot:not(:first-child)::slotted(.card-content) {
|
slot:not(:first-child)::slotted(.card-content) {
|
||||||
padding-top: 0px;
|
padding-top: var(--ha-space-0);
|
||||||
margin-top: -8px;
|
margin-top: calc(var(--ha-space-2) * -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::slotted(.card-content) {
|
:host ::slotted(.card-content) {
|
||||||
padding: 16px;
|
padding: var(--ha-space-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::slotted(.card-actions) {
|
:host ::slotted(.card-actions) {
|
||||||
border-top: 1px solid var(--divider-color, #e8e8e8);
|
border-top: 1px solid var(--divider-color, #e8e8e8);
|
||||||
padding: 8px;
|
padding: var(--ha-space-2);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,12 @@ export class HaDateInput extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _keyDown(ev: KeyboardEvent) {
|
private _keyDown(ev: KeyboardEvent) {
|
||||||
|
if (["Space", "Enter"].includes(ev.code)) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
this._openDialog();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.canClear) {
|
if (!this.canClear) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ export class HaDialogHeader extends LitElement {
|
|||||||
@property({ type: String, attribute: "subtitle-position" })
|
@property({ type: String, attribute: "subtitle-position" })
|
||||||
public subtitlePosition: "above" | "below" = "below";
|
public subtitlePosition: "above" | "below" = "below";
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true, attribute: "show-border" })
|
||||||
|
public showBorder = false;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const titleSlot = html`<div class="header-title">
|
const titleSlot = html`<div class="header-title">
|
||||||
<slot name="title"></slot>
|
<slot name="title"></slot>
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ export class HaDialog extends DialogBase {
|
|||||||
}
|
}
|
||||||
.mdc-dialog__actions {
|
.mdc-dialog__actions {
|
||||||
justify-content: var(--justify-action-buttons, flex-end);
|
justify-content: var(--justify-action-buttons, flex-end);
|
||||||
padding: 12px 16px 16px 16px;
|
padding: var(--ha-space-3) var(--ha-space-4) var(--ha-space-4)
|
||||||
|
var(--ha-space-4);
|
||||||
}
|
}
|
||||||
.mdc-dialog__actions span:nth-child(1) {
|
.mdc-dialog__actions span:nth-child(1) {
|
||||||
flex: var(--secondary-action-button-flex, unset);
|
flex: var(--secondary-action-button-flex, unset);
|
||||||
@@ -100,22 +101,24 @@ export class HaDialog extends DialogBase {
|
|||||||
}
|
}
|
||||||
.mdc-dialog__container {
|
.mdc-dialog__container {
|
||||||
align-items: var(--vertical-align-dialog, center);
|
align-items: var(--vertical-align-dialog, center);
|
||||||
|
padding: var(--dialog-container-padding, var(--ha-space-0));
|
||||||
}
|
}
|
||||||
.mdc-dialog__title {
|
.mdc-dialog__title {
|
||||||
padding: 16px 16px 0 16px;
|
padding: var(--ha-space-4) var(--ha-space-4) var(--ha-space-0)
|
||||||
|
var(--ha-space-4);
|
||||||
}
|
}
|
||||||
.mdc-dialog__title:has(span) {
|
.mdc-dialog__title:has(span) {
|
||||||
padding: 12px 12px 0;
|
padding: var(--ha-space-3) var(--ha-space-3) var(--ha-space-0);
|
||||||
}
|
}
|
||||||
.mdc-dialog__title::before {
|
.mdc-dialog__title::before {
|
||||||
content: unset;
|
content: unset;
|
||||||
}
|
}
|
||||||
.mdc-dialog .mdc-dialog__content {
|
.mdc-dialog .mdc-dialog__content {
|
||||||
position: var(--dialog-content-position, relative);
|
position: var(--dialog-content-position, relative);
|
||||||
padding: var(--dialog-content-padding, 24px);
|
padding: var(--dialog-content-padding, var(--ha-space-6));
|
||||||
}
|
}
|
||||||
:host([hideactions]) .mdc-dialog .mdc-dialog__content {
|
:host([hideactions]) .mdc-dialog .mdc-dialog__content {
|
||||||
padding-bottom: var(--dialog-content-padding, 24px);
|
padding-bottom: var(--dialog-content-padding, var(--ha-space-6));
|
||||||
}
|
}
|
||||||
.mdc-dialog .mdc-dialog__surface {
|
.mdc-dialog .mdc-dialog__surface {
|
||||||
position: var(--dialog-surface-position, relative);
|
position: var(--dialog-surface-position, relative);
|
||||||
@@ -133,7 +136,7 @@ export class HaDialog extends DialogBase {
|
|||||||
--ha-dialog-surface-background,
|
--ha-dialog-surface-background,
|
||||||
var(--mdc-theme-surface, #fff)
|
var(--mdc-theme-surface, #fff)
|
||||||
);
|
);
|
||||||
padding: var(--dialog-surface-padding);
|
padding: var(--dialog-surface-padding, var(--ha-space-0));
|
||||||
}
|
}
|
||||||
:host([flexContent]) .mdc-dialog .mdc-dialog__content {
|
:host([flexContent]) .mdc-dialog .mdc-dialog__content {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -150,22 +153,22 @@ export class HaDialog extends DialogBase {
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
display: block;
|
display: block;
|
||||||
padding-left: 4px;
|
padding-left: var(--ha-space-1);
|
||||||
padding-right: 4px;
|
padding-right: var(--ha-space-1);
|
||||||
margin-right: 12px;
|
margin-right: var(--ha-space-3);
|
||||||
margin-inline-end: 12px;
|
margin-inline-end: var(--ha-space-3);
|
||||||
margin-inline-start: initial;
|
margin-inline-start: initial;
|
||||||
}
|
}
|
||||||
.header_button {
|
.header_button {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
inset-inline-start: initial;
|
inset-inline-start: initial;
|
||||||
inset-inline-end: -12px;
|
inset-inline-end: calc(var(--ha-space-3) * -1);
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
.dialog-actions {
|
.dialog-actions {
|
||||||
inset-inline-start: initial !important;
|
inset-inline-start: initial !important;
|
||||||
inset-inline-end: 0px !important;
|
inset-inline-end: var(--ha-space-0) !important;
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|||||||
41
src/components/ha-dropdown-item.ts
Normal file
41
src/components/ha-dropdown-item.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item";
|
||||||
|
import { css, type CSSResultGroup } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Home Assistant dropdown item component
|
||||||
|
*
|
||||||
|
* @element ha-dropdown-item
|
||||||
|
* @extends {DropdownItem}
|
||||||
|
*
|
||||||
|
* @summary
|
||||||
|
* A stylable dropdown item component supporting Home Assistant theming, variants, and appearances based on webawesome dropdown item.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@customElement("ha-dropdown-item")
|
||||||
|
export class HaDropdownItem extends DropdownItem {
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
DropdownItem.styles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
min-height: var(--ha-space-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#icon ::slotted(*) {
|
||||||
|
color: var(--ha-color-on-neutral-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([variant="danger"]) #icon ::slotted(*) {
|
||||||
|
color: var(--ha-color-on-danger-quiet);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dropdown-item": HaDropdownItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/components/ha-dropdown.ts
Normal file
45
src/components/ha-dropdown.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import Dropdown from "@home-assistant/webawesome/dist/components/dropdown/dropdown";
|
||||||
|
import { css, type CSSResultGroup } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Home Assistant dropdown component
|
||||||
|
*
|
||||||
|
* @element ha-dropdown
|
||||||
|
* @extends {Dropdown}
|
||||||
|
*
|
||||||
|
* @summary
|
||||||
|
* A stylable dropdown component supporting Home Assistant theming, variants, and appearances based on webawesome dropdown.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@customElement("ha-dropdown")
|
||||||
|
export class HaDropdown extends Dropdown {
|
||||||
|
@property({ attribute: false }) dropdownTag = "ha-dropdown";
|
||||||
|
|
||||||
|
@property({ attribute: false }) dropdownItemTag = "ha-dropdown-item";
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
Dropdown.styles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
font-size: var(--ha-dropdown-font-size, var(--ha-font-size-m));
|
||||||
|
--wa-color-surface-raised: var(
|
||||||
|
--card-background-color,
|
||||||
|
var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#menu {
|
||||||
|
padding: var(--ha-space-1);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dropdown": HaDropdown;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -248,7 +248,7 @@ export class HaFilterDevices extends LitElement {
|
|||||||
}
|
}
|
||||||
search-input-outlined {
|
search-input-outlined {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-1) var(--ha-space-2) 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ export class HaFilterDomains extends LitElement {
|
|||||||
}
|
}
|
||||||
search-input-outlined {
|
search-input-outlined {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-1) var(--ha-space-2) 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ export class HaFilterEntities extends LitElement {
|
|||||||
}
|
}
|
||||||
search-input-outlined {
|
search-input-outlined {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-1) var(--ha-space-2) 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
}
|
}
|
||||||
search-input-outlined {
|
search-input-outlined {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-1) var(--ha-space-2) 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -109,7 +109,10 @@ export class HaFilterLabels extends SubscribeMixin(LitElement) {
|
|||||||
.selected=${(this.value || []).includes(label.label_id)}
|
.selected=${(this.value || []).includes(label.label_id)}
|
||||||
hasMeta
|
hasMeta
|
||||||
>
|
>
|
||||||
<ha-label style=${color ? `--color: ${color}` : ""}>
|
<ha-label
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
.description=${label.description}
|
||||||
|
>
|
||||||
${label.icon
|
${label.icon
|
||||||
? html`<ha-icon
|
? html`<ha-icon
|
||||||
slot="icon"
|
slot="icon"
|
||||||
@@ -256,7 +259,7 @@ export class HaFilterLabels extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
search-input-outlined {
|
search-input-outlined {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 0 8px;
|
padding: var(--ha-space-1) var(--ha-space-2) 0;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -383,8 +383,9 @@ export class HaFloorPicker extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.floor-picker.no_match"
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.floor-picker.no_floors"
|
||||||
)}
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
@@ -444,6 +445,11 @@ export class HaFloorPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.floor-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ export class HaForm extends LitElement implements HaFormElement {
|
|||||||
.value=${getValue(this.data, item)}
|
.value=${getValue(this.data, item)}
|
||||||
.label=${this._computeLabel(item, this.data)}
|
.label=${this._computeLabel(item, this.data)}
|
||||||
.disabled=${item.disabled || this.disabled || false}
|
.disabled=${item.disabled || this.disabled || false}
|
||||||
.placeholder=${item.required ? "" : item.default}
|
.placeholder=${item.required ? undefined : item.default}
|
||||||
.helper=${this._computeHelper(item)}
|
.helper=${this._computeHelper(item)}
|
||||||
.localizeValue=${this.localizeValue}
|
.localizeValue=${this.localizeValue}
|
||||||
.required=${item.required || false}
|
.required=${item.required || false}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import "@home-assistant/webawesome/dist/components/popover/popover";
|
||||||
import type { ComboBoxLightOpenedChangedEvent } from "@vaadin/combo-box/vaadin-combo-box-light";
|
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||||
|
import { mdiPlaylistPlus } from "@mdi/js";
|
||||||
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
|
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import { tinykeys } from "tinykeys";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./ha-bottom-sheet";
|
||||||
|
import "./ha-button";
|
||||||
import "./ha-combo-box-item";
|
import "./ha-combo-box-item";
|
||||||
import "./ha-icon-button";
|
|
||||||
import "./ha-input-helper-text";
|
import "./ha-input-helper-text";
|
||||||
import "./ha-picker-combo-box";
|
import "./ha-picker-combo-box";
|
||||||
import type {
|
import type {
|
||||||
@@ -15,15 +18,12 @@ import type {
|
|||||||
PickerComboBoxSearchFn,
|
PickerComboBoxSearchFn,
|
||||||
} from "./ha-picker-combo-box";
|
} from "./ha-picker-combo-box";
|
||||||
import "./ha-picker-field";
|
import "./ha-picker-field";
|
||||||
import type { HaPickerField, PickerValueRenderer } from "./ha-picker-field";
|
import type { PickerValueRenderer } from "./ha-picker-field";
|
||||||
import "./ha-svg-icon";
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
@customElement("ha-generic-picker")
|
@customElement("ha-generic-picker")
|
||||||
export class HaGenericPicker extends LitElement {
|
export class HaGenericPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
// eslint-disable-next-line lit/no-native-attributes
|
|
||||||
@property({ type: Boolean }) public autofocus = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@@ -46,14 +46,17 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false })
|
||||||
public getItems?: () => PickerComboBoxItem[];
|
public getItems?: (
|
||||||
|
searchString?: string,
|
||||||
|
section?: string
|
||||||
|
) => (PickerComboBoxItem | string)[];
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false, type: Array })
|
||||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public rowRenderer?: ComboBoxLitRenderer<PickerComboBoxItem>;
|
public rowRenderer?: RenderItemFunction<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public valueRenderer?: PickerValueRenderer;
|
public valueRenderer?: PickerValueRenderer;
|
||||||
@@ -61,62 +64,175 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ attribute: "not-found-label", type: String })
|
@property({ attribute: false })
|
||||||
public notFoundLabel?: string;
|
public notFoundLabel?: string | ((search: string) => string);
|
||||||
|
|
||||||
@query("ha-picker-field") private _field?: HaPickerField;
|
@property({ attribute: "empty-label" })
|
||||||
|
public emptyLabel?: string;
|
||||||
|
|
||||||
|
@property({ attribute: "popover-placement" })
|
||||||
|
public popoverPlacement:
|
||||||
|
| "bottom"
|
||||||
|
| "top"
|
||||||
|
| "left"
|
||||||
|
| "right"
|
||||||
|
| "top-start"
|
||||||
|
| "top-end"
|
||||||
|
| "right-start"
|
||||||
|
| "right-end"
|
||||||
|
| "bottom-start"
|
||||||
|
| "bottom-end"
|
||||||
|
| "left-start"
|
||||||
|
| "left-end" = "bottom-start";
|
||||||
|
|
||||||
|
/** If set picker shows an add button instead of textbox when value isn't set */
|
||||||
|
@property({ attribute: "add-button-label" }) public addButtonLabel?: string;
|
||||||
|
|
||||||
|
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||||
|
@property({ attribute: false }) public sections?: (
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
| "separator"
|
||||||
|
)[];
|
||||||
|
|
||||||
|
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||||
|
firstIndex: number;
|
||||||
|
lastIndex: number;
|
||||||
|
firstItem: PickerComboBoxItem | string;
|
||||||
|
secondItem: PickerComboBoxItem | string;
|
||||||
|
itemsCount: number;
|
||||||
|
}) => string | undefined;
|
||||||
|
|
||||||
|
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||||
|
|
||||||
|
@query(".container") private _containerElement?: HTMLDivElement;
|
||||||
|
|
||||||
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
||||||
|
|
||||||
@state() private _opened = false;
|
@state() private _opened = false;
|
||||||
|
|
||||||
|
@state() private _pickerWrapperOpen = false;
|
||||||
|
|
||||||
|
@state() private _popoverWidth = 0;
|
||||||
|
|
||||||
|
@state() private _openedNarrow = false;
|
||||||
|
|
||||||
|
static shadowRootOptions = {
|
||||||
|
...LitElement.shadowRootOptions,
|
||||||
|
delegatesFocus: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
private _narrow = false;
|
||||||
|
|
||||||
|
// helper to set new value after closing picker, to avoid flicker
|
||||||
|
private _newValue?: string;
|
||||||
|
|
||||||
|
private _unsubscribeTinyKeys?: () => void;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.label
|
${this.label
|
||||||
? html`<label ?disabled=${this.disabled}>${this.label}</label>`
|
? html`<label ?disabled=${this.disabled}>${this.label}</label>`
|
||||||
: nothing}
|
: nothing}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
${!this._opened
|
<div id="picker">
|
||||||
|
<slot name="field">
|
||||||
|
${this.addButtonLabel && !this.value
|
||||||
|
? html`<ha-button
|
||||||
|
size="small"
|
||||||
|
appearance="filled"
|
||||||
|
@click=${this.open}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
>
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${mdiPlaylistPlus}
|
||||||
|
slot="start"
|
||||||
|
></ha-svg-icon>
|
||||||
|
${this.addButtonLabel}
|
||||||
|
</ha-button>`
|
||||||
|
: html`<ha-picker-field
|
||||||
|
type="button"
|
||||||
|
class=${this._opened ? "opened" : ""}
|
||||||
|
compact
|
||||||
|
aria-label=${ifDefined(this.label)}
|
||||||
|
@click=${this.open}
|
||||||
|
@clear=${this._clear}
|
||||||
|
.placeholder=${this.placeholder}
|
||||||
|
.value=${this.value}
|
||||||
|
.required=${this.required}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
|
.valueRenderer=${this.valueRenderer}
|
||||||
|
>
|
||||||
|
</ha-picker-field>`}
|
||||||
|
</slot>
|
||||||
|
</div>
|
||||||
|
${!this._openedNarrow && (this._pickerWrapperOpen || this._opened)
|
||||||
? html`
|
? html`
|
||||||
<ha-picker-field
|
<wa-popover
|
||||||
id="picker"
|
.open=${this._pickerWrapperOpen}
|
||||||
type="button"
|
style="--body-width: ${this._popoverWidth}px;"
|
||||||
compact
|
without-arrow
|
||||||
aria-label=${ifDefined(this.label)}
|
distance="-4"
|
||||||
@click=${this.open}
|
.placement=${this.popoverPlacement}
|
||||||
@clear=${this._clear}
|
for="picker"
|
||||||
.placeholder=${this.placeholder}
|
auto-size="vertical"
|
||||||
.value=${this.value}
|
auto-size-padding="16"
|
||||||
.required=${this.required}
|
@wa-after-show=${this._dialogOpened}
|
||||||
.disabled=${this.disabled}
|
@wa-after-hide=${this._hidePicker}
|
||||||
.hideClearIcon=${this.hideClearIcon}
|
trap-focus
|
||||||
.valueRenderer=${this.valueRenderer}
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label=${this.label || "Select option"}
|
||||||
>
|
>
|
||||||
</ha-picker-field>
|
${this._renderComboBox()}
|
||||||
|
</wa-popover>
|
||||||
`
|
`
|
||||||
: html`
|
: this._pickerWrapperOpen || this._opened
|
||||||
<ha-picker-combo-box
|
? html`<ha-bottom-sheet
|
||||||
.hass=${this.hass}
|
flexcontent
|
||||||
.autofocus=${this.autofocus}
|
.open=${this._pickerWrapperOpen}
|
||||||
.allowCustomValue=${this.allowCustomValue}
|
@wa-after-show=${this._dialogOpened}
|
||||||
.label=${this.searchLabel ??
|
@closed=${this._hidePicker}
|
||||||
this.hass.localize("ui.common.search")}
|
role="dialog"
|
||||||
.value=${this.value}
|
aria-modal="true"
|
||||||
hide-clear-icon
|
aria-label=${this.label || "Select option"}
|
||||||
@opened-changed=${this._openedChanged}
|
>
|
||||||
@value-changed=${this._valueChanged}
|
${this._renderComboBox(true)}
|
||||||
.rowRenderer=${this.rowRenderer}
|
</ha-bottom-sheet>`
|
||||||
.notFoundLabel=${this.notFoundLabel}
|
: nothing}
|
||||||
.getItems=${this.getItems}
|
|
||||||
.getAdditionalItems=${this.getAdditionalItems}
|
|
||||||
.searchFn=${this.searchFn}
|
|
||||||
></ha-picker-combo-box>
|
|
||||||
`}
|
|
||||||
</div>
|
</div>
|
||||||
${this._renderHelper()}
|
${this._renderHelper()}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderComboBox(dialogMode = false) {
|
||||||
|
if (!this._opened) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
return html`
|
||||||
|
<ha-picker-combo-box
|
||||||
|
.hass=${this.hass}
|
||||||
|
.allowCustomValue=${this.allowCustomValue}
|
||||||
|
.label=${this.searchLabel}
|
||||||
|
.value=${this.value}
|
||||||
|
@value-changed=${this._valueChanged}
|
||||||
|
.rowRenderer=${this.rowRenderer}
|
||||||
|
.notFoundLabel=${this.notFoundLabel}
|
||||||
|
.emptyLabel=${this.emptyLabel}
|
||||||
|
.getItems=${this.getItems}
|
||||||
|
.getAdditionalItems=${this.getAdditionalItems}
|
||||||
|
.searchFn=${this.searchFn}
|
||||||
|
.mode=${dialogMode ? "dialog" : "popover"}
|
||||||
|
.sections=${this.sections}
|
||||||
|
.sectionTitleFunction=${this.sectionTitleFunction}
|
||||||
|
.selectedSection=${this.selectedSection}
|
||||||
|
></ha-picker-combo-box>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
private _renderHelper() {
|
private _renderHelper() {
|
||||||
return this.helper
|
return this.helper
|
||||||
? html`<ha-input-helper-text .disabled=${this.disabled}
|
? html`<ha-input-helper-text .disabled=${this.disabled}
|
||||||
@@ -125,13 +241,33 @@ export class HaGenericPicker extends LitElement {
|
|||||||
: nothing;
|
: nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _dialogOpened = () => {
|
||||||
|
this._opened = true;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
this._comboBox?.focus();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _hidePicker(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
if (this._newValue) {
|
||||||
|
fireEvent(this, "value-changed", { value: this._newValue });
|
||||||
|
this._newValue = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._opened = false;
|
||||||
|
this._pickerWrapperOpen = false;
|
||||||
|
this._unsubscribeTinyKeys?.();
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private _valueChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const value = ev.detail.value;
|
const value = ev.detail.value;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fireEvent(this, "value-changed", { value });
|
this._pickerWrapperOpen = false;
|
||||||
|
this._newValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _clear(e) {
|
private _clear(e) {
|
||||||
@@ -144,25 +280,45 @@ export class HaGenericPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async open() {
|
public async open(ev?: Event) {
|
||||||
|
ev?.stopPropagation();
|
||||||
if (this.disabled) {
|
if (this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._opened = true;
|
this._openedNarrow = this._narrow;
|
||||||
await this.updateComplete;
|
this._popoverWidth = this._containerElement?.offsetWidth || 250;
|
||||||
this._comboBox?.focus();
|
this._pickerWrapperOpen = true;
|
||||||
this._comboBox?.open();
|
this._unsubscribeTinyKeys = tinykeys(this, {
|
||||||
|
Escape: this._handleEscClose,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _openedChanged(ev: ComboBoxLightOpenedChangedEvent) {
|
connectedCallback() {
|
||||||
const opened = ev.detail.value;
|
super.connectedCallback();
|
||||||
if (this._opened && !opened) {
|
this._handleResize();
|
||||||
this._opened = false;
|
window.addEventListener("resize", this._handleResize);
|
||||||
await this.updateComplete;
|
|
||||||
this._field?.focus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
window.removeEventListener("resize", this._handleResize);
|
||||||
|
this._unsubscribeTinyKeys?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleResize = () => {
|
||||||
|
this._narrow =
|
||||||
|
window.matchMedia("(max-width: 870px)").matches ||
|
||||||
|
window.matchMedia("(max-height: 500px)").matches;
|
||||||
|
|
||||||
|
if (!this._openedNarrow && this._pickerWrapperOpen) {
|
||||||
|
this._popoverWidth = this._containerElement?.offsetWidth || 250;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _handleEscClose = (ev: KeyboardEvent) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
};
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
css`
|
css`
|
||||||
@@ -181,6 +337,44 @@ export class HaGenericPicker extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
margin: var(--ha-space-2) 0 0;
|
margin: var(--ha-space-2) 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wa-popover {
|
||||||
|
--wa-space-l: var(--ha-space-0);
|
||||||
|
}
|
||||||
|
|
||||||
|
wa-popover::part(body) {
|
||||||
|
width: max(var(--body-width), 250px);
|
||||||
|
max-width: max(var(--body-width), 250px);
|
||||||
|
max-height: 500px;
|
||||||
|
height: 70vh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-height: 1000px) {
|
||||||
|
wa-popover::part(body) {
|
||||||
|
max-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-height: 1000px) {
|
||||||
|
wa-popover::part(body) {
|
||||||
|
max-height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-bottom-sheet {
|
||||||
|
--ha-bottom-sheet-height: 90vh;
|
||||||
|
--ha-bottom-sheet-height: calc(100dvh - var(--ha-space-12));
|
||||||
|
--ha-bottom-sheet-max-height: var(--ha-bottom-sheet-height);
|
||||||
|
--ha-bottom-sheet-max-width: 600px;
|
||||||
|
--ha-bottom-sheet-padding: var(--ha-space-0);
|
||||||
|
--ha-bottom-sheet-surface-background: var(--card-background-color);
|
||||||
|
--ha-bottom-sheet-border-radius: var(--ha-border-radius-2xl);
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-picker-field.opened {
|
||||||
|
--mdc-text-field-idle-line-color: var(--primary-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ class HaHLSPlayer extends LitElement {
|
|||||||
private static streamCount = 0;
|
private static streamCount = 0;
|
||||||
|
|
||||||
private _handleVisibilityChange = () => {
|
private _handleVisibilityChange = () => {
|
||||||
|
if (document.pictureInPictureElement) {
|
||||||
|
// video is playing in picture-in-picture mode, don't do anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
this._cleanUp();
|
this._cleanUp();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import { mdiLabel, mdiPlus } from "@mdi/js";
|
|||||||
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { LitElement, html } from "lit";
|
import { LitElement, html } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import {
|
||||||
|
customElement,
|
||||||
|
property,
|
||||||
|
query,
|
||||||
|
queryAssignedElements,
|
||||||
|
state,
|
||||||
|
} from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import type { LabelRegistryEntry } from "../data/label_registry";
|
import type { LabelRegistryEntry } from "../data/label_registry";
|
||||||
@@ -84,6 +90,9 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _labels?: LabelRegistryEntry[];
|
@state() private _labels?: LabelRegistryEntry[];
|
||||||
|
|
||||||
|
@queryAssignedElements({ flatten: true })
|
||||||
|
private _slotNodes?: NodeListOf<HTMLElement>;
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||||
|
|
||||||
public async open() {
|
public async open() {
|
||||||
@@ -211,12 +220,15 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
|
.disabled=${this.disabled}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label}
|
.label=${this.label}
|
||||||
.notFoundLabel=${this.hass.localize(
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
"ui.components.label-picker.no_match"
|
.emptyLabel=${this.hass.localize(
|
||||||
|
"ui.components.label-picker.no_labels"
|
||||||
)}
|
)}
|
||||||
|
.addButtonLabel=${this.hass.localize("ui.components.label-picker.add")}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
@@ -224,6 +236,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
|
<slot .slot=${this._slotNodes?.length ? "field" : undefined}></slot>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -276,6 +289,11 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
fireEvent(this, "change");
|
fireEvent(this, "change");
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) =>
|
||||||
|
this.hass.localize("ui.components.label-picker.no_match", {
|
||||||
|
term: html`<b>‘${search}’</b>`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { uid } from "../common/util/uid";
|
||||||
|
import "./ha-tooltip";
|
||||||
|
|
||||||
@customElement("ha-label")
|
@customElement("ha-label")
|
||||||
class HaLabel extends LitElement {
|
class HaLabel extends LitElement {
|
||||||
@property({ type: Boolean, reflect: true }) dense = false;
|
@property({ type: Boolean, reflect: true }) dense = false;
|
||||||
|
|
||||||
|
@property({ attribute: "description" })
|
||||||
|
public description?: string;
|
||||||
|
|
||||||
|
private _elementId = "label-" + uid();
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<span class="content">
|
<ha-tooltip
|
||||||
<slot name="icon"></slot>
|
.for=${this._elementId}
|
||||||
<slot></slot>
|
.disabled=${!this.description?.trim()}
|
||||||
</span>
|
>
|
||||||
|
${this.description}
|
||||||
|
</ha-tooltip>
|
||||||
|
<div class="container" .id=${this._elementId}>
|
||||||
|
<span class="content">
|
||||||
|
<slot name="icon"></slot>
|
||||||
|
<slot></slot>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,9 +51,7 @@ class HaLabel extends LitElement {
|
|||||||
font-weight: var(--ha-font-weight-medium);
|
font-weight: var(--ha-font-weight-medium);
|
||||||
line-height: var(--ha-line-height-condensed);
|
line-height: var(--ha-line-height-condensed);
|
||||||
letter-spacing: 0.1px;
|
letter-spacing: 0.1px;
|
||||||
vertical-align: middle;
|
|
||||||
height: 32px;
|
height: 32px;
|
||||||
padding: 0 16px;
|
|
||||||
border-radius: var(--ha-border-radius-xl);
|
border-radius: var(--ha-border-radius-xl);
|
||||||
color: var(--ha-label-text-color);
|
color: var(--ha-label-text-color);
|
||||||
--mdc-icon-size: 12px;
|
--mdc-icon-size: 12px;
|
||||||
@@ -66,15 +79,24 @@ class HaLabel extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([dense]) {
|
:host([dense]) {
|
||||||
height: 20px;
|
height: 20px;
|
||||||
padding: 0 12px;
|
|
||||||
border-radius: var(--ha-border-radius-md);
|
border-radius: var(--ha-border-radius-md);
|
||||||
}
|
}
|
||||||
|
:host([dense]) .container {
|
||||||
|
padding: 0 12px;
|
||||||
|
}
|
||||||
:host([dense]) ::slotted([slot="icon"]) {
|
:host([dense]) ::slotted([slot="icon"]) {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
margin-left: -4px;
|
margin-left: -4px;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { mdiPlaylistPlus } from "@mdi/js";
|
||||||
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
@@ -20,6 +21,7 @@ import "./chips/ha-input-chip";
|
|||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||||
import "./ha-label-picker";
|
import "./ha-label-picker";
|
||||||
import type { HaLabelPicker } from "./ha-label-picker";
|
import type { HaLabelPicker } from "./ha-label-picker";
|
||||||
|
import "./ha-tooltip";
|
||||||
|
|
||||||
@customElement("ha-labels-picker")
|
@customElement("ha-labels-picker")
|
||||||
export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
||||||
@@ -123,36 +125,6 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
);
|
);
|
||||||
return html`
|
return html`
|
||||||
${this.label ? html`<label>${this.label}</label>` : nothing}
|
${this.label ? html`<label>${this.label}</label>` : nothing}
|
||||||
${labels?.length
|
|
||||||
? html`<ha-chip-set>
|
|
||||||
${repeat(
|
|
||||||
labels,
|
|
||||||
(label) => label?.label_id,
|
|
||||||
(label) => {
|
|
||||||
const color = label?.color
|
|
||||||
? computeCssColor(label.color)
|
|
||||||
: undefined;
|
|
||||||
return html`
|
|
||||||
<ha-input-chip
|
|
||||||
.item=${label}
|
|
||||||
@remove=${this._removeItem}
|
|
||||||
@click=${this._openDetail}
|
|
||||||
.label=${label?.name}
|
|
||||||
selected
|
|
||||||
style=${color ? `--color: ${color}` : ""}
|
|
||||||
>
|
|
||||||
${label?.icon
|
|
||||||
? html`<ha-icon
|
|
||||||
slot="icon"
|
|
||||||
.icon=${label.icon}
|
|
||||||
></ha-icon>`
|
|
||||||
: nothing}
|
|
||||||
</ha-input-chip>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
</ha-chip-set>`
|
|
||||||
: nothing}
|
|
||||||
<ha-label-picker
|
<ha-label-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
@@ -162,6 +134,55 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
.excludeLabels=${this.value}
|
.excludeLabels=${this.value}
|
||||||
@value-changed=${this._labelChanged}
|
@value-changed=${this._labelChanged}
|
||||||
>
|
>
|
||||||
|
<ha-chip-set>
|
||||||
|
${labels?.length
|
||||||
|
? repeat(
|
||||||
|
labels,
|
||||||
|
(label) => label?.label_id,
|
||||||
|
(label) => {
|
||||||
|
const color = label?.color
|
||||||
|
? computeCssColor(label.color)
|
||||||
|
: undefined;
|
||||||
|
const elementId = "label-" + label.label_id;
|
||||||
|
return html`
|
||||||
|
<ha-tooltip
|
||||||
|
.for=${elementId}
|
||||||
|
.disabled=${!label?.description?.trim()}
|
||||||
|
>
|
||||||
|
${label?.description}
|
||||||
|
</ha-tooltip>
|
||||||
|
<ha-input-chip
|
||||||
|
.item=${label}
|
||||||
|
.id=${elementId}
|
||||||
|
@remove=${this._removeItem}
|
||||||
|
@click=${this._openDetail}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
.label=${label?.name}
|
||||||
|
selected
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
>
|
||||||
|
${label?.icon
|
||||||
|
? html`<ha-icon
|
||||||
|
slot="icon"
|
||||||
|
.icon=${label.icon}
|
||||||
|
></ha-icon>`
|
||||||
|
: nothing}
|
||||||
|
</ha-input-chip>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: nothing}
|
||||||
|
<ha-button
|
||||||
|
id="picker"
|
||||||
|
size="small"
|
||||||
|
appearance="filled"
|
||||||
|
@click=${this._openPicker}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
>
|
||||||
|
<ha-svg-icon .path=${mdiPlaylistPlus} slot="start"></ha-svg-icon>
|
||||||
|
${this.hass.localize("ui.components.label-picker.add")}
|
||||||
|
</ha-button>
|
||||||
|
</ha-chip-set>
|
||||||
</ha-label-picker>
|
</ha-label-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -203,9 +224,25 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _openPicker(ev: Event) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.labelPicker.open();
|
||||||
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
ha-chip-set {
|
ha-chip-set {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
|
background-color: var(--mdc-text-field-fill-color);
|
||||||
|
border-bottom: 1px solid var(--ha-color-border-neutral-normal);
|
||||||
|
border-top-right-radius: var(--ha-border-radius-sm);
|
||||||
|
border-top-left-radius: var(--ha-border-radius-sm);
|
||||||
|
padding: var(--ha-space-3);
|
||||||
|
}
|
||||||
|
.placeholder {
|
||||||
|
color: var(--mdc-text-field-label-ink-color);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: var(--ha-space-8);
|
||||||
}
|
}
|
||||||
ha-input-chip {
|
ha-input-chip {
|
||||||
--md-input-chip-selected-container-color: var(--color, var(--grey-color));
|
--md-input-chip-selected-container-color: var(--color, var(--grey-color));
|
||||||
|
|||||||
@@ -1,56 +1,59 @@
|
|||||||
|
import { mdiMenuDown } from "@mdi/js";
|
||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { stopPropagation } from "../common/dom/stop_propagation";
|
|
||||||
import { formatLanguageCode } from "../common/language/format_language";
|
import { formatLanguageCode } from "../common/language/format_language";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import type { FrontendLocaleData } from "../data/translation";
|
import type { FrontendLocaleData } from "../data/translation";
|
||||||
import { translationMetadata } from "../resources/translations-metadata";
|
import { translationMetadata } from "../resources/translations-metadata";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
||||||
import "./ha-list-item";
|
import "./ha-button";
|
||||||
import "./ha-select";
|
import "./ha-generic-picker";
|
||||||
import type { HaSelect } from "./ha-select";
|
import type { HaGenericPicker } from "./ha-generic-picker";
|
||||||
|
import type { PickerComboBoxItem } from "./ha-picker-combo-box";
|
||||||
|
|
||||||
export const getLanguageOptions = (
|
export const getLanguageOptions = (
|
||||||
languages: string[],
|
languages: string[],
|
||||||
nativeName: boolean,
|
nativeName: boolean,
|
||||||
noSort: boolean,
|
noSort: boolean,
|
||||||
locale?: FrontendLocaleData
|
locale?: FrontendLocaleData
|
||||||
) => {
|
): PickerComboBoxItem[] => {
|
||||||
let options: { label: string; value: string }[] = [];
|
let options: PickerComboBoxItem[] = [];
|
||||||
|
|
||||||
if (nativeName) {
|
if (nativeName) {
|
||||||
const translations = translationMetadata.translations;
|
const translations = translationMetadata.translations;
|
||||||
options = languages.map((lang) => {
|
options = languages.map((lang) => {
|
||||||
let label = translations[lang]?.nativeName;
|
let primary = translations[lang]?.nativeName;
|
||||||
if (!label) {
|
if (!primary) {
|
||||||
try {
|
try {
|
||||||
// this will not work if Intl.DisplayNames is polyfilled, it will return in the language of the user
|
// this will not work if Intl.DisplayNames is polyfilled, it will return in the language of the user
|
||||||
label = new Intl.DisplayNames(lang, {
|
primary = new Intl.DisplayNames(lang, {
|
||||||
type: "language",
|
type: "language",
|
||||||
fallback: "code",
|
fallback: "code",
|
||||||
}).of(lang)!;
|
}).of(lang)!;
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
label = lang;
|
primary = lang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
value: lang,
|
id: lang,
|
||||||
label,
|
primary,
|
||||||
|
search_labels: [primary],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else if (locale) {
|
} else if (locale) {
|
||||||
options = languages.map((lang) => ({
|
options = languages.map((lang) => ({
|
||||||
value: lang,
|
id: lang,
|
||||||
label: formatLanguageCode(lang, locale),
|
primary: formatLanguageCode(lang, locale),
|
||||||
|
search_labels: [formatLanguageCode(lang, locale)],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!noSort && locale) {
|
if (!noSort && locale) {
|
||||||
options.sort((a, b) =>
|
options.sort((a, b) =>
|
||||||
caseInsensitiveStringCompare(a.label, b.label, locale.language)
|
caseInsensitiveStringCompare(a.primary, b.primary, locale.language)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
@@ -73,6 +76,9 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
@property({ attribute: "native-name", type: Boolean })
|
@property({ attribute: "native-name", type: Boolean })
|
||||||
public nativeName = false;
|
public nativeName = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "button-style" })
|
||||||
|
public buttonStyle = false;
|
||||||
|
|
||||||
@property({ attribute: "no-sort", type: Boolean }) public noSort = false;
|
@property({ attribute: "no-sort", type: Boolean }) public noSort = false;
|
||||||
|
|
||||||
@property({ attribute: "inline-arrow", type: Boolean })
|
@property({ attribute: "inline-arrow", type: Boolean })
|
||||||
@@ -80,117 +86,102 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
|
|
||||||
@state() _defaultLanguages: string[] = [];
|
@state() _defaultLanguages: string[] = [];
|
||||||
|
|
||||||
@query("ha-select") private _select!: HaSelect;
|
@query("ha-generic-picker", true) public genericPicker!: HaGenericPicker;
|
||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this._computeDefaultLanguageOptions();
|
this._computeDefaultLanguageOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
|
||||||
super.updated(changedProperties);
|
|
||||||
|
|
||||||
const localeChanged =
|
|
||||||
changedProperties.has("hass") &&
|
|
||||||
this.hass &&
|
|
||||||
changedProperties.get("hass") &&
|
|
||||||
changedProperties.get("hass").locale.language !==
|
|
||||||
this.hass.locale.language;
|
|
||||||
if (
|
|
||||||
changedProperties.has("languages") ||
|
|
||||||
changedProperties.has("value") ||
|
|
||||||
localeChanged
|
|
||||||
) {
|
|
||||||
this._select.layoutOptions();
|
|
||||||
if (!this.disabled && this._select.value !== this.value) {
|
|
||||||
fireEvent(this, "value-changed", { value: this._select.value });
|
|
||||||
}
|
|
||||||
if (!this.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const languageOptions = this._getLanguagesOptions(
|
|
||||||
this.languages ?? this._defaultLanguages,
|
|
||||||
this.nativeName,
|
|
||||||
this.noSort,
|
|
||||||
this.hass?.locale
|
|
||||||
);
|
|
||||||
const selectedItemIndex = languageOptions.findIndex(
|
|
||||||
(option) => option.value === this.value
|
|
||||||
);
|
|
||||||
if (selectedItemIndex === -1) {
|
|
||||||
this.value = undefined;
|
|
||||||
}
|
|
||||||
if (localeChanged) {
|
|
||||||
this._select.select(selectedItemIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getLanguagesOptions = memoizeOne(getLanguageOptions);
|
private _getLanguagesOptions = memoizeOne(getLanguageOptions);
|
||||||
|
|
||||||
private _computeDefaultLanguageOptions() {
|
private _computeDefaultLanguageOptions() {
|
||||||
this._defaultLanguages = Object.keys(translationMetadata.translations);
|
this._defaultLanguages = Object.keys(translationMetadata.translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
private _getItems = () =>
|
||||||
const languageOptions = this._getLanguagesOptions(
|
this._getLanguagesOptions(
|
||||||
this.languages ?? this._defaultLanguages,
|
this.languages ?? this._defaultLanguages,
|
||||||
this.nativeName,
|
this.nativeName,
|
||||||
this.noSort,
|
this.noSort,
|
||||||
this.hass?.locale
|
this.hass?.locale
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _getLanguageName = (lang?: string) =>
|
||||||
|
this._getItems().find((language) => language.id === lang)?.primary;
|
||||||
|
|
||||||
|
private _valueRenderer = (value) =>
|
||||||
|
html`<span slot="headline"
|
||||||
|
>${this._getLanguageName(value) ?? value}</span
|
||||||
|
> `;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
const value =
|
const value =
|
||||||
this.value ??
|
this.value ??
|
||||||
(this.required && !this.disabled
|
(this.required && !this.disabled ? this._getItems()[0].id : this.value);
|
||||||
? languageOptions[0]?.value
|
|
||||||
: this.value);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-generic-picker
|
||||||
.label=${this.label ??
|
.hass=${this.hass}
|
||||||
|
.autofocus=${this.autofocus}
|
||||||
|
popover-placement="bottom-end"
|
||||||
|
.notFoundLabel=${this._notFoundLabel}
|
||||||
|
.emptyLabel=${this.hass?.localize(
|
||||||
|
"ui.components.language-picker.no_languages"
|
||||||
|
) || "No languages available"}
|
||||||
|
.placeholder=${this.label ??
|
||||||
(this.hass?.localize("ui.components.language-picker.language") ||
|
(this.hass?.localize("ui.components.language-picker.language") ||
|
||||||
"Language")}
|
"Language")}
|
||||||
.value=${value || ""}
|
.value=${value}
|
||||||
.required=${this.required}
|
.valueRenderer=${this._valueRenderer}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@selected=${this._changed}
|
.getItems=${this._getItems}
|
||||||
@closed=${stopPropagation}
|
@value-changed=${this._changed}
|
||||||
fixedMenuPosition
|
hide-clear-icon
|
||||||
naturalMenuWidth
|
|
||||||
.inlineArrow=${this.inlineArrow}
|
|
||||||
>
|
>
|
||||||
${languageOptions.length === 0
|
${this.buttonStyle
|
||||||
? html`<ha-list-item value=""
|
? html`<ha-button
|
||||||
>${this.hass?.localize(
|
slot="field"
|
||||||
"ui.components.language-picker.no_languages"
|
.disabled=${this.disabled}
|
||||||
) || "No languages"}</ha-list-item
|
@click=${this._openPicker}
|
||||||
>`
|
appearance="plain"
|
||||||
: languageOptions.map(
|
variant="neutral"
|
||||||
(option) => html`
|
>
|
||||||
<ha-list-item .value=${option.value}
|
${this._getLanguageName(value)}
|
||||||
>${option.label}</ha-list-item
|
<ha-svg-icon slot="end" .path=${mdiMenuDown}></ha-svg-icon>
|
||||||
>
|
</ha-button>`
|
||||||
`
|
: nothing}
|
||||||
)}
|
</ha-generic-picker>
|
||||||
</ha-select>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _openPicker(ev: Event) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.genericPicker.open();
|
||||||
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
ha-select {
|
ha-generic-picker {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
min-width: 200px;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
private _changed(ev): void {
|
private _changed(ev: ValueChangedEvent<string>): void {
|
||||||
const target = ev.target as HaSelect;
|
ev.stopPropagation();
|
||||||
if (this.disabled || target.value === "" || target.value === this.value) {
|
this.value = ev.detail.value;
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.value = target.value;
|
|
||||||
fireEvent(this, "value-changed", { value: this.value });
|
fireEvent(this, "value-changed", { value: this.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _notFoundLabel = (search: string) => {
|
||||||
|
const term = html`<b>‘${search}’</b>`;
|
||||||
|
return this.hass
|
||||||
|
? this.hass.localize("ui.components.language-picker.no_match", {
|
||||||
|
term,
|
||||||
|
})
|
||||||
|
: html`No languages found for ${term}`;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import { ReactiveElement } from "lit";
|
import { ReactiveElement, render, html } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
// eslint-disable-next-line import/extensions
|
||||||
|
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
||||||
import hash from "object-hash";
|
import hash from "object-hash";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { renderMarkdown } from "../resources/render-markdown";
|
import { renderMarkdown } from "../resources/render-markdown";
|
||||||
import { CacheManager } from "../util/cache-manager";
|
import { CacheManager } from "../util/cache-manager";
|
||||||
|
|
||||||
|
const h = (template: ReturnType<typeof unsafeHTML>) => html`${template}`;
|
||||||
|
|
||||||
const markdownCache = new CacheManager<string>(1000);
|
const markdownCache = new CacheManager<string>(1000);
|
||||||
|
|
||||||
const _gitHubMarkdownAlerts = {
|
const _gitHubMarkdownAlerts = {
|
||||||
@@ -48,18 +52,26 @@ class HaMarkdownElement extends ReactiveElement {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _renderPromise: ReturnType<typeof this._render> = Promise.resolve();
|
||||||
|
|
||||||
protected update(changedProps) {
|
protected update(changedProps) {
|
||||||
super.update(changedProps);
|
super.update(changedProps);
|
||||||
if (this.content !== undefined) {
|
if (this.content !== undefined) {
|
||||||
this._render();
|
this._renderPromise = this._render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async getUpdateComplete(): Promise<boolean> {
|
||||||
|
await super.getUpdateComplete();
|
||||||
|
await this._renderPromise;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected willUpdate(_changedProperties: PropertyValues): void {
|
protected willUpdate(_changedProperties: PropertyValues): void {
|
||||||
if (!this.innerHTML && this.cache) {
|
if (!this.innerHTML && this.cache) {
|
||||||
const key = this._computeCacheKey();
|
const key = this._computeCacheKey();
|
||||||
if (markdownCache.has(key)) {
|
if (markdownCache.has(key)) {
|
||||||
this.innerHTML = markdownCache.get(key)!;
|
render(markdownCache.get(key)!, this.renderRoot);
|
||||||
this._resize();
|
this._resize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +87,7 @@ class HaMarkdownElement extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _render() {
|
private async _render() {
|
||||||
this.innerHTML = await renderMarkdown(
|
const elements = await renderMarkdown(
|
||||||
String(this.content),
|
String(this.content),
|
||||||
{
|
{
|
||||||
breaks: this.breaks,
|
breaks: this.breaks,
|
||||||
@@ -87,6 +99,11 @@ class HaMarkdownElement extends ReactiveElement {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
render(
|
||||||
|
elements.map((e) => h(unsafeHTML(e))),
|
||||||
|
this.renderRoot
|
||||||
|
);
|
||||||
|
|
||||||
this._resize();
|
this._resize();
|
||||||
|
|
||||||
const walker = document.createTreeWalker(
|
const walker = document.createTreeWalker(
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
|
import {
|
||||||
import { customElement, property } from "lit/decorators";
|
css,
|
||||||
|
html,
|
||||||
|
LitElement,
|
||||||
|
nothing,
|
||||||
|
type ReactiveElement,
|
||||||
|
type CSSResultGroup,
|
||||||
|
} from "lit";
|
||||||
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "./ha-markdown-element";
|
import "./ha-markdown-element";
|
||||||
|
|
||||||
@customElement("ha-markdown")
|
@customElement("ha-markdown")
|
||||||
@@ -18,6 +25,14 @@ export class HaMarkdown extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public cache = false;
|
@property({ type: Boolean }) public cache = false;
|
||||||
|
|
||||||
|
@query("ha-markdown-element") private _markdownElement!: ReactiveElement;
|
||||||
|
|
||||||
|
protected async getUpdateComplete() {
|
||||||
|
const result = await super.getUpdateComplete();
|
||||||
|
await this._markdownElement.updateComplete;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.content) {
|
if (!this.content) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@@ -50,22 +65,49 @@ export class HaMarkdown extends LitElement {
|
|||||||
}
|
}
|
||||||
ha-alert {
|
ha-alert {
|
||||||
display: block;
|
display: block;
|
||||||
margin: 4px 0;
|
margin: var(--ha-space-1) 0;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
color: var(--primary-color);
|
color: var(--markdown-link-color, var(--primary-color));
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
|
background-color: rgba(10, 10, 10, 0.15);
|
||||||
|
border-radius: var(--markdown-image-border-radius);
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
min-height: 2lh;
|
||||||
|
height: auto;
|
||||||
|
width: auto;
|
||||||
|
text-indent: 4px;
|
||||||
|
transition: height 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
p:first-child > img:first-child {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
p:first-child > img:last-child {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
ol,
|
||||||
|
ul {
|
||||||
|
list-style-position: inside;
|
||||||
|
padding-inline-start: 0;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
&:has(input[type="checkbox"]) {
|
||||||
|
list-style: none;
|
||||||
|
& > input[type="checkbox"] {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
background-color: var(--markdown-svg-background-color, none);
|
||||||
|
color: var(--markdown-svg-color, none);
|
||||||
}
|
}
|
||||||
code,
|
code,
|
||||||
pre {
|
pre {
|
||||||
background-color: var(--markdown-code-background-color, none);
|
background-color: var(--markdown-code-background-color, none);
|
||||||
border-radius: var(--ha-border-radius-sm);
|
border-radius: var(--ha-border-radius-sm);
|
||||||
}
|
color: var(--markdown-code-text-color, inherit);
|
||||||
svg {
|
|
||||||
background-color: var(--markdown-svg-background-color, none);
|
|
||||||
color: var(--markdown-svg-color, none);
|
|
||||||
}
|
}
|
||||||
code {
|
code {
|
||||||
font-size: var(--ha-font-size-s);
|
font-size: var(--ha-font-size-s);
|
||||||
@@ -75,7 +117,7 @@ export class HaMarkdown extends LitElement {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
pre {
|
pre {
|
||||||
padding: 16px;
|
padding: var(--ha-space-4);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
line-height: var(--ha-line-height-condensed);
|
line-height: var(--ha-line-height-condensed);
|
||||||
font-family: var(--ha-font-family-code);
|
font-family: var(--ha-font-family-code);
|
||||||
@@ -95,7 +137,25 @@ export class HaMarkdown extends LitElement {
|
|||||||
hr {
|
hr {
|
||||||
border-color: var(--divider-color);
|
border-color: var(--divider-color);
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: 16px 0;
|
margin: var(--ha-space-4) 0;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
text-align: start;
|
||||||
|
}
|
||||||
|
td,
|
||||||
|
th {
|
||||||
|
border: 1px solid var(--markdown-table-border-color, transparent);
|
||||||
|
padding: 0.25em 0.5em;
|
||||||
|
}
|
||||||
|
blockquote {
|
||||||
|
border-left: 4px solid var(--divider-color);
|
||||||
|
margin-inline: 0;
|
||||||
|
padding-inline: 1em;
|
||||||
}
|
}
|
||||||
` as CSSResultGroup;
|
` as CSSResultGroup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,10 +175,10 @@ export class HaMdDialog extends Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
padding-top: var(--safe-area-inset-top);
|
margin-top: var(--safe-area-inset-top, var(--ha-space-0));
|
||||||
padding-bottom: var(--safe-area-inset-bottom);
|
margin-bottom: var(--safe-area-inset-bottom, var(--ha-space-0));
|
||||||
padding-left: var(--safe-area-inset-left);
|
margin-left: var(--safe-area-inset-left, var(--ha-space-0));
|
||||||
padding-right: var(--safe-area-inset-right);
|
margin-right: var(--safe-area-inset-right, var(--ha-space-0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ export class HaMdDialog extends Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slot[name="actions"]::slotted(*) {
|
slot[name="actions"]::slotted(*) {
|
||||||
padding: 16px;
|
padding: var(--ha-space-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.scroller {
|
.scroller {
|
||||||
@@ -195,7 +195,7 @@ export class HaMdDialog extends Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slot[name="content"]::slotted(*) {
|
slot[name="content"]::slotted(*) {
|
||||||
padding: var(--dialog-content-padding, 24px);
|
padding: var(--dialog-content-padding, var(--ha-space-6));
|
||||||
}
|
}
|
||||||
.scrim {
|
.scrim {
|
||||||
z-index: 10; /* overlay navigation */
|
z-index: 10; /* overlay navigation */
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ListItemEl } from "@material/web/list/internal/listitem/list-item";
|
import { ListItemEl } from "@material/web/list/internal/listitem/list-item";
|
||||||
import { styles } from "@material/web/list/internal/listitem/list-item-styles";
|
import { styles } from "@material/web/list/internal/listitem/list-item-styles";
|
||||||
import { css } from "lit";
|
import { css, html, nothing, type TemplateResult } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
import "./ha-ripple";
|
||||||
|
|
||||||
export const haMdListStyles = [
|
export const haMdListStyles = [
|
||||||
styles,
|
styles,
|
||||||
@@ -25,6 +26,18 @@ export const haMdListStyles = [
|
|||||||
@customElement("ha-md-list-item")
|
@customElement("ha-md-list-item")
|
||||||
export class HaMdListItem extends ListItemEl {
|
export class HaMdListItem extends ListItemEl {
|
||||||
static override styles = haMdListStyles;
|
static override styles = haMdListStyles;
|
||||||
|
|
||||||
|
protected renderRipple(): TemplateResult | typeof nothing {
|
||||||
|
if (this.type === "text") {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`<ha-ripple
|
||||||
|
part="ripple"
|
||||||
|
for="item"
|
||||||
|
?disabled=${this.disabled && this.type !== "link"}
|
||||||
|
></ha-ripple>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { fireEvent } from "../common/dom/fire_event";
|
|||||||
import { titleCase } from "../common/string/title-case";
|
import { titleCase } from "../common/string/title-case";
|
||||||
import { fetchConfig } from "../data/lovelace/config/types";
|
import { fetchConfig } from "../data/lovelace/config/types";
|
||||||
import type { LovelaceViewRawConfig } from "../data/lovelace/config/view";
|
import type { LovelaceViewRawConfig } from "../data/lovelace/config/view";
|
||||||
|
import { getDefaultPanelUrlPath } from "../data/panel";
|
||||||
import type { HomeAssistant, PanelInfo, ValueChangedEvent } from "../types";
|
import type { HomeAssistant, PanelInfo, ValueChangedEvent } from "../types";
|
||||||
import "./ha-combo-box";
|
import "./ha-combo-box";
|
||||||
import type { HaComboBox } from "./ha-combo-box";
|
import type { HaComboBox } from "./ha-combo-box";
|
||||||
@@ -44,7 +45,7 @@ const createPanelNavigationItem = (hass: HomeAssistant, panel: PanelInfo) => ({
|
|||||||
path: `/${panel.url_path}`,
|
path: `/${panel.url_path}`,
|
||||||
icon: panel.icon ?? "mdi:view-dashboard",
|
icon: panel.icon ?? "mdi:view-dashboard",
|
||||||
title:
|
title:
|
||||||
panel.url_path === hass.defaultPanel
|
panel.url_path === getDefaultPanelUrlPath(hass)
|
||||||
? hass.localize("panel.states")
|
? hass.localize("panel.states")
|
||||||
: hass.localize(`panel.${panel.title}`) ||
|
: hass.localize(`panel.${panel.title}`) ||
|
||||||
panel.title ||
|
panel.title ||
|
||||||
|
|||||||
@@ -1,39 +1,42 @@
|
|||||||
import { mdiMagnify } from "@mdi/js";
|
import type { LitVirtualizer } from "@lit-labs/virtualizer";
|
||||||
import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
|
||||||
|
import { mdiMagnify, mdiMinusBoxOutline } from "@mdi/js";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import type { PropertyValues, TemplateResult } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import {
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
customElement,
|
||||||
|
eventOptions,
|
||||||
|
property,
|
||||||
|
query,
|
||||||
|
state,
|
||||||
|
} from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
|
import { tinykeys } from "tinykeys";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
|
||||||
import { HaFuse } from "../resources/fuse";
|
import { HaFuse } from "../resources/fuse";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import "./ha-combo-box";
|
import { loadVirtualizer } from "../resources/virtualizer";
|
||||||
import type { HaComboBox } from "./ha-combo-box";
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./chips/ha-chip-set";
|
||||||
|
import "./chips/ha-filter-chip";
|
||||||
import "./ha-combo-box-item";
|
import "./ha-combo-box-item";
|
||||||
import "./ha-icon";
|
import "./ha-icon";
|
||||||
|
import "./ha-textfield";
|
||||||
|
import type { HaTextField } from "./ha-textfield";
|
||||||
|
|
||||||
export interface PickerComboBoxItem {
|
export interface PickerComboBoxItem {
|
||||||
id: string;
|
id: string;
|
||||||
primary: string;
|
primary: string;
|
||||||
a11y_label?: string;
|
|
||||||
secondary?: string;
|
secondary?: string;
|
||||||
search_labels?: string[];
|
search_labels?: string[];
|
||||||
sorting_label?: string;
|
sorting_label?: string;
|
||||||
icon_path?: string;
|
icon_path?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
}
|
}
|
||||||
|
const NO_ITEMS_AVAILABLE_ID = "___no_items_available___";
|
||||||
|
|
||||||
// Hack to force empty label to always display empty value by default in the search field
|
const DEFAULT_ROW_RENDERER: RenderItemFunction<PickerComboBoxItem> = (
|
||||||
export interface PickerComboBoxItemWithLabel extends PickerComboBoxItem {
|
|
||||||
a11y_label: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NO_MATCHING_ITEMS_FOUND_ID = "___no_matching_items_found___";
|
|
||||||
|
|
||||||
const DEFAULT_ROW_RENDERER: ComboBoxLitRenderer<PickerComboBoxItem> = (
|
|
||||||
item
|
item
|
||||||
) => html`
|
) => html`
|
||||||
<ha-combo-box-item type="button" compact>
|
<ha-combo-box-item type="button" compact>
|
||||||
@@ -57,7 +60,7 @@ export type PickerComboBoxSearchFn<T extends PickerComboBoxItem> = (
|
|||||||
|
|
||||||
@customElement("ha-picker-combo-box")
|
@customElement("ha-picker-combo-box")
|
||||||
export class HaPickerComboBox extends LitElement {
|
export class HaPickerComboBox extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
// eslint-disable-next-line lit/no-native-attributes
|
// eslint-disable-next-line lit/no-native-attributes
|
||||||
@property({ type: Boolean }) public autofocus = false;
|
@property({ type: Boolean }) public autofocus = false;
|
||||||
@@ -73,204 +76,664 @@ export class HaPickerComboBox extends LitElement {
|
|||||||
|
|
||||||
@property() public value?: string;
|
@property() public value?: string;
|
||||||
|
|
||||||
@property() public helper?: string;
|
@state() private _listScrolled = false;
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false })
|
||||||
public getItems?: () => PickerComboBoxItem[];
|
public getItems?: (
|
||||||
|
searchString?: string,
|
||||||
|
section?: string
|
||||||
|
) => (PickerComboBoxItem | string)[];
|
||||||
|
|
||||||
@property({ attribute: false, type: Array })
|
@property({ attribute: false, type: Array })
|
||||||
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
public getAdditionalItems?: (searchString?: string) => PickerComboBoxItem[];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public rowRenderer?: ComboBoxLitRenderer<PickerComboBoxItem>;
|
public rowRenderer?: RenderItemFunction<PickerComboBoxItem>;
|
||||||
|
|
||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: false })
|
||||||
public hideClearIcon = false;
|
public notFoundLabel?: string | ((search: string) => string);
|
||||||
|
|
||||||
@property({ attribute: "not-found-label", type: String })
|
@property({ attribute: "empty-label" })
|
||||||
public notFoundLabel?: string;
|
public emptyLabel?: string;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||||
|
|
||||||
@state() private _opened = false;
|
@property({ reflect: true }) public mode: "popover" | "dialog" = "popover";
|
||||||
|
|
||||||
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
/** Section filter buttons for the list, section headers needs to be defined in getItems as strings */
|
||||||
|
@property({ attribute: false }) public sections?: (
|
||||||
|
| {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
| "separator"
|
||||||
|
)[];
|
||||||
|
|
||||||
public async open() {
|
@property({ attribute: false }) public sectionTitleFunction?: (listInfo: {
|
||||||
await this.updateComplete;
|
firstIndex: number;
|
||||||
await this.comboBox?.open();
|
lastIndex: number;
|
||||||
}
|
firstItem: PickerComboBoxItem | string;
|
||||||
|
secondItem: PickerComboBoxItem | string;
|
||||||
|
itemsCount: number;
|
||||||
|
}) => string | undefined;
|
||||||
|
|
||||||
public async focus() {
|
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||||
await this.updateComplete;
|
|
||||||
await this.comboBox?.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _initialItems = false;
|
@query("lit-virtualizer") private _virtualizerElement?: LitVirtualizer;
|
||||||
|
|
||||||
private _items: PickerComboBoxItemWithLabel[] = [];
|
@query("ha-textfield") private _searchFieldElement?: HaTextField;
|
||||||
|
|
||||||
private _defaultNotFoundItem = memoizeOne(
|
@state() private _items: (PickerComboBoxItem | string)[] = [];
|
||||||
(
|
|
||||||
label: this["notFoundLabel"],
|
|
||||||
localize: LocalizeFunc
|
|
||||||
): PickerComboBoxItemWithLabel => ({
|
|
||||||
id: NO_MATCHING_ITEMS_FOUND_ID,
|
|
||||||
primary: label || localize("ui.components.combo-box.no_match"),
|
|
||||||
icon_path: mdiMagnify,
|
|
||||||
a11y_label: label || localize("ui.components.combo-box.no_match"),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
private _getAdditionalItems = (searchString?: string) => {
|
@state() private _sectionTitle?: string;
|
||||||
const items = this.getAdditionalItems?.(searchString) || [];
|
|
||||||
|
|
||||||
return items.map<PickerComboBoxItemWithLabel>((item) => ({
|
private _allItems: (PickerComboBoxItem | string)[] = [];
|
||||||
...item,
|
|
||||||
a11y_label: item.a11y_label || item.primary,
|
private _selectedItemIndex = -1;
|
||||||
}));
|
|
||||||
|
static shadowRootOptions = {
|
||||||
|
...LitElement.shadowRootOptions,
|
||||||
|
delegatesFocus: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
private _getItems = (): PickerComboBoxItemWithLabel[] => {
|
private _removeKeyboardShortcuts?: () => void;
|
||||||
const items = this.getItems ? this.getItems() : [];
|
|
||||||
|
|
||||||
const sortedItems = items
|
private _search = "";
|
||||||
.map<PickerComboBoxItemWithLabel>((item) => ({
|
|
||||||
...item,
|
protected firstUpdated() {
|
||||||
a11y_label: item.a11y_label || item.primary,
|
this._registerKeyboardShortcuts();
|
||||||
}))
|
}
|
||||||
.sort((entityA, entityB) =>
|
|
||||||
|
public willUpdate() {
|
||||||
|
if (!this.hasUpdated) {
|
||||||
|
loadVirtualizer();
|
||||||
|
this._allItems = this._getItems();
|
||||||
|
this._items = this._allItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this._removeKeyboardShortcuts?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
return html`<ha-textfield
|
||||||
|
.label=${this.label ??
|
||||||
|
this.hass?.localize("ui.common.search") ??
|
||||||
|
"Search"}
|
||||||
|
@input=${this._filterChanged}
|
||||||
|
></ha-textfield>
|
||||||
|
${this._renderSectionButtons()}
|
||||||
|
${this.sections?.length
|
||||||
|
? html`
|
||||||
|
<div class="section-title-wrapper">
|
||||||
|
<div
|
||||||
|
class="section-title ${!this.selectedSection &&
|
||||||
|
this._sectionTitle
|
||||||
|
? "show"
|
||||||
|
: ""}"
|
||||||
|
>
|
||||||
|
${this._sectionTitle}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
|
<lit-virtualizer
|
||||||
|
.keyFunction=${this._keyFunction}
|
||||||
|
tabindex="0"
|
||||||
|
scroller
|
||||||
|
.items=${this._items}
|
||||||
|
.renderItem=${this._renderItem}
|
||||||
|
style="min-height: 36px;"
|
||||||
|
class=${this._listScrolled ? "scrolled" : ""}
|
||||||
|
@scroll=${this._onScrollList}
|
||||||
|
@focus=${this._focusList}
|
||||||
|
@visibilityChanged=${this._visibilityChanged}
|
||||||
|
>
|
||||||
|
</lit-virtualizer> `;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _renderSectionButtons() {
|
||||||
|
if (!this.sections || this.sections.length === 0) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-chip-set class="sections">
|
||||||
|
${this.sections.map((section) =>
|
||||||
|
section === "separator"
|
||||||
|
? html`<div class="separator"></div>`
|
||||||
|
: html`<ha-filter-chip
|
||||||
|
@click=${this._toggleSection}
|
||||||
|
.section-id=${section.id}
|
||||||
|
.selected=${this.selectedSection === section.id}
|
||||||
|
.label=${section.label}
|
||||||
|
>
|
||||||
|
</ha-filter-chip>`
|
||||||
|
)}
|
||||||
|
</ha-chip-set>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
@eventOptions({ passive: true })
|
||||||
|
private _visibilityChanged(ev) {
|
||||||
|
if (
|
||||||
|
this._virtualizerElement &&
|
||||||
|
this.sectionTitleFunction &&
|
||||||
|
this.sections?.length
|
||||||
|
) {
|
||||||
|
const firstItem = this._virtualizerElement.items[ev.first];
|
||||||
|
const secondItem = this._virtualizerElement.items[ev.first + 1];
|
||||||
|
this._sectionTitle = this.sectionTitleFunction({
|
||||||
|
firstIndex: ev.first,
|
||||||
|
lastIndex: ev.last,
|
||||||
|
firstItem: firstItem as PickerComboBoxItem | string,
|
||||||
|
secondItem: secondItem as PickerComboBoxItem | string,
|
||||||
|
itemsCount: this._virtualizerElement.items.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getAdditionalItems = (searchString?: string) =>
|
||||||
|
this.getAdditionalItems?.(searchString) || [];
|
||||||
|
|
||||||
|
private _getItems = () => {
|
||||||
|
let items = [
|
||||||
|
...(this.getItems
|
||||||
|
? this.getItems(this._search, this.selectedSection)
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!this.sections?.length) {
|
||||||
|
items = items.sort((entityA, entityB) =>
|
||||||
caseInsensitiveStringCompare(
|
caseInsensitiveStringCompare(
|
||||||
entityA.sorting_label!,
|
(entityA as PickerComboBoxItem).sorting_label!,
|
||||||
entityB.sorting_label!,
|
(entityB as PickerComboBoxItem).sorting_label!,
|
||||||
this.hass.locale.language
|
this.hass?.locale.language ?? navigator.language
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!sortedItems.length) {
|
if (!items.length) {
|
||||||
sortedItems.push(
|
items.push(NO_ITEMS_AVAILABLE_ID);
|
||||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass.localize)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const additionalItems = this._getAdditionalItems();
|
const additionalItems = this._getAdditionalItems();
|
||||||
sortedItems.push(...additionalItems);
|
items.push(...additionalItems);
|
||||||
return sortedItems;
|
|
||||||
|
if (this.mode === "dialog") {
|
||||||
|
items.push("padding"); // padding for safe area inset
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected shouldUpdate(changedProps: PropertyValues) {
|
private _renderItem = (item: PickerComboBoxItem | string, index: number) => {
|
||||||
if (
|
if (item === "padding") {
|
||||||
changedProps.has("value") ||
|
return html`<div class="bottom-padding"></div>`;
|
||||||
changedProps.has("label") ||
|
|
||||||
changedProps.has("disabled")
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return !(!changedProps.has("_opened") && this._opened);
|
if (item === NO_ITEMS_AVAILABLE_ID) {
|
||||||
}
|
return html`
|
||||||
|
<div class="combo-box-row">
|
||||||
public willUpdate(changedProps: PropertyValues) {
|
<ha-combo-box-item type="text" compact>
|
||||||
if (changedProps.has("_opened") && this._opened) {
|
<ha-svg-icon
|
||||||
this._items = this._getItems();
|
slot="start"
|
||||||
if (this._initialItems) {
|
.path=${this._search ? mdiMagnify : mdiMinusBoxOutline}
|
||||||
this.comboBox.filteredItems = this._items;
|
></ha-svg-icon>
|
||||||
}
|
<span slot="headline"
|
||||||
this._initialItems = true;
|
>${this._search
|
||||||
|
? typeof this.notFoundLabel === "function"
|
||||||
|
? this.notFoundLabel(this._search)
|
||||||
|
: this.notFoundLabel ||
|
||||||
|
this.hass?.localize("ui.components.combo-box.no_match") ||
|
||||||
|
"No matching items found"
|
||||||
|
: this.emptyLabel ||
|
||||||
|
this.hass?.localize("ui.components.combo-box.no_items") ||
|
||||||
|
"No items available"}</span
|
||||||
|
>
|
||||||
|
</ha-combo-box-item>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
if (typeof item === "string") {
|
||||||
|
return html`<div class="title">${item}</div>`;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
const renderer = this.rowRenderer || DEFAULT_ROW_RENDERER;
|
||||||
return html`
|
return html`<div
|
||||||
<ha-combo-box
|
id=${`list-item-${index}`}
|
||||||
item-id-path="id"
|
class="combo-box-row ${this._value === item.id ? "current-value" : ""}"
|
||||||
item-value-path="id"
|
.value=${item.id}
|
||||||
item-label-path="a11y_label"
|
.index=${index}
|
||||||
clear-initial-value
|
@click=${this._valueSelected}
|
||||||
.hass=${this.hass}
|
>
|
||||||
.value=${this._value}
|
${renderer(item, index)}
|
||||||
.label=${this.label}
|
</div>`;
|
||||||
.helper=${this.helper}
|
};
|
||||||
.allowCustomValue=${this.allowCustomValue}
|
|
||||||
.filteredItems=${this._items}
|
@eventOptions({ passive: true })
|
||||||
.renderer=${this.rowRenderer || DEFAULT_ROW_RENDERER}
|
private _onScrollList(ev) {
|
||||||
.required=${this.required}
|
const top = ev.target.scrollTop ?? 0;
|
||||||
.disabled=${this.disabled}
|
this._listScrolled = top > 0;
|
||||||
.hideClearIcon=${this.hideClearIcon}
|
|
||||||
@opened-changed=${this._openedChanged}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
@filter-changed=${this._filterChanged}
|
|
||||||
>
|
|
||||||
</ha-combo-box>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _value() {
|
private get _value() {
|
||||||
return this.value || "";
|
return this.value || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private _openedChanged(ev: ValueChangedEvent<boolean>) {
|
private _valueSelected = (ev: Event) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
if (ev.detail.value !== this._opened) {
|
const value = (ev.currentTarget as any).value as string;
|
||||||
this._opened = ev.detail.value;
|
const newValue = value?.trim();
|
||||||
fireEvent(this, "opened-changed", { value: this._opened });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueChanged(ev: ValueChangedEvent<string | undefined>) {
|
fireEvent(this, "value-changed", { value: newValue });
|
||||||
ev.stopPropagation();
|
};
|
||||||
// Clear the input field to prevent showing the old value next time
|
|
||||||
this.comboBox.setTextFieldValue("");
|
|
||||||
const newValue = ev.detail.value?.trim();
|
|
||||||
|
|
||||||
if (newValue === NO_MATCHING_ITEMS_FOUND_ID) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newValue !== this._value) {
|
|
||||||
this._setValue(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _fuseIndex = memoizeOne((states: PickerComboBoxItem[]) =>
|
private _fuseIndex = memoizeOne((states: PickerComboBoxItem[]) =>
|
||||||
Fuse.createIndex(["search_labels"], states)
|
Fuse.createIndex(["search_labels"], states)
|
||||||
);
|
);
|
||||||
|
|
||||||
private _filterChanged(ev: CustomEvent): void {
|
private _filterChanged = (ev: Event) => {
|
||||||
if (!this._opened) return;
|
const textfield = ev.target as HaTextField;
|
||||||
|
const searchString = textfield.value.trim();
|
||||||
|
this._search = searchString;
|
||||||
|
|
||||||
const target = ev.target as HaComboBox;
|
if (this.sections?.length) {
|
||||||
const searchString = ev.detail.value.trim() as string;
|
this._items = this._getItems();
|
||||||
|
} else {
|
||||||
|
if (!searchString) {
|
||||||
|
this._items = this._allItems;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const index = this._fuseIndex(this._items);
|
const index = this._fuseIndex(this._allItems as PickerComboBoxItem[]);
|
||||||
const fuse = new HaFuse(this._items, { shouldSort: false }, index);
|
const fuse = new HaFuse(
|
||||||
|
this._allItems as PickerComboBoxItem[],
|
||||||
|
{
|
||||||
|
shouldSort: false,
|
||||||
|
minMatchCharLength: Math.min(searchString.length, 2),
|
||||||
|
},
|
||||||
|
index
|
||||||
|
);
|
||||||
|
|
||||||
const results = fuse.multiTermsSearch(searchString);
|
const results = fuse.multiTermsSearch(searchString);
|
||||||
let filteredItems = this._items as PickerComboBoxItem[];
|
let filteredItems = [...this._allItems];
|
||||||
if (results) {
|
|
||||||
const items = results.map((result) => result.item);
|
if (results) {
|
||||||
if (items.length === 0) {
|
const items: (PickerComboBoxItem | string)[] = results.map(
|
||||||
items.push(
|
(result) => result.item
|
||||||
this._defaultNotFoundItem(this.notFoundLabel, this.hass.localize)
|
);
|
||||||
|
|
||||||
|
if (!items.length) {
|
||||||
|
filteredItems.push(NO_ITEMS_AVAILABLE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
const additionalItems = this._getAdditionalItems();
|
||||||
|
items.push(...additionalItems);
|
||||||
|
|
||||||
|
filteredItems = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.searchFn) {
|
||||||
|
filteredItems = this.searchFn(
|
||||||
|
searchString,
|
||||||
|
filteredItems as PickerComboBoxItem[],
|
||||||
|
this._allItems as PickerComboBoxItem[]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const additionalItems = this._getAdditionalItems(searchString);
|
|
||||||
items.push(...additionalItems);
|
this._items = filteredItems as PickerComboBoxItem[];
|
||||||
filteredItems = items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.searchFn) {
|
this._selectedItemIndex = -1;
|
||||||
filteredItems = this.searchFn(searchString, filteredItems, this._items);
|
if (this._virtualizerElement) {
|
||||||
|
this._virtualizerElement.scrollTo(0, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _toggleSection(ev: Event) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this._resetSelectedItem();
|
||||||
|
this._sectionTitle = undefined;
|
||||||
|
const section = (ev.target as HTMLElement)["section-id"] as string;
|
||||||
|
if (!section) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.selectedSection === section) {
|
||||||
|
this.selectedSection = undefined;
|
||||||
|
} else {
|
||||||
|
this.selectedSection = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.filteredItems = filteredItems;
|
this._items = this._getItems();
|
||||||
|
|
||||||
|
// Reset scroll position when filter changes
|
||||||
|
if (this._virtualizerElement) {
|
||||||
|
this._virtualizerElement.scrollToIndex(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue(value: string | undefined) {
|
private _registerKeyboardShortcuts() {
|
||||||
setTimeout(() => {
|
this._removeKeyboardShortcuts = tinykeys(this, {
|
||||||
fireEvent(this, "value-changed", { value });
|
ArrowUp: this._selectPreviousItem,
|
||||||
}, 0);
|
ArrowDown: this._selectNextItem,
|
||||||
|
Home: this._selectFirstItem,
|
||||||
|
End: this._selectLastItem,
|
||||||
|
Enter: this._pickSelectedItem,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _focusList() {
|
||||||
|
if (this._selectedItemIndex === -1) {
|
||||||
|
this._selectNextItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _selectNextItem = (ev?: KeyboardEvent) => {
|
||||||
|
ev?.stopPropagation();
|
||||||
|
ev?.preventDefault();
|
||||||
|
if (!this._virtualizerElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._searchFieldElement?.focus();
|
||||||
|
|
||||||
|
const items = this._virtualizerElement.items as PickerComboBoxItem[];
|
||||||
|
|
||||||
|
const maxItems = items.length - 1;
|
||||||
|
|
||||||
|
if (maxItems === -1) {
|
||||||
|
this._resetSelectedItem();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIndex =
|
||||||
|
maxItems === this._selectedItemIndex
|
||||||
|
? this._selectedItemIndex
|
||||||
|
: this._selectedItemIndex + 1;
|
||||||
|
|
||||||
|
if (!items[nextIndex]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof items[nextIndex] === "string") {
|
||||||
|
// Skip titles, padding and empty search
|
||||||
|
if (nextIndex === maxItems) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._selectedItemIndex = nextIndex + 1;
|
||||||
|
} else {
|
||||||
|
this._selectedItemIndex = nextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._scrollToSelectedItem();
|
||||||
|
};
|
||||||
|
|
||||||
|
private _selectPreviousItem = (ev: KeyboardEvent) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
ev.preventDefault();
|
||||||
|
if (!this._virtualizerElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._selectedItemIndex > 0) {
|
||||||
|
const nextIndex = this._selectedItemIndex - 1;
|
||||||
|
|
||||||
|
const items = this._virtualizerElement.items as PickerComboBoxItem[];
|
||||||
|
|
||||||
|
if (!items[nextIndex]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof items[nextIndex] === "string") {
|
||||||
|
// Skip titles, padding and empty search
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._selectedItemIndex = nextIndex - 1;
|
||||||
|
} else {
|
||||||
|
this._selectedItemIndex = nextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._scrollToSelectedItem();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _selectFirstItem = (ev: KeyboardEvent) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
if (!this._virtualizerElement || !this._virtualizerElement.items.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIndex = 0;
|
||||||
|
|
||||||
|
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||||
|
this._selectedItemIndex = nextIndex + 1;
|
||||||
|
} else {
|
||||||
|
this._selectedItemIndex = nextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._scrollToSelectedItem();
|
||||||
|
};
|
||||||
|
|
||||||
|
private _selectLastItem = (ev: KeyboardEvent) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
if (!this._virtualizerElement || !this._virtualizerElement.items.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIndex = this._virtualizerElement.items.length - 1;
|
||||||
|
|
||||||
|
if (typeof this._virtualizerElement.items[nextIndex] === "string") {
|
||||||
|
this._selectedItemIndex = nextIndex - 1;
|
||||||
|
} else {
|
||||||
|
this._selectedItemIndex = nextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._scrollToSelectedItem();
|
||||||
|
};
|
||||||
|
|
||||||
|
private _scrollToSelectedItem = () => {
|
||||||
|
this._virtualizerElement
|
||||||
|
?.querySelector(".selected")
|
||||||
|
?.classList.remove("selected");
|
||||||
|
|
||||||
|
this._virtualizerElement?.scrollToIndex(this._selectedItemIndex, "end");
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
this._virtualizerElement
|
||||||
|
?.querySelector(`#list-item-${this._selectedItemIndex}`)
|
||||||
|
?.classList.add("selected");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _pickSelectedItem = (ev: KeyboardEvent) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const firstItem = this._virtualizerElement?.items[0] as PickerComboBoxItem;
|
||||||
|
|
||||||
|
if (this._virtualizerElement?.items.length === 1) {
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: firstItem.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._selectedItemIndex === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if filter button is focused
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
|
const item = this._virtualizerElement?.items[
|
||||||
|
this._selectedItemIndex
|
||||||
|
] as PickerComboBoxItem;
|
||||||
|
if (item) {
|
||||||
|
fireEvent(this, "value-changed", { value: item.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private _resetSelectedItem() {
|
||||||
|
this._virtualizerElement
|
||||||
|
?.querySelector(".selected")
|
||||||
|
?.classList.remove("selected");
|
||||||
|
this._selectedItemIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _keyFunction = (item: PickerComboBoxItem | string) =>
|
||||||
|
typeof item === "string" ? item : item.id;
|
||||||
|
|
||||||
|
static styles = [
|
||||||
|
haStyleScrollbar,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding-top: var(--ha-space-3);
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-textfield {
|
||||||
|
padding: 0 var(--ha-space-3);
|
||||||
|
margin-bottom: var(--ha-space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) ha-textfield {
|
||||||
|
padding: 0 var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-combo-box-item {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-combo-box-item.selected {
|
||||||
|
background-color: var(--ha-color-fill-neutral-quiet-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
ha-combo-box-item.selected {
|
||||||
|
background-color: var(--ha-color-fill-neutral-normal-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lit-virtualizer {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lit-virtualizer:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
lit-virtualizer.scrolled {
|
||||||
|
border-top: 1px solid var(--ha-color-border-neutral-quiet);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom-padding {
|
||||||
|
height: max(var(--safe-area-inset-bottom, 0px), var(--ha-space-8));
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combo-box-row {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
align-items: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
min-height: 36px;
|
||||||
|
}
|
||||||
|
.combo-box-row.current-value {
|
||||||
|
background-color: var(--ha-color-fill-primary-quiet-resting);
|
||||||
|
}
|
||||||
|
|
||||||
|
.combo-box-row.selected {
|
||||||
|
background-color: var(--ha-color-fill-neutral-quiet-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.combo-box-row.selected {
|
||||||
|
background-color: var(--ha-color-fill-neutral-normal-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sections {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
gap: var(--ha-space-2);
|
||||||
|
padding: var(--ha-space-3) var(--ha-space-3);
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) .sections {
|
||||||
|
padding: var(--ha-space-3) var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sections ha-filter-chip {
|
||||||
|
flex-shrink: 0;
|
||||||
|
--md-filter-chip-selected-container-color: var(
|
||||||
|
--ha-color-fill-primary-normal-hover
|
||||||
|
);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sections .separator {
|
||||||
|
height: var(--ha-space-8);
|
||||||
|
width: 0;
|
||||||
|
border: 1px solid var(--ha-color-border-neutral-quiet);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title,
|
||||||
|
.title {
|
||||||
|
background-color: var(--ha-color-fill-neutral-quiet-resting);
|
||||||
|
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%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) .title {
|
||||||
|
padding: var(--ha-space-1) var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([mode="dialog"]) ha-textfield {
|
||||||
|
padding: 0 var(--ha-space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title-wrapper {
|
||||||
|
height: 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 1px;
|
||||||
|
width: calc(100% - var(--ha-space-8));
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title.show {
|
||||||
|
opacity: 1;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-search {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: var(--ha-space-3);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ export class HaSelect extends SelectBase {
|
|||||||
height: var(--ha-select-height, 56px);
|
height: var(--ha-select-height, 56px);
|
||||||
}
|
}
|
||||||
.mdc-select--filled .mdc-floating-label {
|
.mdc-select--filled .mdc-floating-label {
|
||||||
inset-inline-start: 12px;
|
inset-inline-start: var(--ha-space-4);
|
||||||
inset-inline-end: initial;
|
inset-inline-end: initial;
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ export class HaSelect extends SelectBase {
|
|||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
.mdc-select .mdc-select__anchor {
|
.mdc-select .mdc-select__anchor {
|
||||||
padding-inline-start: 12px;
|
padding-inline-start: var(--ha-space-4);
|
||||||
padding-inline-end: 0px;
|
padding-inline-end: 0px;
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,10 @@ export class HaSelect extends SelectBase {
|
|||||||
padding-inline-end: var(--select-selected-text-padding-end, 0px);
|
padding-inline-end: var(--select-selected-text-padding-end, 0px);
|
||||||
}
|
}
|
||||||
:host([clearable]) .mdc-select__selected-text-container {
|
:host([clearable]) .mdc-select__selected-text-container {
|
||||||
padding-inline-end: var(--select-selected-text-padding-end, 12px);
|
padding-inline-end: var(
|
||||||
|
--select-selected-text-padding-end,
|
||||||
|
var(--ha-space-4)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
import { css, html, LitElement } from "lit";
|
|
||||||
import { customElement, property, state } from "lit/decorators";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
|
||||||
import type { BackgroundSelector } from "../../data/selector";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
|
||||||
import "../ha-picture-upload";
|
|
||||||
import "../ha-alert";
|
|
||||||
import type { HaPictureUpload } from "../ha-picture-upload";
|
|
||||||
import { URL_PREFIX } from "../../data/image_upload";
|
|
||||||
|
|
||||||
@customElement("ha-selector-background")
|
|
||||||
export class HaBackgroundSelector extends LitElement {
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
|
||||||
|
|
||||||
@property() public value?: any;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public selector!: BackgroundSelector;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = true;
|
|
||||||
|
|
||||||
@state() private yamlBackground = false;
|
|
||||||
|
|
||||||
protected updated(changedProps) {
|
|
||||||
super.updated(changedProps);
|
|
||||||
|
|
||||||
if (changedProps.has("value")) {
|
|
||||||
this.yamlBackground = !!this.value && !this.value.startsWith(URL_PREFIX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
|
||||||
return html`
|
|
||||||
<div>
|
|
||||||
${this.yamlBackground
|
|
||||||
? html`
|
|
||||||
<div class="value">
|
|
||||||
<img
|
|
||||||
src=${this.value}
|
|
||||||
alt=${this.hass.localize(
|
|
||||||
"ui.components.picture-upload.current_image_alt"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ha-alert alert-type="info">
|
|
||||||
${this.hass.localize(
|
|
||||||
`ui.components.selectors.background.yaml_info`
|
|
||||||
)}
|
|
||||||
<ha-button slot="action" @click=${this._clearValue}>
|
|
||||||
${this.hass.localize(
|
|
||||||
`ui.components.picture-upload.clear_picture`
|
|
||||||
)}
|
|
||||||
</ha-button>
|
|
||||||
</ha-alert>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<ha-picture-upload
|
|
||||||
.hass=${this.hass}
|
|
||||||
.value=${this.value?.startsWith(URL_PREFIX) ? this.value : null}
|
|
||||||
.original=${!!this.selector.background?.original}
|
|
||||||
.cropOptions=${this.selector.background?.crop}
|
|
||||||
select-media
|
|
||||||
@change=${this._pictureChanged}
|
|
||||||
></ha-picture-upload>
|
|
||||||
`}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _pictureChanged(ev) {
|
|
||||||
const value = (ev.target as HaPictureUpload).value;
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", { value: value ?? undefined });
|
|
||||||
}
|
|
||||||
|
|
||||||
private _clearValue() {
|
|
||||||
fireEvent(this, "value-changed", { value: undefined });
|
|
||||||
}
|
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
:host {
|
|
||||||
display: block;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
ha-picture-upload {
|
|
||||||
background-color: var(--primary-background-color);
|
|
||||||
border-radius: var(--file-upload-image-border-radius);
|
|
||||||
}
|
|
||||||
div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
ha-button {
|
|
||||||
white-space: nowrap;
|
|
||||||
--mdc-theme-primary: var(--primary-color);
|
|
||||||
}
|
|
||||||
.value {
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
img {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 200px;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
border-radius: var(--file-upload-image-border-radius);
|
|
||||||
transition: opacity 0.3s;
|
|
||||||
opacity: var(--picture-opacity, 1);
|
|
||||||
}
|
|
||||||
img:hover {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-selector-background": HaBackgroundSelector;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -52,9 +52,10 @@ export class HaObjectSelector extends LitElement {
|
|||||||
const translationKey = this.selector.object?.translation_key;
|
const translationKey = this.selector.object?.translation_key;
|
||||||
|
|
||||||
if (this.localizeValue && translationKey) {
|
if (this.localizeValue && translationKey) {
|
||||||
const label = this.localizeValue(
|
const label =
|
||||||
`${translationKey}.fields.${schema.name}`
|
this.localizeValue(`${translationKey}.fields.${schema.name}.name`) ||
|
||||||
);
|
// Fallback for backward compatibility
|
||||||
|
this.localizeValue(`${translationKey}.fields.${schema.name}`);
|
||||||
if (label) {
|
if (label) {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,20 @@ export class HaObjectSelector extends LitElement {
|
|||||||
return this.selector.object?.fields?.[schema.name]?.label || schema.name;
|
return this.selector.object?.fields?.[schema.name]?.label || schema.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _computeHelper = (schema: HaFormSchema): string => {
|
||||||
|
const translationKey = this.selector.object?.translation_key;
|
||||||
|
|
||||||
|
if (this.localizeValue && translationKey) {
|
||||||
|
const helper = this.localizeValue(
|
||||||
|
`${translationKey}.fields.${schema.name}.description`
|
||||||
|
);
|
||||||
|
if (helper) {
|
||||||
|
return helper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.selector.object?.fields?.[schema.name]?.description || "";
|
||||||
|
};
|
||||||
|
|
||||||
private _renderItem(item: any, index: number) {
|
private _renderItem(item: any, index: number) {
|
||||||
const labelField =
|
const labelField =
|
||||||
this.selector.object!.label_field ||
|
this.selector.object!.label_field ||
|
||||||
@@ -214,6 +229,7 @@ export class HaObjectSelector extends LitElement {
|
|||||||
schema: this._schema(this.selector),
|
schema: this._schema(this.selector),
|
||||||
data: {},
|
data: {},
|
||||||
computeLabel: this._computeLabel,
|
computeLabel: this._computeLabel,
|
||||||
|
computeHelper: this._computeHelper,
|
||||||
submitText: this.hass.localize("ui.common.add"),
|
submitText: this.hass.localize("ui.common.add"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import type { HassServiceTarget } from "home-assistant-js-websocket";
|
||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import type { StateSelector } from "../../data/selector";
|
import type { StateSelector } from "../../data/selector";
|
||||||
|
import { extractFromTarget } from "../../data/target";
|
||||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../entity/ha-entity-state-picker";
|
import "../entity/ha-entity-state-picker";
|
||||||
@@ -25,15 +27,29 @@ export class HaSelectorState extends SubscribeMixin(LitElement) {
|
|||||||
@property({ attribute: false }) public context?: {
|
@property({ attribute: false }) public context?: {
|
||||||
filter_attribute?: string;
|
filter_attribute?: string;
|
||||||
filter_entity?: string | string[];
|
filter_entity?: string | string[];
|
||||||
|
filter_target?: HassServiceTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@state() private _entityIds?: string | string[];
|
||||||
|
|
||||||
|
willUpdate(changedProps) {
|
||||||
|
if (changedProps.has("selector") || changedProps.has("context")) {
|
||||||
|
this._resolveEntityIds(
|
||||||
|
this.selector.state?.entity_id,
|
||||||
|
this.context?.filter_entity,
|
||||||
|
this.context?.filter_target
|
||||||
|
).then((entityIds) => {
|
||||||
|
this._entityIds = entityIds;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this.selector.state?.multiple) {
|
if (this.selector.state?.multiple) {
|
||||||
return html`
|
return html`
|
||||||
<ha-entity-states-picker
|
<ha-entity-states-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entityId=${this.selector.state?.entity_id ||
|
.entityId=${this._entityIds}
|
||||||
this.context?.filter_entity}
|
|
||||||
.attribute=${this.selector.state?.attribute ||
|
.attribute=${this.selector.state?.attribute ||
|
||||||
this.context?.filter_attribute}
|
this.context?.filter_attribute}
|
||||||
.extraOptions=${this.selector.state?.extra_options}
|
.extraOptions=${this.selector.state?.extra_options}
|
||||||
@@ -50,8 +66,7 @@ export class HaSelectorState extends SubscribeMixin(LitElement) {
|
|||||||
return html`
|
return html`
|
||||||
<ha-entity-state-picker
|
<ha-entity-state-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.entityId=${this.selector.state?.entity_id ||
|
.entityId=${this._entityIds}
|
||||||
this.context?.filter_entity}
|
|
||||||
.attribute=${this.selector.state?.attribute ||
|
.attribute=${this.selector.state?.attribute ||
|
||||||
this.context?.filter_attribute}
|
this.context?.filter_attribute}
|
||||||
.extraOptions=${this.selector.state?.extra_options}
|
.extraOptions=${this.selector.state?.extra_options}
|
||||||
@@ -65,6 +80,24 @@ export class HaSelectorState extends SubscribeMixin(LitElement) {
|
|||||||
></ha-entity-state-picker>
|
></ha-entity-state-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _resolveEntityIds(
|
||||||
|
selectorEntityId: string | string[] | undefined,
|
||||||
|
contextFilterEntity: string | string[] | undefined,
|
||||||
|
contextFilterTarget: HassServiceTarget | undefined
|
||||||
|
): Promise<string | string[] | undefined> {
|
||||||
|
if (selectorEntityId !== undefined) {
|
||||||
|
return selectorEntityId;
|
||||||
|
}
|
||||||
|
if (contextFilterEntity !== undefined) {
|
||||||
|
return contextFilterEntity;
|
||||||
|
}
|
||||||
|
if (contextFilterTarget !== undefined) {
|
||||||
|
const result = await extractFromTarget(this.hass, contextFilterTarget);
|
||||||
|
return result.referenced_entities;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class HaSelectorUiStateContent extends SubscribeMixin(LitElement) {
|
|||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.allowName=${this.selector.ui_state_content?.allow_name}
|
.allowName=${this.selector.ui_state_content?.allow_name || false}
|
||||||
></ha-entity-state-content-picker>
|
></ha-entity-state-content-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ const LOAD_ELEMENTS = {
|
|||||||
file: () => import("./ha-selector-file"),
|
file: () => import("./ha-selector-file"),
|
||||||
floor: () => import("./ha-selector-floor"),
|
floor: () => import("./ha-selector-floor"),
|
||||||
label: () => import("./ha-selector-label"),
|
label: () => import("./ha-selector-label"),
|
||||||
background: () => import("./ha-selector-background"),
|
|
||||||
language: () => import("./ha-selector-language"),
|
language: () => import("./ha-selector-language"),
|
||||||
navigation: () => import("./ha-selector-navigation"),
|
navigation: () => import("./ha-selector-navigation"),
|
||||||
number: () => import("./ha-selector-number"),
|
number: () => import("./ha-selector-number"),
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import type { HomeAssistant, ValueChangedEvent } from "../types";
|
|||||||
import { documentationUrl } from "../util/documentation-url";
|
import { documentationUrl } from "../util/documentation-url";
|
||||||
import "./ha-checkbox";
|
import "./ha-checkbox";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
|
import "./ha-markdown";
|
||||||
import "./ha-selector/ha-selector";
|
import "./ha-selector/ha-selector";
|
||||||
import "./ha-service-picker";
|
import "./ha-service-picker";
|
||||||
import "./ha-service-section-icon";
|
import "./ha-service-section-icon";
|
||||||
@@ -684,10 +685,14 @@ export class HaServiceControl extends LitElement {
|
|||||||
dataField.key}</span
|
dataField.key}</span
|
||||||
>
|
>
|
||||||
<span slot="description"
|
<span slot="description"
|
||||||
>${this.hass.localize(
|
><ha-markdown
|
||||||
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description`
|
breaks
|
||||||
) || dataField?.description}</span
|
allow-svg
|
||||||
>
|
.content=${this.hass.localize(
|
||||||
|
`component.${domain}.services.${serviceName}.fields.${dataField.key}.description`
|
||||||
|
) || dataField?.description}
|
||||||
|
></ha-markdown>
|
||||||
|
</span>
|
||||||
<ha-selector
|
<ha-selector
|
||||||
.context=${this._selectorContext(targetEntities)}
|
.context=${this._selectorContext(targetEntities)}
|
||||||
.disabled=${this.disabled ||
|
.disabled=${this.disabled ||
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class HaServicePicker extends LitElement {
|
|||||||
item,
|
item,
|
||||||
{ index }
|
{ index }
|
||||||
) => html`
|
) => html`
|
||||||
<ha-combo-box-item type="button" border-top .borderTop=${index !== 0}>
|
<ha-combo-box-item type="button" .borderTop=${index !== 0}>
|
||||||
<ha-service-icon
|
<ha-service-icon
|
||||||
slot="start"
|
slot="start"
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -76,34 +76,42 @@ class HaServicePicker extends LitElement {
|
|||||||
</ha-combo-box-item>
|
</ha-combo-box-item>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
private _valueRenderer: PickerValueRenderer = (value) => {
|
private _valueRenderer = memoizeOne(
|
||||||
const serviceId = value;
|
(
|
||||||
const [domain, service] = serviceId.split(".");
|
localize: LocalizeFunc,
|
||||||
|
services: HomeAssistant["services"]
|
||||||
|
): PickerValueRenderer =>
|
||||||
|
(value) => {
|
||||||
|
const serviceId = value;
|
||||||
|
const [domain, service] = serviceId.split(".");
|
||||||
|
|
||||||
if (!this.hass.services[domain]?.[service]) {
|
if (!services[domain]?.[service]) {
|
||||||
return html`
|
return html`
|
||||||
<ha-svg-icon slot="start" .path=${mdiRoomService}></ha-svg-icon>
|
<ha-svg-icon slot="start" .path=${mdiRoomService}></ha-svg-icon>
|
||||||
<span slot="headline">${value}</span>
|
<span slot="headline">${value}</span>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const serviceName =
|
const serviceName =
|
||||||
this.hass.localize(`component.${domain}.services.${service}.name`) ||
|
localize(`component.${domain}.services.${service}.name`) ||
|
||||||
this.hass.services[domain][service].name ||
|
services[domain][service].name ||
|
||||||
service;
|
service;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-service-icon
|
<ha-service-icon
|
||||||
slot="start"
|
slot="start"
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.service=${serviceId}
|
.service=${serviceId}
|
||||||
></ha-service-icon>
|
></ha-service-icon>
|
||||||
<span slot="headline">${serviceName}</span>
|
<span slot="headline">${serviceName}</span>
|
||||||
${this.showServiceId
|
${this.showServiceId
|
||||||
? html`<span slot="supporting-text" class="code">${serviceId}</span>`
|
? html`<span slot="supporting-text" class="code"
|
||||||
: nothing}
|
>${serviceId}</span
|
||||||
`;
|
>`
|
||||||
};
|
: nothing}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const placeholder =
|
const placeholder =
|
||||||
@@ -123,7 +131,10 @@ class HaServicePicker extends LitElement {
|
|||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer(
|
||||||
|
this.hass.localize,
|
||||||
|
this.hass.services
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -162,7 +173,9 @@ class HaServicePicker extends LitElement {
|
|||||||
const description =
|
const description =
|
||||||
this.hass.localize(
|
this.hass.localize(
|
||||||
`component.${domain}.services.${service}.description`
|
`component.${domain}.services.${service}.description`
|
||||||
) || services[domain][service].description;
|
) ||
|
||||||
|
services[domain][service].description ||
|
||||||
|
"";
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
id: serviceId,
|
id: serviceId,
|
||||||
|
|||||||
@@ -29,9 +29,11 @@ import memoizeOne from "memoize-one";
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { toggleAttribute } from "../common/dom/toggle_attribute";
|
import { toggleAttribute } from "../common/dom/toggle_attribute";
|
||||||
import { stringCompare } from "../common/string/compare";
|
import { stringCompare } from "../common/string/compare";
|
||||||
|
import { computeRTL } from "../common/util/compute_rtl";
|
||||||
import { throttle } from "../common/util/throttle";
|
import { throttle } from "../common/util/throttle";
|
||||||
import { subscribeFrontendUserData } from "../data/frontend";
|
import { subscribeFrontendUserData } from "../data/frontend";
|
||||||
import type { ActionHandlerDetail } from "../data/lovelace/action_handler";
|
import type { ActionHandlerDetail } from "../data/lovelace/action_handler";
|
||||||
|
import { getDefaultPanelUrlPath } from "../data/panel";
|
||||||
import type { PersistentNotification } from "../data/persistent_notification";
|
import type { PersistentNotification } from "../data/persistent_notification";
|
||||||
import { subscribeNotifications } from "../data/persistent_notification";
|
import { subscribeNotifications } from "../data/persistent_notification";
|
||||||
import { subscribeRepairsIssueRegistry } from "../data/repairs";
|
import { subscribeRepairsIssueRegistry } from "../data/repairs";
|
||||||
@@ -141,7 +143,7 @@ const defaultPanelSorter = (
|
|||||||
export const computePanels = memoizeOne(
|
export const computePanels = memoizeOne(
|
||||||
(
|
(
|
||||||
panels: HomeAssistant["panels"],
|
panels: HomeAssistant["panels"],
|
||||||
defaultPanel: HomeAssistant["defaultPanel"],
|
defaultPanel: string,
|
||||||
panelsOrder: string[],
|
panelsOrder: string[],
|
||||||
hiddenPanels: string[],
|
hiddenPanels: string[],
|
||||||
locale: HomeAssistant["locale"]
|
locale: HomeAssistant["locale"]
|
||||||
@@ -156,7 +158,9 @@ export const computePanels = memoizeOne(
|
|||||||
Object.values(panels).forEach((panel) => {
|
Object.values(panels).forEach((panel) => {
|
||||||
if (
|
if (
|
||||||
hiddenPanels.includes(panel.url_path) ||
|
hiddenPanels.includes(panel.url_path) ||
|
||||||
(!panel.title && panel.url_path !== defaultPanel)
|
(!panel.title && panel.url_path !== defaultPanel) ||
|
||||||
|
(panel.default_visible === false &&
|
||||||
|
!panelsOrder.includes(panel.url_path))
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -295,7 +299,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
hass.localize !== oldHass.localize ||
|
hass.localize !== oldHass.localize ||
|
||||||
hass.locale !== oldHass.locale ||
|
hass.locale !== oldHass.locale ||
|
||||||
hass.states !== oldHass.states ||
|
hass.states !== oldHass.states ||
|
||||||
hass.defaultPanel !== oldHass.defaultPanel ||
|
hass.userData !== oldHass.userData ||
|
||||||
|
hass.systemData !== oldHass.systemData ||
|
||||||
hass.connected !== oldHass.connected
|
hass.connected !== oldHass.connected
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -398,9 +403,11 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||||
|
|
||||||
const [beforeSpacer, afterSpacer] = computePanels(
|
const [beforeSpacer, afterSpacer] = computePanels(
|
||||||
this.hass.panels,
|
this.hass.panels,
|
||||||
this.hass.defaultPanel,
|
defaultPanel,
|
||||||
this._panelOrder,
|
this._panelOrder,
|
||||||
this._hiddenPanels,
|
this._hiddenPanels,
|
||||||
this.hass.locale
|
this.hass.locale
|
||||||
@@ -415,23 +422,27 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
@scroll=${this._listboxScroll}
|
@scroll=${this._listboxScroll}
|
||||||
@keydown=${this._listboxKeydown}
|
@keydown=${this._listboxKeydown}
|
||||||
>
|
>
|
||||||
${this._renderPanels(beforeSpacer, selectedPanel)}
|
${this._renderPanels(beforeSpacer, selectedPanel, defaultPanel)}
|
||||||
${this._renderSpacer()}
|
${this._renderSpacer()}
|
||||||
${this._renderPanels(afterSpacer, selectedPanel)}
|
${this._renderPanels(afterSpacer, selectedPanel, defaultPanel)}
|
||||||
${this._renderExternalConfiguration()}
|
${this._renderExternalConfiguration()}
|
||||||
</ha-md-list>
|
</ha-md-list>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderPanels(panels: PanelInfo[], selectedPanel: string) {
|
private _renderPanels(
|
||||||
|
panels: PanelInfo[],
|
||||||
|
selectedPanel: string,
|
||||||
|
defaultPanel: string
|
||||||
|
) {
|
||||||
return panels.map((panel) =>
|
return panels.map((panel) =>
|
||||||
this._renderPanel(
|
this._renderPanel(
|
||||||
panel.url_path,
|
panel.url_path,
|
||||||
panel.url_path === this.hass.defaultPanel
|
panel.url_path === defaultPanel
|
||||||
? panel.title || this.hass.localize("panel.states")
|
? panel.title || this.hass.localize("panel.states")
|
||||||
: this.hass.localize(`panel.${panel.title}`) || panel.title,
|
: this.hass.localize(`panel.${panel.title}`) || panel.title,
|
||||||
panel.icon,
|
panel.icon,
|
||||||
panel.url_path === this.hass.defaultPanel && !panel.icon
|
panel.url_path === defaultPanel && !panel.icon
|
||||||
? PANEL_ICONS.lovelace
|
? PANEL_ICONS.lovelace
|
||||||
: panel.url_path in PANEL_ICONS
|
: panel.url_path in PANEL_ICONS
|
||||||
? PANEL_ICONS[panel.url_path]
|
? PANEL_ICONS[panel.url_path]
|
||||||
@@ -536,11 +547,17 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _renderUserItem(selectedPanel: string) {
|
private _renderUserItem(selectedPanel: string) {
|
||||||
|
const isRTL = computeRTL(this.hass);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-md-list-item
|
<ha-md-list-item
|
||||||
href="/profile"
|
href="/profile"
|
||||||
type="link"
|
type="link"
|
||||||
class="user ${selectedPanel === "profile" ? " selected" : ""}"
|
class=${classMap({
|
||||||
|
user: true,
|
||||||
|
selected: selectedPanel === "profile",
|
||||||
|
rtl: isRTL,
|
||||||
|
})}
|
||||||
@mouseenter=${this._itemMouseEnter}
|
@mouseenter=${this._itemMouseEnter}
|
||||||
@mouseleave=${this._itemMouseLeave}
|
@mouseleave=${this._itemMouseLeave}
|
||||||
>
|
>
|
||||||
@@ -666,7 +683,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
tooltip.style.display = "block";
|
tooltip.style.display = "block";
|
||||||
tooltip.style.position = "fixed";
|
tooltip.style.position = "fixed";
|
||||||
tooltip.style.top = `${top}px`;
|
tooltip.style.top = `${top}px`;
|
||||||
tooltip.style.left = `calc(${item.offsetLeft + item.clientWidth + 8}px + var(--safe-area-inset-left, 0px))`;
|
tooltip.style.left = `calc(${item.offsetLeft + item.clientWidth + 8}px + var(--safe-area-inset-left, var(--ha-space-0)))`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _hideTooltip() {
|
private _hideTooltip() {
|
||||||
@@ -705,13 +722,17 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
background-color: var(--sidebar-background-color);
|
background-color: var(--sidebar-background-color);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-bottom: calc(14px + var(--safe-area-inset-bottom, 0px));
|
padding-bottom: calc(
|
||||||
|
14px + var(--safe-area-inset-bottom, var(--ha-space-0))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
.menu {
|
.menu {
|
||||||
height: calc(var(--header-height) + var(--safe-area-inset-top, 0px));
|
height: calc(
|
||||||
|
var(--header-height) + var(--safe-area-inset-top, var(--ha-space-0))
|
||||||
|
);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0 4px;
|
padding: 0 var(--ha-space-1);
|
||||||
border-bottom: 1px solid transparent;
|
border-bottom: 1px solid transparent;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
font-weight: var(--ha-font-weight-normal);
|
font-weight: var(--ha-font-weight-normal);
|
||||||
@@ -726,13 +747,17 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
);
|
);
|
||||||
font-size: var(--ha-font-size-xl);
|
font-size: var(--ha-font-size-xl);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-left: calc(4px + var(--safe-area-inset-left, 0px));
|
padding-left: calc(
|
||||||
padding-inline-start: calc(4px + var(--safe-area-inset-left, 0px));
|
var(--ha-space-1) + var(--safe-area-inset-left, var(--ha-space-0))
|
||||||
|
);
|
||||||
|
padding-inline-start: calc(
|
||||||
|
var(--ha-space-1) + var(--safe-area-inset-left, var(--ha-space-0))
|
||||||
|
);
|
||||||
padding-inline-end: initial;
|
padding-inline-end: initial;
|
||||||
padding-top: var(--safe-area-inset-top, 0px);
|
padding-top: var(--safe-area-inset-top, var(--ha-space-0));
|
||||||
}
|
}
|
||||||
:host([expanded]) .menu {
|
:host([expanded]) .menu {
|
||||||
width: calc(256px + var(--safe-area-inset-left, 0px));
|
width: calc(256px + var(--safe-area-inset-left, var(--ha-space-0)));
|
||||||
}
|
}
|
||||||
:host([narrow][expanded]) .menu {
|
:host([narrow][expanded]) .menu {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -748,8 +773,8 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
:host([narrow]) .title {
|
:host([narrow]) .title {
|
||||||
margin: 0;
|
margin: var(--ha-space-0);
|
||||||
padding: 0 16px;
|
padding: var(--ha-space-0) var(--ha-space-4);
|
||||||
}
|
}
|
||||||
:host([expanded]) .title {
|
:host([expanded]) .title {
|
||||||
display: initial;
|
display: initial;
|
||||||
@@ -761,13 +786,16 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
ha-fade-in,
|
ha-fade-in,
|
||||||
ha-md-list {
|
ha-md-list {
|
||||||
height: calc(
|
height: calc(
|
||||||
100% - var(--header-height) - var(--safe-area-inset-top, 0px) -
|
100% - var(--header-height) - var(
|
||||||
|
--safe-area-inset-top,
|
||||||
|
var(--ha-space-0)
|
||||||
|
) -
|
||||||
132px
|
132px
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-fade-in {
|
ha-fade-in {
|
||||||
padding: 4px 0;
|
padding: var(--ha-space-1) var(--ha-space-0);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -777,29 +805,29 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
ha-md-list {
|
ha-md-list {
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
background: none;
|
background: none;
|
||||||
margin-left: var(--safe-area-inset-left, 0px);
|
margin-left: var(--safe-area-inset-left, var(--ha-space-0));
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-md-list-item {
|
ha-md-list-item {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
margin: 4px;
|
margin: var(--ha-space-1);
|
||||||
border-radius: var(--ha-border-radius-sm);
|
border-radius: var(--ha-border-radius-sm);
|
||||||
--md-list-item-one-line-container-height: 40px;
|
--md-list-item-one-line-container-height: var(--ha-space-10);
|
||||||
--md-list-item-top-space: 0;
|
--md-list-item-top-space: 0;
|
||||||
--md-list-item-bottom-space: 0;
|
--md-list-item-bottom-space: 0;
|
||||||
width: 48px;
|
width: var(--ha-space-12);
|
||||||
position: relative;
|
position: relative;
|
||||||
--md-list-item-label-text-color: var(--sidebar-text-color);
|
--md-list-item-label-text-color: var(--sidebar-text-color);
|
||||||
--md-list-item-leading-space: 12px;
|
--md-list-item-leading-space: var(--ha-space-3);
|
||||||
--md-list-item-trailing-space: 12px;
|
--md-list-item-trailing-space: var(--ha-space-3);
|
||||||
--md-list-item-leading-icon-size: 24px;
|
--md-list-item-leading-icon-size: var(--ha-space-6);
|
||||||
}
|
}
|
||||||
:host([expanded]) ha-md-list-item {
|
:host([expanded]) ha-md-list-item {
|
||||||
width: 248px;
|
width: 248px;
|
||||||
}
|
}
|
||||||
:host([narrow][expanded]) ha-md-list-item {
|
:host([narrow][expanded]) ha-md-list-item {
|
||||||
width: calc(240px - var(--safe-area-inset-left, 0px));
|
width: calc(240px - var(--safe-area-inset-left, var(--ha-space-0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-md-list-item.selected {
|
ha-md-list-item.selected {
|
||||||
@@ -823,7 +851,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
ha-icon[slot="start"],
|
ha-icon[slot="start"],
|
||||||
ha-svg-icon[slot="start"] {
|
ha-svg-icon[slot="start"] {
|
||||||
width: 24px;
|
width: var(--ha-space-6);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
color: var(--sidebar-icon-color);
|
color: var(--sidebar-icon-color);
|
||||||
}
|
}
|
||||||
@@ -856,7 +884,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-width: 8px;
|
min-width: var(--ha-space-2);
|
||||||
border-radius: var(--ha-border-radius-xl);
|
border-radius: var(--ha-border-radius-xl);
|
||||||
font-weight: var(--ha-font-weight-normal);
|
font-weight: var(--ha-font-weight-normal);
|
||||||
line-height: normal;
|
line-height: normal;
|
||||||
@@ -867,22 +895,26 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
ha-svg-icon + .badge {
|
ha-svg-icon + .badge {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 4px;
|
top: var(--ha-space-1);
|
||||||
left: 26px;
|
left: 26px;
|
||||||
border-radius: var(--ha-border-radius-md);
|
border-radius: var(--ha-border-radius-md);
|
||||||
font-size: 0.65em;
|
font-size: 0.65em;
|
||||||
line-height: var(--ha-line-height-expanded);
|
line-height: var(--ha-line-height-expanded);
|
||||||
padding: 0 4px;
|
padding: var(--ha-space-0) var(--ha-space-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-md-list-item.user {
|
ha-md-list-item.user {
|
||||||
--md-list-item-leading-icon-size: 40px;
|
--md-list-item-leading-icon-size: var(--ha-space-10);
|
||||||
--md-list-item-leading-space: 4px;
|
--md-list-item-leading-space: var(--ha-space-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-md-list-item.user.rtl {
|
||||||
|
--md-list-item-leading-space: var(--ha-space-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
ha-user-badge {
|
ha-user-badge {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-right: -8px;
|
margin-right: calc(var(--ha-space-2) * -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.spacer {
|
.spacer {
|
||||||
@@ -894,7 +926,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
color: var(--sidebar-text-color);
|
color: var(--sidebar-text-color);
|
||||||
font-size: var(--ha-font-size-m);
|
font-size: var(--ha-font-size-m);
|
||||||
font-weight: var(--ha-font-weight-medium);
|
font-weight: var(--ha-font-weight-medium);
|
||||||
padding: 16px;
|
padding: var(--ha-space-4);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,7 +938,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
color: var(--sidebar-background-color);
|
color: var(--sidebar-background-color);
|
||||||
background-color: var(--sidebar-text-color);
|
background-color: var(--sidebar-text-color);
|
||||||
padding: 4px;
|
padding: var(--ha-space-1);
|
||||||
font-weight: var(--ha-font-weight-medium);
|
font-weight: var(--ha-font-weight-medium);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ export class HaTooltip extends Tooltip {
|
|||||||
@property({ attribute: "show-delay", type: Number }) showDelay = 150;
|
@property({ attribute: "show-delay", type: Number }) showDelay = 150;
|
||||||
|
|
||||||
/** The amount of time to wait before hiding the tooltip when the user mouses out.. */
|
/** The amount of time to wait before hiding the tooltip when the user mouses out.. */
|
||||||
@property({ attribute: "hide-delay", type: Number }) hideDelay = 400;
|
@property({ attribute: "hide-delay", type: Number }) hideDelay = 150;
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
|
|||||||
97
src/components/ha-trigger-icon.ts
Normal file
97
src/components/ha-trigger-icon.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import {
|
||||||
|
mdiAvTimer,
|
||||||
|
mdiCalendar,
|
||||||
|
mdiClockOutline,
|
||||||
|
mdiCodeBraces,
|
||||||
|
mdiDevices,
|
||||||
|
mdiFormatListBulleted,
|
||||||
|
mdiGestureDoubleTap,
|
||||||
|
mdiHomeAssistant,
|
||||||
|
mdiMapMarker,
|
||||||
|
mdiMapMarkerRadius,
|
||||||
|
mdiMessageAlert,
|
||||||
|
mdiMicrophoneMessage,
|
||||||
|
mdiNfcVariant,
|
||||||
|
mdiNumeric,
|
||||||
|
mdiStateMachine,
|
||||||
|
mdiSwapHorizontal,
|
||||||
|
mdiWeatherSunny,
|
||||||
|
mdiWebhook,
|
||||||
|
} from "@mdi/js";
|
||||||
|
import { html, LitElement, nothing } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { until } from "lit/directives/until";
|
||||||
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
|
import { FALLBACK_DOMAIN_ICONS, triggerIcon } from "../data/icons";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./ha-icon";
|
||||||
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
|
export const TRIGGER_ICONS = {
|
||||||
|
calendar: mdiCalendar,
|
||||||
|
device: mdiDevices,
|
||||||
|
event: mdiGestureDoubleTap,
|
||||||
|
state: mdiStateMachine,
|
||||||
|
geo_location: mdiMapMarker,
|
||||||
|
homeassistant: mdiHomeAssistant,
|
||||||
|
mqtt: mdiSwapHorizontal,
|
||||||
|
numeric_state: mdiNumeric,
|
||||||
|
sun: mdiWeatherSunny,
|
||||||
|
conversation: mdiMicrophoneMessage,
|
||||||
|
tag: mdiNfcVariant,
|
||||||
|
template: mdiCodeBraces,
|
||||||
|
time: mdiClockOutline,
|
||||||
|
time_pattern: mdiAvTimer,
|
||||||
|
webhook: mdiWebhook,
|
||||||
|
persistent_notification: mdiMessageAlert,
|
||||||
|
zone: mdiMapMarkerRadius,
|
||||||
|
list: mdiFormatListBulleted,
|
||||||
|
};
|
||||||
|
|
||||||
|
@customElement("ha-trigger-icon")
|
||||||
|
export class HaTriggerIcon extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public trigger?: string;
|
||||||
|
|
||||||
|
@property() public icon?: string;
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
if (this.icon) {
|
||||||
|
return html`<ha-icon .icon=${this.icon}></ha-icon>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.trigger) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.hass) {
|
||||||
|
return this._renderFallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const icon = triggerIcon(this.hass, this.trigger).then((icn) => {
|
||||||
|
if (icn) {
|
||||||
|
return html`<ha-icon .icon=${icn}></ha-icon>`;
|
||||||
|
}
|
||||||
|
return this._renderFallback();
|
||||||
|
});
|
||||||
|
|
||||||
|
return html`${until(icon)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _renderFallback() {
|
||||||
|
const domain = computeDomain(this.trigger!);
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-svg-icon
|
||||||
|
.path=${TRIGGER_ICONS[this.trigger!] || FALLBACK_DOMAIN_ICONS[domain]}
|
||||||
|
></ha-svg-icon>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-trigger-icon": HaTriggerIcon;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import {
|
||||||
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
customElement,
|
||||||
|
eventOptions,
|
||||||
|
property,
|
||||||
|
query,
|
||||||
|
state,
|
||||||
|
} from "lit/decorators";
|
||||||
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { mdiClose } from "@mdi/js";
|
import { mdiClose } from "@mdi/js";
|
||||||
import "./ha-dialog-header";
|
import "@home-assistant/webawesome/dist/components/dialog/dialog";
|
||||||
import "./ha-icon-button";
|
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
|
import "./ha-dialog-header";
|
||||||
|
import "./ha-icon-button";
|
||||||
|
|
||||||
export type DialogWidth = "small" | "medium" | "large" | "full";
|
export type DialogWidth = "small" | "medium" | "large" | "full";
|
||||||
|
|
||||||
@@ -25,6 +32,8 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
*
|
*
|
||||||
* @slot header - Replace the entire header area.
|
* @slot header - Replace the entire header area.
|
||||||
* @slot headerNavigationIcon - Leading header action (e.g. close/back button).
|
* @slot headerNavigationIcon - Leading header action (e.g. close/back button).
|
||||||
|
* @slot headerTitle - Custom title content (used when header-title is not set).
|
||||||
|
* @slot headerSubtitle - Custom subtitle content (used when header-subtitle is not set).
|
||||||
* @slot headerActionItems - Trailing header actions (e.g. buttons, menus).
|
* @slot headerActionItems - Trailing header actions (e.g. buttons, menus).
|
||||||
* @slot - Dialog content body.
|
* @slot - Dialog content body.
|
||||||
* @slot footer - Dialog footer content.
|
* @slot footer - Dialog footer content.
|
||||||
@@ -46,8 +55,8 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
* @attr {boolean} open - Controls the dialog open state.
|
* @attr {boolean} open - Controls the dialog open state.
|
||||||
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
|
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
|
||||||
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
|
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
|
||||||
* @attr {string} header-title - Header title text when no custom title slot is provided.
|
* @attr {string} header-title - Header title text. If not set, the headerTitle slot is used.
|
||||||
* @attr {string} header-subtitle - Header subtitle text when no custom subtitle slot is provided.
|
* @attr {string} header-subtitle - Header subtitle text. If not set, the headerSubtitle slot is used.
|
||||||
* @attr {("above"|"below")} header-subtitle-position - Position of the subtitle relative to the title. Defaults to "below".
|
* @attr {("above"|"below")} header-subtitle-position - Position of the subtitle relative to the title. Defaults to "below".
|
||||||
* @attr {boolean} flexcontent - Makes the dialog body a flex container for flexible layouts.
|
* @attr {boolean} flexcontent - Makes the dialog body a flex container for flexible layouts.
|
||||||
*
|
*
|
||||||
@@ -66,6 +75,12 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
|
|||||||
export class HaWaDialog extends LitElement {
|
export class HaWaDialog extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: "aria-labelledby" })
|
||||||
|
public ariaLabelledBy?: string;
|
||||||
|
|
||||||
|
@property({ attribute: "aria-describedby" })
|
||||||
|
public ariaDescribedBy?: string;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ type: Boolean, reflect: true })
|
||||||
public open = false;
|
public open = false;
|
||||||
|
|
||||||
@@ -75,11 +90,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
@property({ type: Boolean, reflect: true, attribute: "prevent-scrim-close" })
|
@property({ type: Boolean, reflect: true, attribute: "prevent-scrim-close" })
|
||||||
public preventScrimClose = false;
|
public preventScrimClose = false;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-title" })
|
@property({ attribute: "header-title" })
|
||||||
public headerTitle = "";
|
public headerTitle?: string;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-subtitle" })
|
@property({ attribute: "header-subtitle" })
|
||||||
public headerSubtitle = "";
|
public headerSubtitle?: string;
|
||||||
|
|
||||||
@property({ type: String, attribute: "header-subtitle-position" })
|
@property({ type: String, attribute: "header-subtitle-position" })
|
||||||
public headerSubtitlePosition: "above" | "below" = "below";
|
public headerSubtitlePosition: "above" | "below" = "below";
|
||||||
@@ -90,6 +105,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
@state()
|
@state()
|
||||||
private _open = false;
|
private _open = false;
|
||||||
|
|
||||||
|
@query(".body") public bodyContainer!: HTMLDivElement;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _bodyScrolled = false;
|
||||||
|
|
||||||
protected updated(
|
protected updated(
|
||||||
changedProperties: Map<string | number | symbol, unknown>
|
changedProperties: Map<string | number | symbol, unknown>
|
||||||
): void {
|
): void {
|
||||||
@@ -106,11 +126,20 @@ export class HaWaDialog extends LitElement {
|
|||||||
.open=${this._open}
|
.open=${this._open}
|
||||||
.lightDismiss=${!this.preventScrimClose}
|
.lightDismiss=${!this.preventScrimClose}
|
||||||
without-header
|
without-header
|
||||||
|
aria-labelledby=${ifDefined(
|
||||||
|
this.ariaLabelledBy ||
|
||||||
|
(this.headerTitle !== undefined ? "ha-wa-dialog-title" : undefined)
|
||||||
|
)}
|
||||||
|
aria-describedby=${ifDefined(this.ariaDescribedBy)}
|
||||||
@wa-show=${this._handleShow}
|
@wa-show=${this._handleShow}
|
||||||
|
@wa-after-show=${this._handleAfterShow}
|
||||||
@wa-after-hide=${this._handleAfterHide}
|
@wa-after-hide=${this._handleAfterHide}
|
||||||
>
|
>
|
||||||
<slot name="header">
|
<slot name="header">
|
||||||
<ha-dialog-header .subtitlePosition=${this.headerSubtitlePosition}>
|
<ha-dialog-header
|
||||||
|
.subtitlePosition=${this.headerSubtitlePosition}
|
||||||
|
.showBorder=${this._bodyScrolled}
|
||||||
|
>
|
||||||
<slot name="headerNavigationIcon" slot="navigationIcon">
|
<slot name="headerNavigationIcon" slot="navigationIcon">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
data-dialog="close"
|
data-dialog="close"
|
||||||
@@ -118,18 +147,18 @@ export class HaWaDialog extends LitElement {
|
|||||||
.path=${mdiClose}
|
.path=${mdiClose}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</slot>
|
</slot>
|
||||||
${this.headerTitle
|
${this.headerTitle !== undefined
|
||||||
? html`<span slot="title" class="title">
|
? html`<span slot="title" class="title" id="ha-wa-dialog-title">
|
||||||
${this.headerTitle}
|
${this.headerTitle}
|
||||||
</span>`
|
</span>`
|
||||||
: nothing}
|
: html`<slot name="headerTitle" slot="title"></slot>`}
|
||||||
${this.headerSubtitle
|
${this.headerSubtitle !== undefined
|
||||||
? html`<span slot="subtitle">${this.headerSubtitle}</span>`
|
? html`<span slot="subtitle">${this.headerSubtitle}</span>`
|
||||||
: nothing}
|
: html`<slot name="headerSubtitle" slot="subtitle"></slot>`}
|
||||||
<slot name="headerActionItems" slot="actionItems"></slot>
|
<slot name="headerActionItems" slot="actionItems"></slot>
|
||||||
</ha-dialog-header>
|
</ha-dialog-header>
|
||||||
</slot>
|
</slot>
|
||||||
<div class="body ha-scrollbar">
|
<div class="body ha-scrollbar" @scroll=${this._handleBodyScroll}>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
<slot name="footer" slot="footer"></slot>
|
<slot name="footer" slot="footer"></slot>
|
||||||
@@ -146,6 +175,10 @@ export class HaWaDialog extends LitElement {
|
|||||||
(this.querySelector("[autofocus]") as HTMLElement | null)?.focus();
|
(this.querySelector("[autofocus]") as HTMLElement | null)?.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _handleAfterShow = () => {
|
||||||
|
fireEvent(this, "after-show");
|
||||||
|
};
|
||||||
|
|
||||||
private _handleAfterHide = () => {
|
private _handleAfterHide = () => {
|
||||||
this._open = false;
|
this._open = false;
|
||||||
fireEvent(this, "closed");
|
fireEvent(this, "closed");
|
||||||
@@ -156,6 +189,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
this._open = false;
|
this._open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@eventOptions({ passive: true })
|
||||||
|
private _handleBodyScroll(ev: Event) {
|
||||||
|
this._bodyScrolled = (ev.target as HTMLDivElement).scrollTop > 0;
|
||||||
|
}
|
||||||
|
|
||||||
static styles = [
|
static styles = [
|
||||||
haStyleScrollbar,
|
haStyleScrollbar,
|
||||||
css`
|
css`
|
||||||
@@ -172,7 +210,7 @@ export class HaWaDialog extends LitElement {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
--width: var(--ha-dialog-width-md, min(580px, var(--full-width)));
|
--width: min(var(--ha-dialog-width-md, 580px), var(--full-width));
|
||||||
--spacing: var(--dialog-content-padding, var(--ha-space-6));
|
--spacing: var(--dialog-content-padding, var(--ha-space-6));
|
||||||
--show-duration: var(--ha-dialog-show-duration, 200ms);
|
--show-duration: var(--ha-dialog-show-duration, 200ms);
|
||||||
--hide-duration: var(--ha-dialog-hide-duration, 200ms);
|
--hide-duration: var(--ha-dialog-hide-duration, 200ms);
|
||||||
@@ -193,11 +231,11 @@ export class HaWaDialog extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
:host([width="small"]) wa-dialog {
|
:host([width="small"]) wa-dialog {
|
||||||
--width: var(--ha-dialog-width-sm, min(320px, var(--full-width)));
|
--width: min(var(--ha-dialog-width-sm, 320px), var(--full-width));
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([width="large"]) wa-dialog {
|
:host([width="large"]) wa-dialog {
|
||||||
--width: var(--ha-dialog-width-lg, min(720px, var(--full-width)));
|
--width: min(var(--ha-dialog-width-lg, 720px), var(--full-width));
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([width="full"]) wa-dialog {
|
:host([width="full"]) wa-dialog {
|
||||||
@@ -211,6 +249,7 @@ export class HaWaDialog extends LitElement {
|
|||||||
--ha-dialog-max-height,
|
--ha-dialog-max-height,
|
||||||
calc(100% - var(--ha-space-20))
|
calc(100% - var(--ha-space-20))
|
||||||
);
|
);
|
||||||
|
min-height: var(--ha-dialog-min-height);
|
||||||
position: var(--dialog-surface-position, relative);
|
position: var(--dialog-surface-position, relative);
|
||||||
margin-top: var(--dialog-surface-margin-top, auto);
|
margin-top: var(--dialog-surface-margin-top, auto);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -284,6 +323,7 @@ export class HaWaDialog extends LitElement {
|
|||||||
}
|
}
|
||||||
:host([flexcontent]) .body {
|
:host([flexcontent]) .body {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
@@ -312,6 +352,7 @@ declare global {
|
|||||||
|
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
opened: undefined;
|
opened: undefined;
|
||||||
|
"after-show": undefined;
|
||||||
closed: undefined;
|
closed: undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ class HaWebRtcPlayer extends LitElement {
|
|||||||
private _candidatesList: RTCIceCandidate[] = [];
|
private _candidatesList: RTCIceCandidate[] = [];
|
||||||
|
|
||||||
private _handleVisibilityChange = () => {
|
private _handleVisibilityChange = () => {
|
||||||
|
if (document.pictureInPictureElement) {
|
||||||
|
// video is playing in picture-in-picture mode, don't do anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
this._cleanUp();
|
this._cleanUp();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
removeLocalMedia,
|
removeLocalMedia,
|
||||||
} from "../../data/media_source";
|
} from "../../data/media_source";
|
||||||
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyleDialog } from "../../resources/styles";
|
import { haStyleDialog, haStyleDialogFixedTop } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-button";
|
import "../ha-button";
|
||||||
import "../ha-check-list-item";
|
import "../ha-check-list-item";
|
||||||
@@ -305,6 +305,7 @@ class DialogMediaManage extends LitElement {
|
|||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
|
haStyleDialogFixedTop,
|
||||||
css`
|
css`
|
||||||
ha-dialog {
|
ha-dialog {
|
||||||
--dialog-z-index: 9;
|
--dialog-z-index: 9;
|
||||||
@@ -314,9 +315,9 @@ class DialogMediaManage extends LitElement {
|
|||||||
@media (min-width: 800px) {
|
@media (min-width: 800px) {
|
||||||
ha-dialog {
|
ha-dialog {
|
||||||
--mdc-dialog-max-width: 800px;
|
--mdc-dialog-max-width: 800px;
|
||||||
--dialog-surface-position: fixed;
|
--mdc-dialog-max-height: calc(
|
||||||
--dialog-surface-top: 40px;
|
100vh - var(--ha-space-18) - var(--safe-area-inset-y)
|
||||||
--mdc-dialog-max-height: calc(100vh - 72px);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user