Skip to content

Commit

Permalink
feat: Added group to fSelectionChange event
Browse files Browse the repository at this point in the history
  • Loading branch information
siarheihuzarevich committed Jan 11, 2025
1 parent 9a15216 commit 58850bb
Show file tree
Hide file tree
Showing 90 changed files with 516 additions and 449 deletions.
2 changes: 1 addition & 1 deletion projects/f-flow/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foblex/flow",
"version": "17.0.4",
"version": "17.0.5",
"description": "An Angular library designed to simplify the creation and manipulation of dynamic flow. Provides components for flows, nodes, and connections, automating node manipulation and inter-node connections.",
"main": "index.js",
"types": "index.d.ts",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { TestBed } from '@angular/core/testing';
import { GetConnectionLineExecution } from './get-connection-line.execution';
import { GetConnectionLineRequest } from './get-connection-line.request';
import { EFConnectionBehavior } from '../../f-connection';
import { EFConnectableSide } from '../../f-connectors';
import { setupTestModule } from '../test-setup';
import { CalculateConnectionLineByBehaviorExecution } from './calculate-connection-line-by-behavior.execution';
import { CalculateConnectionLineByBehaviorRequest } from './calculate-connection-line-by-behavior.request';
import { EFConnectionBehavior } from '../../../f-connection';
import { EFConnectableSide } from '../../../f-connectors';
import { setupTestModule } from '../../test-setup';
import { FMediator } from '@foblex/mediator';
import { RoundedRect, ILine, PointExtensions } from '@foblex/2d';

describe('GetConnectionLineExecution', () => {
describe('CalculateConnectionLineByBehaviorExecution', () => {
let fMediator: FMediator;

beforeEach(() => {
setupTestModule([ GetConnectionLineExecution ]);
setupTestModule([ CalculateConnectionLineByBehaviorExecution ]);
fMediator = TestBed.inject(FMediator) as jasmine.SpyObj<FMediator>;
});

it('should handle floating behavior correctly', () => {
const result: ILine = fMediator.send(new GetConnectionLineRequest(
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand All @@ -35,7 +35,7 @@ describe('GetConnectionLineExecution', () => {
});

it('should handle fixed center behavior correctly', () => {
const result: ILine = fMediator.send(new GetConnectionLineRequest(
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand All @@ -54,7 +54,7 @@ describe('GetConnectionLineExecution', () => {
});

it('should handle fixed outbound behavior correctly', () => {
const result: ILine = fMediator.send(new GetConnectionLineRequest(
const result: ILine = fMediator.send(new CalculateConnectionLineByBehaviorRequest(
RoundedRect.fromRect({ x: 0, y: 0, width: 100, height: 100, gravityCenter: PointExtensions.initialize(50, 50) }),
RoundedRect.fromRect({
x: 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CalculateConnectionLineByBehaviorRequest } from './calculate-connection-line-by-behavior.request';
import { Injectable } from '@angular/core';
import { EFConnectionBehavior } from '../../../f-connection';
import { FExecutionRegister, IExecution } from '@foblex/mediator';
import { ILine } from '@foblex/2d';
import { floatingBehavior } from './floating-behavior';
import { fixedCenterBehavior } from './fixed-center-behavior';
import { fixedOutboundBehavior } from './fixed-outbound-behavior';

@Injectable()
@FExecutionRegister(CalculateConnectionLineByBehaviorRequest)
export class CalculateConnectionLineByBehaviorExecution implements IExecution<CalculateConnectionLineByBehaviorRequest, ILine> {

private _handlers = {

[ EFConnectionBehavior.FLOATING.toString() ]: floatingBehavior,

[ EFConnectionBehavior.FIXED_CENTER.toString() ]: fixedCenterBehavior,

[ EFConnectionBehavior.FIXED.toString() ]: fixedOutboundBehavior,
}

public handle(payload: CalculateConnectionLineByBehaviorRequest): ILine {
return this._handlers[ payload.behavior ](payload);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { EFConnectionBehavior } from '../../../f-connection';
import { EFConnectableSide } from '../../../f-connectors';
import { IRoundedRect } from '@foblex/2d';

export class CalculateConnectionLineByBehaviorRequest {

constructor(
public outputRect: IRoundedRect,
public inputRect: IRoundedRect,
public behavior: EFConnectionBehavior | string,
public outputSide: EFConnectableSide,
public inputSide: EFConnectableSide,
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ILine, Line } from '@foblex/2d';
import { CalculateConnectionLineByBehaviorRequest } from './calculate-connection-line-by-behavior.request';

export function fixedCenterBehavior(payload: CalculateConnectionLineByBehaviorRequest): ILine {
return new Line(
payload.outputRect.gravityCenter,
payload.inputRect.gravityCenter
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ILine, IPoint, IRect, Line, Point } from '@foblex/2d';
import { CalculateConnectionLineByBehaviorRequest } from './calculate-connection-line-by-behavior.request';
import { EFConnectableSide } from '../../../f-connectors';

export function fixedOutboundBehavior(payload: CalculateConnectionLineByBehaviorRequest): ILine {
return new Line(
positions[ payload.outputSide === EFConnectableSide.AUTO ? EFConnectableSide.BOTTOM : payload.outputSide ](payload.outputRect),
positions[ payload.inputSide === EFConnectableSide.AUTO ? EFConnectableSide.TOP : payload.inputSide ](payload.inputRect)
);
}

const positions = {
[ EFConnectableSide.TOP ]: (rect: IRect): IPoint => {
const result = new Point();
result.y = rect.y;
result.x = rect.x + rect.width / 2;
return result;
},
[ EFConnectableSide.BOTTOM ]: (rect: IRect): IPoint => {
const result = new Point();
result.y = rect.y + rect.height;
result.x = rect.x + rect.width / 2;
return result;
},
[ EFConnectableSide.LEFT ]: (rect: IRect): IPoint => {
const result = new Point();
result.x = rect.x;
result.y = rect.y + rect.height / 2;
return result;
},
[ EFConnectableSide.RIGHT ]: (rect: IRect): IPoint => {
const result = new Point();
result.x = rect.x + rect.width;
result.y = rect.y + rect.height / 2;
return result;
},
};




Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { GetIntersections, ILine, IPoint, Line } from '@foblex/2d';
import { CalculateConnectionLineByBehaviorRequest } from './calculate-connection-line-by-behavior.request';

export function floatingBehavior(payload: CalculateConnectionLineByBehaviorRequest): ILine {
return _getIntersectionsLine(
_fromRoundedRectIntersections(payload),
_toRoundedRectIntersections(payload),
payload
);
}

function _fromRoundedRectIntersections(payload: CalculateConnectionLineByBehaviorRequest) {
return GetIntersections.getRoundedRectIntersections(
payload.outputRect.gravityCenter, payload.inputRect.gravityCenter, payload.outputRect
)[ 0 ];
}

function _toRoundedRectIntersections(payload: CalculateConnectionLineByBehaviorRequest) {
return GetIntersections.getRoundedRectIntersections(
payload.inputRect.gravityCenter, payload.outputRect.gravityCenter, payload.inputRect
)[ 0 ];
}

function _getIntersectionsLine(from: IPoint, to: IPoint, payload: CalculateConnectionLineByBehaviorRequest): ILine {
return new Line(
from ? from : payload.outputRect.gravityCenter,
to ? to : payload.inputRect.gravityCenter
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from './calculate-connection-line-by-behavior.execution';

export * from './calculate-connection-line-by-behavior.request';

export * from './fixed-center-behavior';

export * from './fixed-outbound-behavior';

export * from './floating-behavior';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
import { GetConnectorWithRectRequest } from './get-connector-with-rect-request';
import { IRoundedRect } from '@foblex/2d';
import { IConnectorWithRect } from './i-connector-with-rect';
import { GetElementRectInFlowRequest } from '../../get-element-rect-in-flow';
import { GetNormalizedElementRectRequest } from '../../get-normalized-element-rect';

@Injectable()
@FExecutionRegister(GetConnectorWithRectRequest)
Expand All @@ -17,7 +17,7 @@ export class GetConnectorWithRectExecution implements IExecution<GetConnectorWit
public handle(request: GetConnectorWithRectRequest): IConnectorWithRect {
return {
fConnector: request.connector,
fRect: this.fMediator.send<IRoundedRect>(new GetElementRectInFlowRequest(request.connector.hostElement))
fRect: this.fMediator.send<IRoundedRect>(new GetNormalizedElementRectRequest(request.connector.hostElement))
}
}
}
2 changes: 2 additions & 0 deletions projects/f-flow/src/domain/f-connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export * from './find-closest-input-using-snap-threshold';

export * from './get-all-can-be-connected-input-positions';

export * from './calculate-connection-line-by-behavior';

export * from './get-connector-with-rect';

export * from './redraw-connections';
Expand Down
3 changes: 3 additions & 0 deletions projects/f-flow/src/domain/f-connection/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RemoveSnapConnectionFromStoreExecution } from './remove-snap-connection
import { AddConnectionMarkerToStoreExecution } from './add-connection-marker-to-store';
import { RemoveConnectionMarkerFromStoreExecution } from './remove-connection-marker-from-store';
import { RedrawConnectionsExecution } from './redraw-connections';
import { CalculateConnectionLineByBehaviorExecution } from './calculate-connection-line-by-behavior';

export const F_CONNECTION_FEATURES = [

Expand All @@ -28,6 +29,8 @@ export const F_CONNECTION_FEATURES = [

GetAllCanBeConnectedInputPositionsExecution,

CalculateConnectionLineByBehaviorExecution,

GetConnectorWithRectExecution,

RedrawConnectionsExecution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { ILine } from '@foblex/2d';
import { Injectable } from '@angular/core';
import { RedrawConnectionsRequest } from './redraw-connections-request';
import { FComponentsStore } from '../../../f-storage';
import { GetConnectionLineRequest } from '../../get-connection-line';
import { CalculateConnectionLineByBehaviorRequest } from '../calculate-connection-line-by-behavior';
import { FConnectorBase } from '../../../f-connectors';
import { FConnectionBase } from '../../../f-connection';
import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
import { GetElementRectInFlowRequest } from '../../get-element-rect-in-flow';
import { GetNormalizedElementRectRequest } from '../../get-normalized-element-rect';
import { CreateConnectionMarkersRequest } from '../create-connection-markers';

@Injectable()
Expand Down Expand Up @@ -59,9 +59,9 @@ export class RedrawConnectionsExecution implements IExecution<RedrawConnectionsR
}

private getLine(output: FConnectorBase, input: FConnectorBase, connection: FConnectionBase): ILine {
return this.fMediator.send(new GetConnectionLineRequest(
this.fMediator.send(new GetElementRectInFlowRequest(output.hostElement)),
this.fMediator.send(new GetElementRectInFlowRequest(input.hostElement)),
return this.fMediator.send(new CalculateConnectionLineByBehaviorRequest(
this.fMediator.send(new GetNormalizedElementRectRequest(output.hostElement)),
this.fMediator.send(new GetNormalizedElementRectRequest(input.hostElement)),
connection.fBehavior,
output.fConnectableSide,
input.fConnectableSide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
import { EmitSelectionChangeEventRequest } from './emit-selection-change-event-request';
import { FComponentsStore } from '../../../f-storage';
import { FDraggableDataContext, FSelectionChangeEvent } from '../../../f-draggable';
import { GetSelectionRequest } from '../../f-selection';
import { GetCurrentSelectionRequest, ICurrentSelection } from '../../f-selection';
import { NotifyTransformChangedRequest } from '../../../f-storage/features/notify-transform-changed';

@Injectable()
Expand All @@ -26,8 +26,19 @@ export class EmitSelectionChangeEventExecution implements IExecution<EmitSelecti
) {
return;
}
this._fSelectionChange.emit(this._fMediator.send<FSelectionChangeEvent>(new GetSelectionRequest()));

this._emitSelectionChange(this._getSelection());
this._fDraggableDataContext.isSelectedChanged = false;
this._fMediator.send<void>(new NotifyTransformChangedRequest());
}

private _getSelection(): ICurrentSelection {
return this._fMediator.send<ICurrentSelection>(new GetCurrentSelectionRequest());
}

private _emitSelectionChange(selection: ICurrentSelection): void {
this._fSelectionChange.emit(
new FSelectionChangeEvent(selection.nodes, selection.groups, selection.connections)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { GetFlowStateConnectionsRequest } from './get-flow-state-connections-request';
import { FExecutionRegister, IExecution } from '@foblex/mediator';
import { FComponentsStore } from '../../../f-storage';
import { FComponentsStore } from '../../../../f-storage';
import { IFFlowStateConnection } from '../i-f-flow-state-connection';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { GetFlowStateNodesRequest } from './get-flow-state-nodes-request';
import { FExecutionRegister, IExecution } from '@foblex/mediator';
import { IFFlowStateNode } from '../i-f-flow-state-node';
import { FComponentsStore } from '../../../f-storage';
import { FComponentsStore } from '../../../../f-storage';
import { IFFlowStateConnector } from '../i-f-flow-state-connector';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { GetFlowStateRequest } from './get-flow-state.request';
import { Injectable } from '@angular/core';
import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator';
import { IFFlowState } from './i-f-flow-state';
import { FComponentsStore } from '../../f-storage';
import { FGroupDirective, FNodeDirective } from '../../f-node';
import { FComponentsStore } from '../../../f-storage';
import { FGroupDirective, FNodeDirective } from '../../../f-node';
import { IPoint, ITransformModel, PointExtensions } from '@foblex/2d';
import { GetFlowStateNodesRequest } from './get-flow-state-nodes';
import { GetFlowStateConnectionsRequest } from './get-flow-state-connections';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EFConnectionBehavior, EFConnectionType } from '../../f-connection';
import { EFConnectionBehavior, EFConnectionType } from '../../../f-connection';

export interface IFFlowStateConnection {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EFConnectableSide } from '../../f-connectors';
import { EFConnectableSide } from '../../../f-connectors';

export interface IFFlowStateConnector {

Expand Down
2 changes: 2 additions & 0 deletions projects/f-flow/src/domain/f-flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export * from './get-flow';

export * from './get-flow-host-element';

export * from './get-flow-state';

export * from './remove-flow-from-store';

export * from './providers';
Loading

0 comments on commit 58850bb

Please sign in to comment.