@inradius/solid-wc-hass-mixin 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -61
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
# @inradius/solid-wc-hass-mixin
|
|
2
|
-
 
|
|
3
|
-
|
|
4
|
-
A lightweight mixin for [component-register](https://www.npmjs.com/package/component-register) that streamlines the creation of Home Assistant Custom Cards using Solid.js.
|
|
5
|
-
|
|
6
|
-
This mixin automatically handles the boilerplate required by Home Assistant, including `setConfig`, card registration in the global window object, and the `getCardSize` method.
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
- **Automatic Registration:** Automatically pushes your card configuration to the Home Assistant `customCards` registry.
|
|
10
|
-
- **Config Handling:** Implements `setConfig` and merges your `defaultConfig` with user-provided settings.
|
|
11
|
-
- **TypeScript Ready:** Full type safety for Home Assistant card configurations.
|
|
12
|
-
- **Clean Integration:** Designed to work seamlessly with `compose` and `register`.
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install @inradius/solid-wc-hass-mixin component-register
|
|
16
|
-
# or
|
|
17
|
-
pnpm add @inradius/solid-wc-hass-mixin component-register
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
Use `withHomeAssistant` within your `compose` pipeline. It should wrap your final component ***before*** registration.
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import { register, compose, withSolid } from 'component-register';
|
|
25
|
-
import withHomeAssistant from '@inradius/solid-wc-hass-mixin';
|
|
26
|
-
import { MyApp } from './MyApp';
|
|
27
|
-
|
|
28
|
-
compose(
|
|
29
|
-
withHomeAssistant({
|
|
30
|
-
defaultConfig: {
|
|
31
|
-
name: 'My Card',
|
|
32
|
-
layout: 'vertical',
|
|
33
|
-
},
|
|
34
|
-
customCard: {
|
|
35
|
-
type: 'my-custom-card',
|
|
36
|
-
name: 'My Custom Card',
|
|
37
|
-
description: 'A beautiful Solid.js card for Home Assistant.',
|
|
38
|
-
preview: true
|
|
39
|
-
},
|
|
40
|
-
cardSize: 3
|
|
41
|
-
}),
|
|
42
|
-
register('my-custom-card'),
|
|
43
|
-
withSolid
|
|
44
|
-
)(MyApp);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Options
|
|
48
|
-
The `withHomeAssistant` function accepts an options object:
|
|
49
|
-
|
|
50
|
-
| Property | Type | Default | Description |
|
|
51
|
-
| --- | --- | --- | --- |
|
|
52
|
-
| customCard | CustomCardEntry | Required | The metadata used by the Home Assistant UI picker. |
|
|
53
|
-
| defaultConfig | Record<string, unknown> | {} | Default values for your card's YAML configuration. |
|
|
54
|
-
| cardSize | number | 3 | The height of the card in the Home Assistant grid. |
|
|
55
|
-
|
|
56
|
-
## How it works
|
|
57
|
-
1. `setConfig(config)`: Home Assistant calls this when the UI editor changes. This mixin ensures a valid config is provided and attaches it to `this.config`.
|
|
58
|
-
2. `getCardSize()`: Returns the specified grid height for the Home Assistant dashboard.
|
|
59
|
-
3. Global Registry: Adds your card to `window.customCards` so it appears in the "Add Card" dialog in the Lovelace UI.
|
|
60
|
-
|
|
61
|
-
## License
|
|
1
|
+
# @inradius/solid-wc-hass-mixin
|
|
2
|
+
 
|
|
3
|
+
|
|
4
|
+
A lightweight mixin for [component-register](https://www.npmjs.com/package/component-register) that streamlines the creation of Home Assistant Custom Cards using Solid.js.
|
|
5
|
+
|
|
6
|
+
This mixin automatically handles the boilerplate required by Home Assistant, including `setConfig`, card registration in the global window object, and the `getCardSize` method.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- **Automatic Registration:** Automatically pushes your card configuration to the Home Assistant `customCards` registry.
|
|
10
|
+
- **Config Handling:** Implements `setConfig` and merges your `defaultConfig` with user-provided settings.
|
|
11
|
+
- **TypeScript Ready:** Full type safety for Home Assistant card configurations.
|
|
12
|
+
- **Clean Integration:** Designed to work seamlessly with `compose` and `register`.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @inradius/solid-wc-hass-mixin component-register
|
|
16
|
+
# or
|
|
17
|
+
pnpm add @inradius/solid-wc-hass-mixin component-register
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
Use `withHomeAssistant` within your `compose` pipeline. It should wrap your final component ***before*** registration.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { register, compose, withSolid } from 'component-register';
|
|
25
|
+
import withHomeAssistant from '@inradius/solid-wc-hass-mixin';
|
|
26
|
+
import { MyApp } from './MyApp';
|
|
27
|
+
|
|
28
|
+
compose(
|
|
29
|
+
withHomeAssistant({
|
|
30
|
+
defaultConfig: {
|
|
31
|
+
name: 'My Card',
|
|
32
|
+
layout: 'vertical',
|
|
33
|
+
},
|
|
34
|
+
customCard: {
|
|
35
|
+
type: 'my-custom-card',
|
|
36
|
+
name: 'My Custom Card',
|
|
37
|
+
description: 'A beautiful Solid.js card for Home Assistant.',
|
|
38
|
+
preview: true
|
|
39
|
+
},
|
|
40
|
+
cardSize: 3
|
|
41
|
+
}),
|
|
42
|
+
register('my-custom-card'),
|
|
43
|
+
withSolid
|
|
44
|
+
)(MyApp);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Options
|
|
48
|
+
The `withHomeAssistant` function accepts an options object:
|
|
49
|
+
|
|
50
|
+
| Property | Type | Default | Description |
|
|
51
|
+
| --- | --- | --- | --- |
|
|
52
|
+
| customCard | CustomCardEntry | Required | The metadata used by the Home Assistant UI picker. |
|
|
53
|
+
| defaultConfig | Record<string, unknown> | {} | Default values for your card's YAML configuration. |
|
|
54
|
+
| cardSize | number | 3 | The height of the card in the Home Assistant grid. |
|
|
55
|
+
|
|
56
|
+
## How it works
|
|
57
|
+
1. `setConfig(config)`: Home Assistant calls this when the UI editor changes. This mixin ensures a valid config is provided and attaches it to `this.config`.
|
|
58
|
+
2. `getCardSize()`: Returns the specified grid height for the Home Assistant dashboard.
|
|
59
|
+
3. Global Registry: Adds your card to `window.customCards` so it appears in the "Add Card" dialog in the Lovelace UI.
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
62
|
MIT © Travis
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const u=new Set(["__proto__","constructor","prototype"]),n=r=>Object.fromEntries(Object.entries(r).filter(([o])=>!u.has(o))),d=r=>{const{cardSize:o=3,customCard:c,defaultConfig:a={}}=r;return e=>{const i=e.prototype,s=window;return s.customCards=s.customCards||[],i.setConfig=function(t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Invalid configuration");this.config={...n(a),...n(t)}},i.getCardSize=function(){return o},s.customCards.push(n(c)),e}};module.exports=d;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { ComponentType } from 'component-register';
|
|
2
|
-
|
|
3
|
-
type: string;
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface CustomCardEntry {
|
|
7
|
-
type: string;
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
preview?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface HomeAssistantOptions {
|
|
13
|
-
defaultConfig?: Record<string, unknown>;
|
|
14
|
-
customCard: CustomCardEntry;
|
|
15
|
-
cardSize?: number;
|
|
16
|
-
}
|
|
2
|
+
import { HomeAssistantOptions } from './types';
|
|
17
3
|
declare const withHomeAssistant: (options: HomeAssistantOptions) => <T>(ElementType: ComponentType<T>) => ComponentType<T>;
|
|
18
4
|
export default withHomeAssistant;
|
|
19
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAEL,oBAAoB,EAErB,MAAM,SAAS,CAAC;AASjB,QAAA,MAAM,iBAAiB,GAAI,SAAS,oBAAoB,MAG9C,CAAC,EAAE,aAAa,aAAa,CAAC,CAAC,CAAC,KAAG,aAAa,CAAC,CAAC,CAqB3D,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const u = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]), n = (o) => Object.fromEntries(
|
|
2
|
+
Object.entries(o).filter(([r]) => !u.has(r))
|
|
3
|
+
), d = (o) => {
|
|
4
|
+
const { cardSize: r = 3, customCard: c, defaultConfig: a = {} } = o;
|
|
5
|
+
return (e) => {
|
|
6
|
+
const i = e.prototype, s = window;
|
|
7
|
+
return s.customCards = s.customCards || [], i.setConfig = function(t) {
|
|
8
|
+
if (!t || typeof t != "object" || Array.isArray(t))
|
|
7
9
|
throw new Error("Invalid configuration");
|
|
8
|
-
this.config = { ...
|
|
9
|
-
},
|
|
10
|
-
return
|
|
11
|
-
},
|
|
10
|
+
this.config = { ...n(a), ...n(t) };
|
|
11
|
+
}, i.getCardSize = function() {
|
|
12
|
+
return r;
|
|
13
|
+
}, s.customCards.push(n(c)), e;
|
|
12
14
|
};
|
|
13
15
|
};
|
|
14
16
|
export {
|
|
15
|
-
|
|
17
|
+
d as default
|
|
16
18
|
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface CustomCardEntry {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
description: string;
|
|
4
|
+
name: string;
|
|
5
|
+
preview?: boolean;
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HomeAssistantElement extends HTMLElement {
|
|
9
|
+
config?: LovelaceCardConfig;
|
|
10
|
+
getCardSize(): number;
|
|
11
|
+
setConfig(config: LovelaceCardConfig): void;
|
|
12
|
+
}
|
|
13
|
+
export interface HomeAssistantOptions {
|
|
14
|
+
cardSize?: number;
|
|
15
|
+
customCard: CustomCardEntry;
|
|
16
|
+
defaultConfig?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface LovelaceCardConfig {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,WAAW,IAAI,MAAM,CAAC;IACtB,SAAS,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,eAAe,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inradius/solid-wc-hass-mixin",
|
|
3
3
|
"author": "Travis Stroud <travis.unfasten577@travisstroud.me>",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "A Solid.js Home Assistant web component mixin.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/inradius/solid-wc-utils-monorepo.git",
|
|
9
9
|
"directory": "packages/solid-wc-hass-mixin"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://github.com/inradius/solid-wc-utils-monorepo/tree/main/packages/solid-wc-hass-mixin#readme",
|
|
11
12
|
"type": "module",
|
|
12
13
|
"main": "./dist/index.cjs",
|
|
13
14
|
"module": "./dist/index.js",
|
|
@@ -23,9 +24,14 @@
|
|
|
23
24
|
"dist"
|
|
24
25
|
],
|
|
25
26
|
"devDependencies": {
|
|
27
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
28
|
+
"@vitest/ui": "^2.1.0",
|
|
29
|
+
"jsdom": "^28.1.0",
|
|
26
30
|
"rimraf": "^6.0.0",
|
|
27
31
|
"vite": "^5.4.0",
|
|
28
|
-
"vite-plugin-dts": "^4.0.0"
|
|
32
|
+
"vite-plugin-dts": "^4.0.0",
|
|
33
|
+
"vitest": "^2.1.0",
|
|
34
|
+
"@inradius/solid-wc-utils-config": "0.0.0"
|
|
29
35
|
},
|
|
30
36
|
"peerDependencies": {
|
|
31
37
|
"component-register": "^0.8.0"
|
|
@@ -34,6 +40,10 @@
|
|
|
34
40
|
"scripts": {
|
|
35
41
|
"build": "vite build",
|
|
36
42
|
"dev": "vite build --watch",
|
|
37
|
-
"clean": "rimraf dist"
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"lint": "eslint src",
|
|
45
|
+
"lint:fix": "eslint src --fix",
|
|
46
|
+
"test": "vitest run --coverage",
|
|
47
|
+
"test:watch": "vitest"
|
|
38
48
|
}
|
|
39
49
|
}
|