@inradius/solid-wc-hass-mixin 1.0.0 → 1.0.2

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  # @inradius/solid-wc-hass-mixin
2
- ![npm version](https://img.shields.io/npm/v/@inradius/solid-wc-hass-mixin) ![license](https://img.shields.io/npm/l/@inradius/solid-wc-hass-mixin)
2
+ ![npm version](https://img.shields.io/npm/v/@inradius/solid-wc-hass-mixin) ![CI Action](https://github.com/inradius/solid-wc-utils-monorepo/actions/workflows/ci.yml/badge.svg) ![license](https://img.shields.io/npm/l/@inradius/solid-wc-hass-mixin)
3
3
 
4
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
5
 
@@ -59,4 +59,4 @@ The `withHomeAssistant` function accepts an options object:
59
59
  3. Global Registry: Adds your card to `window.customCards` so it appears in the "Add Card" dialog in the Lovelace UI.
60
60
 
61
61
  ## License
62
- MIT © Travis
62
+ MIT
package/dist/index.cjs CHANGED
@@ -1 +1,25 @@
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;
1
+ "use strict";
2
+ const UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
3
+ const sanitize = (obj) => Object.fromEntries(
4
+ Object.entries(obj).filter(([key]) => !UNSAFE_KEYS.has(key))
5
+ );
6
+ const withHomeAssistant = (options) => {
7
+ const { cardSize = 3, customCard, defaultConfig = {} } = options;
8
+ return (ElementType) => {
9
+ const proto = ElementType.prototype;
10
+ const win = window;
11
+ win.customCards = win.customCards || [];
12
+ proto.setConfig = function(config) {
13
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
14
+ throw new Error("Invalid configuration");
15
+ }
16
+ this.config = { ...sanitize(defaultConfig), ...sanitize(config) };
17
+ };
18
+ proto.getCardSize = function() {
19
+ return cardSize;
20
+ };
21
+ win.customCards.push(sanitize(customCard));
22
+ return ElementType;
23
+ };
24
+ };
25
+ module.exports = withHomeAssistant;
package/dist/index.js CHANGED
@@ -1,18 +1,26 @@
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))
1
+ const UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
2
+ const sanitize = (obj) => Object.fromEntries(
3
+ Object.entries(obj).filter(([key]) => !UNSAFE_KEYS.has(key))
4
+ );
5
+ const withHomeAssistant = (options) => {
6
+ const { cardSize = 3, customCard, defaultConfig = {} } = options;
7
+ return (ElementType) => {
8
+ const proto = ElementType.prototype;
9
+ const win = window;
10
+ win.customCards = win.customCards || [];
11
+ proto.setConfig = function(config) {
12
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
9
13
  throw new Error("Invalid configuration");
10
- this.config = { ...n(a), ...n(t) };
11
- }, i.getCardSize = function() {
12
- return r;
13
- }, s.customCards.push(n(c)), e;
14
+ }
15
+ this.config = { ...sanitize(defaultConfig), ...sanitize(config) };
16
+ };
17
+ proto.getCardSize = function() {
18
+ return cardSize;
19
+ };
20
+ win.customCards.push(sanitize(customCard));
21
+ return ElementType;
14
22
  };
15
23
  };
16
24
  export {
17
- d as default
25
+ withHomeAssistant as default
18
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inradius/solid-wc-hass-mixin",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Travis Stroud <travis.unfasten577@travisstroud.me>",
6
6
  "description": "A Solid.js Home Assistant web component mixin.",
@@ -41,7 +41,7 @@
41
41
  "vite": "^5.4.0",
42
42
  "vite-plugin-dts": "^4.0.0",
43
43
  "vitest": "^2.1.0",
44
- "@inradius/solid-wc-utils-config": "0.0.0"
44
+ "@inradius/solid-wc-utils-config": "0.1.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "component-register": "^0.8.0"