humainflow-web/src/app/shared/nodes/output/output-node.component.ts

51 lines
1.1 KiB
TypeScript

import {
Component,
Input,
HostBinding,
ChangeDetectorRef,
OnChanges
} from "@angular/core";
import { ClassicPreset } from "rete";
import { CommonModule, KeyValue } from "@angular/common";
import { ReteModule } from "rete-angular-plugin/21";
@Component({
templateUrl: "./output-node.component.html",
styleUrls: ["./output-node.component.scss"],
imports: [CommonModule, ReteModule],
host: {
"data-testid": "output-node"
}
})
export class OutputNodeComponent implements OnChanges {
@Input() data!: ClassicPreset.Node;
@Input() emit!: (data: any) => void;
@Input() rendered!: () => void;
seed = 0;
@HostBinding("class.selected") get selected() {
return this.data.selected;
}
constructor(private cdr: ChangeDetectorRef) {
this.cdr.detach();
}
ngOnChanges(): void {
this.cdr.detectChanges();
requestAnimationFrame(() => this.rendered());
this.seed++; // force render sockets
}
sortByIndex<
N extends object,
T extends KeyValue<string, N & { index?: number }>
>(a: T, b: T) {
const ai = a.value.index || 0;
const bi = b.value.index || 0;
return ai - bi;
}
}