Skip to content

Commit

Permalink
Merge pull request #79 from taiga-family/selection
Browse files Browse the repository at this point in the history
  • Loading branch information
a1rat91 authored Oct 28, 2024
2 parents 3079e24 + 5475c0e commit 383be5a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[formControl]="form"
(connectionCreated)="onConnectionCreated($event)"
(connectionDeleted)="onConnectionDeleted($event)"
(connectionSelected)="onConnectionSelected($event)"
(nodeDeleted)="onNodeDeleted($event)"
(nodeMoved)="onNodeMoved($event)"
(nodeSelected)="onNodeSelected($event)"
Expand Down
4 changes: 4 additions & 0 deletions projects/demo/src/pages/examples/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export default class EditorComponent {
console.warn(event, 'onConnectionDeleted');
}

public onConnectionSelected(event: DfDataConnection): void {
console.warn(event, 'onConnectionSelected');
}

public onNodeMoved(event: DfEvent<DfDataNode>): void {
console.warn(event, 'onNodeMoved');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ export class ConnectionComponent {
private readonly connectionsService = inject(ConnectionsService);
private readonly coordinatesService = inject(CoordinatesService);
private readonly options = inject(DRAW_FLOW_OPTIONS);
private connectionSelected = false;
private selected = false;

@Input()
public connection!: DfDataConnection;

@Output()
protected readonly connectionDeleted = new EventEmitter<void>();

@Output()
protected readonly connectionSelected = new EventEmitter<void>();

@HostListener('document:keydown.delete', ['$event'])
@HostListener('document:keydown.backspace', ['$event'])
protected handleKeyboardEvent(event: KeyboardEvent): void {
if (!this.connectionSelected) {
if (!this.selected) {
return;
}

Expand Down Expand Up @@ -112,7 +115,11 @@ export class ConnectionComponent {
);

protected onSelectedChanged(selected: boolean): void {
this.connectionSelected = selected;
this.selected = selected;

if (selected) {
this.connectionSelected.emit();
}
}

private getConnectionPoint(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
data-not-selectable="true"
class="scene"
[style.height.px]="panSize"
[style.width.px]="panSize"
Expand All @@ -16,6 +17,7 @@
<df-connection
[connection]="connection"
(connectionDeleted)="onConnectionDeleted(connection)"
(connectionSelected)="connectionSelected.emit(connection)"
/>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class SceneComponent implements ControlValueAccessor, OnInit {
true,
);

@Output()
protected readonly connectionSelected = new EventEmitter<DfDataConnection>();

protected form: FormControl = this.fb.control({});

protected isConnectionCreating$ = this.draftConnectionService.isConnectionCreating$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class SelectableElementDirective {
protected onDocumentClick(targetElement: any): void {
const clickedInside = this.el.nativeElement.contains(targetElement);

if (targetElement.dataset.notSelectable) {
return;
}

this.setSelected(clickedInside);
}

Expand Down
1 change: 1 addition & 0 deletions projects/ng-draw-flow/src/lib/ng-draw-flow.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[formControl]="form"
(connectionCreated)="connectionCreated.emit($event)"
(connectionDeleted)="onConnectionDeleted($event)"
(connectionSelected)="connectionSelected.emit($event)"
(nodeDeleted)="nodeDeleted.emit($event)"
(nodeMoved)="nodeMoved.emit($event)"
(nodeSelected)="nodeSelected.emit($event)"
Expand Down
3 changes: 3 additions & 0 deletions projects/ng-draw-flow/src/lib/ng-draw-flow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export class NgDrawFlowComponent implements ControlValueAccessor, OnInit, OnDest
@Output()
protected readonly connectionDeleted = new EventEmitter<DfEvent<DfDataConnection>>();

@Output()
protected readonly connectionSelected = new EventEmitter<DfDataConnection>();

@Output()
protected readonly nodeSelected = new EventEmitter<DfDataNode>();

Expand Down

0 comments on commit 383be5a

Please sign in to comment.