Skip to content

Commit

Permalink
revert to retrigger config changed to fix autofill on undefined selec…
Browse files Browse the repository at this point in the history
…tor value, but use a config-changed event listener that triggers once and hopefully won't cause an infinite loop
  • Loading branch information
Nerwyn committed Oct 15, 2024
1 parent 7cd4ba9 commit 0fd5e0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
4 changes: 2 additions & 2 deletions dist/universal-remote-card.min.js

Large diffs are not rendered by default.

36 changes: 15 additions & 21 deletions src/universal-remote-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ import {
Row,
} from './models/interfaces';
import { defaultIcons } from './models/maps';
import {
deepDel,
deepGet,
deepSet,
getDefaultActions,
mergeDeep,
} from './utils';
import { deepGet, deepSet, getDefaultActions, mergeDeep } from './utils';

export class UniversalRemoteCardEditor extends LitElement {
@property() hass!: HomeAssistant;
Expand Down Expand Up @@ -391,22 +385,13 @@ export class UniversalRemoteCardEditor extends LitElement {
switch (this.baseTabIndex) {
case 3:
case 2:
if (value == undefined) {
const entry = deepDel(
this.entryChanged(
deepSet(
structuredClone(this.activeEntry) as object,
key,
) as IElementConfig;
console.log(entry);
this.entryChanged(entry);
} else {
this.entryChanged(
deepSet(
structuredClone(this.activeEntry) as object,
key,
value,
) as IElementConfig,
);
}
value,
) as IElementConfig,
);
break;
default:
this.configChanged({
Expand All @@ -415,6 +400,15 @@ export class UniversalRemoteCardEditor extends LitElement {
});
break;
}
if (value == undefined) {
this.addEventListener(
'config-changed',
() => {
this.configChanged(this.config);
},
{ once: true },
);
}
}

handleLayoutActionListItemDragStart(e: DragEvent) {
Expand Down
22 changes: 0 additions & 22 deletions src/utils/deepKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,6 @@ export function deepSet<T extends object>(
return obj;
}

export function deepDel<T extends object>(obj: T, key: string): T {
const keys = key.split('.');
if (keys.length == 1) {
delete obj[keys[0] as keyof object];
} else {
if (
!(keys[0] in obj) ||
!(typeof obj[keys[0] as keyof object] == 'object')
) {
if (/^-?\d+$/.test(keys[1])) {
obj[keys[0] as keyof object] = new Array(
parseInt(keys[1]),
) as never;
} else {
obj[keys[0] as keyof object] = {} as never;
}
}
deepDel(obj[keys[0] as keyof object], keys.splice(1).join('.'));
}
return obj;
}

export function mergeDeep<T extends object>(target: T, ...sources: [T]): T {
function isObject(item: object) {
return item && typeof item === 'object' && !Array.isArray(item);
Expand Down

0 comments on commit 0fd5e0d

Please sign in to comment.