Add some decorators (#1784)

* Add some decorators

* Disable sort keys

* Add babel plugins

* Update typescript to 7.1
This commit is contained in:
Paulus Schoutsen 2018-10-16 23:30:13 +02:00 committed by GitHub
parent af81ede100
commit a7684d7206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 395 additions and 395 deletions

View File

@ -20,6 +20,9 @@ module.exports.babelLoaderConfig = ({ latestBuild }) => {
"@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-object-rest-spread",
{ loose: true, useBuiltIns: true }, { loose: true, useBuiltIns: true },
], ],
// Used for decorators in typescript
["@babel/plugin-proposal-decorators", { legacy: true }],
"@babel/plugin-proposal-class-properties",
// Only support the syntax, Webpack will handle it. // Only support the syntax, Webpack will handle it.
"@babel/syntax-dynamic-import", "@babel/syntax-dynamic-import",
[ [

View File

@ -91,7 +91,8 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.1.2", "@babel/core": "^7.1.2",
"@babel/plugin-external-helpers": "^7.0.0", "@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-proposal-class-properties": "7.0.0", "@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0", "@babel/plugin-transform-react-jsx": "^7.0.0",

View File

@ -11,13 +11,13 @@ import {
LocalizeMixin, LocalizeMixin,
} from "./localize-base-mixin"; } from "./localize-base-mixin";
export const HassLocalizeLitMixin = ( export const HassLocalizeLitMixin = <T extends LitElement>(
superClass: Constructor<LitElement> superClass: Constructor<T>
): Constructor<LitElement & LocalizeMixin> => ): Constructor<T & LocalizeMixin> =>
// @ts-ignore // @ts-ignore
class extends LocalizeBaseMixin(superClass) { class extends LocalizeBaseMixin(superClass) {
protected hass?: HomeAssistant; protected hass?: HomeAssistant;
protected localize?: LocalizeFunc; protected localize!: LocalizeFunc;
static get properties(): PropertyDeclarations { static get properties(): PropertyDeclarations {
return { return {

View File

@ -1,4 +1,10 @@
import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element"; import {
html,
LitElement,
property,
customElement,
eventOptions,
} from "@polymer/lit-element";
import { fireEvent } from "../../../common/dom/fire_event.js"; import { fireEvent } from "../../../common/dom/fire_event.js";
import "../../../components/ha-card.js"; import "../../../components/ha-card.js";
@ -22,15 +28,13 @@ interface Config extends LovelaceConfig {
service_data?: object; service_data?: object;
} }
class HuiEntityButtonCard extends HassLocalizeLitMixin(LitElement) @customElement("hui-entity-button-card" as any)
export class HuiEntityButtonCard extends HassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
static get properties(): PropertyDeclarations { @property()
return {
hass: {}
};
}
protected hass?: HomeAssistant; protected hass?: HomeAssistant;
@property()
protected config?: Config; protected config?: Config;
public getCardSize() { public getCardSize() {
@ -60,18 +64,26 @@ implements LovelaceCard {
<ha-card @click="${this.handleClick}"> <ha-card @click="${this.handleClick}">
${ ${
!stateObj !stateObj
? html`<div class="not-found">Entity not available: ${this.config.entity}</div>` ? html`<div class="not-found">Entity not available: ${
this.config.entity
}</div>`
: html` : html`
<paper-button> <paper-button>
<div> <div>
<ha-icon <ha-icon
data-domain="${computeStateDomain(stateObj)}" data-domain="${computeStateDomain(stateObj)}"
data-state="${stateObj.state}" data-state="${stateObj.state}"
.icon="${this.config.icon ? this.config.icon : stateIcon(stateObj)}" .icon="${
style="${styleMap({filter: this._computeBrightness(stateObj), color: this._computeColor(stateObj)})}" this.config.icon ? this.config.icon : stateIcon(stateObj)
}"
style="${styleMap({
filter: this._computeBrightness(stateObj),
color: this._computeColor(stateObj),
})}"
></ha-icon> ></ha-icon>
<span> <span>
${this.config.name ${
this.config.name
? this.config.name ? this.config.name
: computeStateName(stateObj) : computeStateName(stateObj)
} }
@ -134,16 +146,17 @@ implements LovelaceCard {
private _computeColor(stateObj) { private _computeColor(stateObj) {
if (!stateObj.attributes.hs_color) { if (!stateObj.attributes.hs_color) {
return ''; return "";
} }
const hue = stateObj.attributes.hs_color[0]; const hue = stateObj.attributes.hs_color[0];
const sat = stateObj.attributes.hs_color[1]; const sat = stateObj.attributes.hs_color[1];
if (sat <= 10) { if (sat <= 10) {
return ''; return "";
} }
return `hsl(${hue}, 100%, ${100 - sat / 2}%)`; return `hsl(${hue}, 100%, ${100 - sat / 2}%)`;
} }
@eventOptions({ passive: true })
private handleClick() { private handleClick() {
const config = this.config; const config = this.config;
if (!config) { if (!config) {
@ -178,5 +191,3 @@ declare global {
"hui-entity-button-card": HuiEntityButtonCard; "hui-entity-button-card": HuiEntityButtonCard;
} }
} }
customElements.define("hui-entity-button-card", HuiEntityButtonCard);

View File

@ -1,4 +1,10 @@
import { html, LitElement, PropertyDeclarations } from "@polymer/lit-element"; import {
html,
LitElement,
customElement,
property,
eventOptions,
} from "@polymer/lit-element";
import { classMap } from "lit-html/directives/classMap.js"; import { classMap } from "lit-html/directives/classMap.js";
import { repeat } from "lit-html/directives/repeat"; import { repeat } from "lit-html/directives/repeat";
@ -35,15 +41,15 @@ interface Config extends LovelaceConfig {
entities: EntityConfig[]; entities: EntityConfig[];
} }
class HuiGlanceCard extends HassLocalizeLitMixin(LitElement) @customElement("hui-glance-card" as any)
export class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
implements LovelaceCard { implements LovelaceCard {
static get properties(): PropertyDeclarations { @property()
return {
hass: {},
};
}
protected hass?: HomeAssistant; protected hass?: HomeAssistant;
@property()
protected config?: Config; protected config?: Config;
protected configEntities?: EntityConfig[]; protected configEntities?: EntityConfig[];
public getCardSize() { public getCardSize() {
@ -179,6 +185,7 @@ class HuiGlanceCard extends HassLocalizeLitMixin(LitElement)
`; `;
} }
@eventOptions({ passive: true })
private handleClick(ev: MouseEvent) { private handleClick(ev: MouseEvent) {
const config = (ev.currentTarget as any).entityConf as EntityConfig; const config = (ev.currentTarget as any).entityConf as EntityConfig;
const entityId = config.entity; const entityId = config.entity;
@ -203,5 +210,3 @@ declare global {
"hui-glance-card": HuiGlanceCard; "hui-glance-card": HuiGlanceCard;
} }
} }
customElements.define("hui-glance-card", HuiGlanceCard);

View File

@ -3,6 +3,7 @@
"rules": { "rules": {
"interface-name": false, "interface-name": false,
"no-submodule-imports": false, "no-submodule-imports": false,
"ordered-imports": false "ordered-imports": false,
"object-literal-sort-keys": false
} }
} }

683
yarn.lock

File diff suppressed because it is too large Load Diff