{
if (!this.isOpen) {
this.highlightConnection();
}
}}
@mouseleave=${() => {
if (!this.isOpen) {
this.unhighlightConnection();
}
}}
?disabled=${this.disabled}
>
this.searchElement.focus()}
@keydown=${this.handleKeydown}
clearable
class="searchInput"
>
${dataFiltered.length === 0
? html`No nodes found`
: html`
${hasNodesOfClass("page") || hasNodesOfClass("origin")
? html`
${options("page")} ${options("origin")}
${hasNodesOfClass("popup") || hasNodesOfClass("branch")
? html``
: ""}
`
: ""}
${hasNodesOfClass("popup")
? html`
${options("popup")}
${hasNodesOfClass("branch")
? html``
: ""}
`
: ""}
${hasNodesOfClass("branch")
? html`
${options("branch")}
`
: ""}
No nodes found
`}
`;
}
/*
*/
private handleSearch(event: Event) {
const searchTerm = (event.target as HTMLInputElement).value.toLowerCase();
this.searchTerm = searchTerm;
this.shadowRoot.querySelectorAll("sl-option").forEach((option) => {
const title = option.textContent.toLowerCase();
option.classList.toggle(
"node-option-visible",
title.includes(searchTerm)
);
option.classList.toggle(
"node-option-hidden",
!title.includes(searchTerm)
);
});
this._toggleDividers(
"page",
this.hasVisibleNodesOfClass("page") ||
this.hasVisibleNodesOfClass("origin")
);
this._toggleDividers("popup", this.hasVisibleNodesOfClass("popup"));
this._toggleDividers("branch", this.hasVisibleNodesOfClass("branch"));
(
this.shadowRoot.querySelector("#no-nodes-found") as HTMLElement
).style.display = this._hasNoVisibleNodes() ? "block" : "none";
}
/*
*/
private _toggleDividers(dividerId: string, shouldDisplay: boolean) {
const displayStyle = shouldDisplay ? "flex" : "none";
this.shadowRoot
.querySelectorAll(`#divider-${dividerId}`)
.forEach((element) => {
(element as HTMLElement).style.display = displayStyle;
});
}
/*
*/
private _hasNoVisibleNodes() {
return !(
this.hasVisibleNodesOfClass("page") ||
this.hasVisibleNodesOfClass("origin") ||
this.hasVisibleNodesOfClass("popup") ||
this.hasVisibleNodesOfClass("branch")
);
}
/*
*/
private hasVisibleNodesOfClass(nodeClass: string) {
return (
this.shadowRoot.querySelectorAll(`.node-option-visible.${nodeClass}`)
.length > 0
);
}
/*
*/
private handleKeydown(event: KeyboardEvent) {
this.searchElement.focus();
event.stopPropagation();
}
/*
*/
private _handleUserInputTargetPage(event: Event) {
if (
event.target instanceof HTMLElement &&
event.target.tagName.toLowerCase() === "sl-select"
) {
const selectedValue = (event.target as SlSelect).value;
const connections =
this.editorStore.selectedNode?.outputs?.[this.outputClass]?.connections;
//this.hasValue = selectedValue !== "";
if (connections?.[0]?.node === undefined && selectedValue) {
const event = new CustomEvent("createConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId: selectedValue,
outputClass: this.outputClass,
inputClass: "input_1",
},
bubbles: true,
composed: true,
});
this.dispatchEvent(event);
}
//
else if (connections?.[0]?.node !== undefined && selectedValue) {
const removeEvent = new CustomEvent("deleteConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId: connections[0].node,
outputClass: this.outputClass,
inputClass: "input_1",
},
bubbles: true,
composed: true,
});
this.dispatchEvent(removeEvent);
const createEvent = new CustomEvent("createConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId: selectedValue,
outputClass: this.outputClass,
inputClass: "input_1",
},
bubbles: true,
composed: true,
});
this.dispatchEvent(createEvent);
}
//
else if (!selectedValue) {
const removeEvent = new CustomEvent("deleteConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId: connections?.[0]?.node,
outputClass: this.outputClass,
inputClass: "input_1",
},
bubbles: true,
composed: true,
});
this.dispatchEvent(removeEvent);
}
}
this.requestUpdate();
}
/*
*/
private onOpenChange(isOpen: boolean) {
this.isOpen = isOpen;
if (isOpen) {
this.unhighlightConnection();
this.dispatchEvent(
new CustomEvent("highlightOutput", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
outputClass: this.outputClass,
},
bubbles: true,
composed: true,
})
);
} else {
this.unhighlightConnection();
}
}
/*
*/
private highlightConnection() {
this.dispatchEvent(
new CustomEvent("highlightConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId:
this.editorStore.selectedNode?.outputs?.[this.outputClass]
?.connections?.[0]?.node,
outputClass: this.outputClass,
inputClass: "input_1",
highlightButton: true,
},
bubbles: true,
composed: true,
})
);
}
/*
*/
private unhighlightConnection() {
this.dispatchEvent(
new CustomEvent("unhighlightConnection", {
detail: {
outputNodeId: this.editorStore.selectedNode.id,
inputNodeId:
this.editorStore.selectedNode?.outputs?.[this.outputClass]
?.connections?.[0]?.node,
outputClass: this.outputClass,
inputClass: "input_1",
highlightButton: true,
},
bubbles: true,
composed: true,
})
);
}
/*
*/
private highlightNode(nodeId) {
this.dispatchEvent(
new CustomEvent("highlightNode", {
detail: {
nodeId: nodeId,
},
bubbles: true,
composed: true,
})
);
}
/*
*/
private unhighlightNode(nodeId) {
this.dispatchEvent(
new CustomEvent("unhighlightNode", {
detail: {
nodeId: nodeId,
},
bubbles: true,
composed: true,
})
);
}
}