fix: keep Symcon binding paths compact and allow direct unlinking
This commit is contained in:
1 parent
00fca890de
commit
b9a095bc6e
12 files changed
+131
-46
No files matched your search
@@ -140,7 +140,7 @@ export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: P
|
||||
// several sensors are averaged: once one is chosen, another can be added; "none" in a slot drops it
|
||||
const save = (list: (string | null)[]) => {
|
||||
const ids = list.filter((id): id is string => !!id && id !== "none");
|
||||
change(key, list[0] === "none" ? "none" : ids.length > 1 ? ids : (ids[0] ?? null));
|
||||
change(key, ids.length > 1 ? ids : (ids[0] ?? (list.includes("none") ? "none" : null)));
|
||||
};
|
||||
const real = picked[0] && picked[0] !== "none";
|
||||
const slots = real ? [...picked, null] : picked;
|
||||
|
||||
@@ -115,7 +115,7 @@ export class EntityPicker extends LitElement {
|
||||
if (this.objectTree !== undefined) return html`<nf-symcon-object-picker
|
||||
.objects=${this.objectTree} .options=${this.options} .fixed=${this.fixed} .value=${this.value}
|
||||
.disabled=${this.disabled} .placeholder=${this.placeholder}
|
||||
@change=${(event: CustomEvent<{ value: string }>) => { this.value = event.detail.value; }}
|
||||
@change=${(event: CustomEvent<{ value: string | null }>) => { this.value = event.detail.value; }}
|
||||
></nf-symcon-object-picker>`;
|
||||
const current = this.current;
|
||||
const hits = this._open ? this.hits : [];
|
||||
@@ -169,6 +169,8 @@ export class EntityPicker extends LitElement {
|
||||
:host {
|
||||
display: block;
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
|
||||
@@ -81,6 +81,18 @@ export class SymconObjectPicker extends LitElement {
|
||||
|
||||
private close(): void { this.dialog?.close(); }
|
||||
|
||||
private clear(event: Event): void {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (this.disabled) return;
|
||||
this.value = this.fixed.some((option) => option.id === "none") ? "none" : null;
|
||||
this._pending = this.value;
|
||||
this._selected = null;
|
||||
this._active = null;
|
||||
this.close();
|
||||
this.dispatchEvent(new CustomEvent("change", { detail: { value: this.value }, bubbles: true, composed: true }));
|
||||
}
|
||||
|
||||
private commit(): void {
|
||||
if (this.disabled || !this._pending || !this.allowed.has(this._pending)) return;
|
||||
this.value = this._pending;
|
||||
@@ -178,10 +190,11 @@ export class SymconObjectPicker extends LitElement {
|
||||
const pendingNode = (selectedObject && this.entityFor(selectedObject) === this._pending ? selectedObject : undefined) ?? this.variableNode(this._pending);
|
||||
const rows = symconTreeRows(this.tree, this._expanded, this._query);
|
||||
const active = rows.find((row) => row.node.object_id === this._active);
|
||||
return html`<button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
|
||||
<span><strong>${selectedNode?.name ?? current?.label ?? "Datenpunkt auswählen"}</strong>
|
||||
${selectedNode ? html`<small>${selectedNode.path}</small>` : nothing}</span><span aria-hidden="true">⌘</span>
|
||||
</button>
|
||||
const linked = !!this.value && !this.fixed.some((option) => option.id === this.value);
|
||||
return html`<div class="field"><button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
|
||||
<span class="trigger-text"><strong>${selectedNode?.name ?? current?.label ?? "Datenpunkt auswählen"}</strong>
|
||||
${selectedNode ? html`<small title=${selectedNode.path}>${selectedNode.path}</small>` : nothing}</span><span class="picker-icon" aria-hidden="true">⌘</span>
|
||||
</button>${linked ? html`<button class="clear" type="button" ?disabled=${this.disabled} aria-label="Verknüpfung entfernen" title="Verknüpfung entfernen" @click=${this.clear}>×</button>` : nothing}</div>
|
||||
<dialog aria-labelledby="picker-title" @click=${(event: MouseEvent) => {
|
||||
event.stopPropagation();
|
||||
if (event.target === this.dialog) {
|
||||
@@ -211,13 +224,17 @@ export class SymconObjectPicker extends LitElement {
|
||||
}
|
||||
|
||||
static styles = [tokens, css`
|
||||
:host { display:block; min-width:0; font:inherit; color:var(--nf-text); }
|
||||
:host { display:block; min-width:0; max-width:100%; font:inherit; color:var(--nf-text); }
|
||||
button,input { font:inherit; box-sizing:border-box; }
|
||||
button { cursor:pointer; color:var(--nf-text); border:1px solid var(--nf-line); background:var(--nf-chrome-solid); border-radius:9px; padding:8px 12px; }
|
||||
button:disabled { opacity:.45; cursor:default; }
|
||||
button:focus-visible,input:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
|
||||
.trigger { width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
|
||||
.trigger>span:first-child { min-width:0; }
|
||||
.field { display:flex; gap:6px; min-width:0; }
|
||||
.trigger { flex:1; min-width:0; width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
|
||||
.trigger-text { flex:1; min-width:0; overflow:hidden; }
|
||||
.trigger strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
||||
.picker-icon { flex:none; }
|
||||
.clear { flex:none; width:32px; padding:0; font-size:22px; }
|
||||
strong { font-weight:500; } small { display:block; color:var(--nf-muted); font-size:11px; }
|
||||
.trigger small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; }
|
||||
dialog { width:min(780px,calc(100vw - 32px)); max-width:none; height:min(690px,calc(100dvh - 32px)); max-height:none; box-sizing:border-box; padding:0; border:1px solid var(--nf-line); border-radius:16px; color:var(--nf-text); background:var(--nf-chrome-solid); box-shadow:0 24px 80px #0008; font:14px system-ui,sans-serif; }
|
||||
|
||||
Reference in new issue
Block a user