diff --git a/projects/f-flow/package.json b/projects/f-flow/package.json index bdcc347a..db354ecb 100644 --- a/projects/f-flow/package.json +++ b/projects/f-flow/package.json @@ -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", diff --git a/projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element.execution.ts b/projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element.execution.ts deleted file mode 100644 index f0ac82a2..00000000 --- a/projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element.execution.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Injectable } from '@angular/core'; -import { CreateRoundedRectFromElementRequest } from './create-rounded-rect-from-element-request'; -import { FExecutionRegister, IExecution } from '@foblex/mediator'; -import { BrowserService } from '@foblex/platform'; -import { RoundedRect, RectExtensions } from '@foblex/2d'; - -@Injectable() -@FExecutionRegister(CreateRoundedRectFromElementRequest) -export class CreateRoundedRectFromElementExecution implements IExecution { - - constructor( - private fBrowser: BrowserService - ) { - } - - public handle(request: CreateRoundedRectFromElementRequest): RoundedRect { - return this.setRadiusFromElement(RoundedRect.fromRect(RectExtensions.fromElement(request.element)), request.element); - } - - private setRadiusFromElement(rect: RoundedRect, element: HTMLElement | SVGElement): RoundedRect { - const styles = this.getComputedStyle(element); - rect.radius1 = this.toPixels(styles.borderTopLeftRadius, element, styles.fontSize); - rect.radius2 = this.toPixels(styles.borderTopRightRadius, element, styles.fontSize); - rect.radius3 = this.toPixels(styles.borderBottomRightRadius, element, styles.fontSize); - rect.radius4 = this.toPixels(styles.borderBottomLeftRadius, element, styles.fontSize); - return rect; - } - - private getComputedStyle(element: HTMLElement | SVGElement): CSSStyleDeclaration { - return this.fBrowser.window.getComputedStyle(element); - } - - private toPixels(value: string, element: HTMLElement | SVGElement, fontSize: string): number { - return this.fBrowser.toPixels(value, element.clientWidth, element.clientHeight, fontSize) || 0 - } -} diff --git a/projects/f-flow/src/domain/create-rounded-rect-from-element/index.ts b/projects/f-flow/src/domain/create-rounded-rect-from-element/index.ts deleted file mode 100644 index 1af081f0..00000000 --- a/projects/f-flow/src/domain/create-rounded-rect-from-element/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './create-rounded-rect-from-element.execution'; - -export * from './create-rounded-rect-from-element-request'; diff --git a/projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.spec.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.spec.ts similarity index 71% rename from projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.spec.ts rename to projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.spec.ts index 75d80194..c2529d74 100644 --- a/projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.spec.ts +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.spec.ts @@ -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; }); 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, @@ -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, @@ -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, diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.ts new file mode 100644 index 00000000..d701f7f6 --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.execution.ts @@ -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 { + + 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); + } +} + diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.request.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.request.ts new file mode 100644 index 00000000..aaa3c6d9 --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/calculate-connection-line-by-behavior.request.ts @@ -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, + ) { + + } +} diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-center-behavior.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-center-behavior.ts new file mode 100644 index 00000000..cbcb57e1 --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-center-behavior.ts @@ -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 + ); +} diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-outbound-behavior.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-outbound-behavior.ts new file mode 100644 index 00000000..1054d6bf --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/fixed-outbound-behavior.ts @@ -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; + }, +}; + + + + diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/floating-behavior.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/floating-behavior.ts new file mode 100644 index 00000000..60112236 --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/floating-behavior.ts @@ -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 + ); +} diff --git a/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/index.ts b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/index.ts new file mode 100644 index 00000000..103ea120 --- /dev/null +++ b/projects/f-flow/src/domain/f-connection/calculate-connection-line-by-behavior/index.ts @@ -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'; diff --git a/projects/f-flow/src/domain/f-connection/get-connector-with-rect/get-connector-with-rect.execution.ts b/projects/f-flow/src/domain/f-connection/get-connector-with-rect/get-connector-with-rect.execution.ts index 12647144..844c71a4 100644 --- a/projects/f-flow/src/domain/f-connection/get-connector-with-rect/get-connector-with-rect.execution.ts +++ b/projects/f-flow/src/domain/f-connection/get-connector-with-rect/get-connector-with-rect.execution.ts @@ -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) @@ -17,7 +17,7 @@ export class GetConnectorWithRectExecution implements IExecution(new GetElementRectInFlowRequest(request.connector.hostElement)) + fRect: this.fMediator.send(new GetNormalizedElementRectRequest(request.connector.hostElement)) } } } diff --git a/projects/f-flow/src/domain/f-connection/index.ts b/projects/f-flow/src/domain/f-connection/index.ts index 4d7b3422..db3439d8 100644 --- a/projects/f-flow/src/domain/f-connection/index.ts +++ b/projects/f-flow/src/domain/f-connection/index.ts @@ -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'; diff --git a/projects/f-flow/src/domain/f-connection/providers.ts b/projects/f-flow/src/domain/f-connection/providers.ts index 50c87c60..810e5cb3 100644 --- a/projects/f-flow/src/domain/f-connection/providers.ts +++ b/projects/f-flow/src/domain/f-connection/providers.ts @@ -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 = [ @@ -28,6 +29,8 @@ export const F_CONNECTION_FEATURES = [ GetAllCanBeConnectedInputPositionsExecution, + CalculateConnectionLineByBehaviorExecution, + GetConnectorWithRectExecution, RedrawConnectionsExecution, diff --git a/projects/f-flow/src/domain/f-connection/redraw-connections/redraw-connections.execution.ts b/projects/f-flow/src/domain/f-connection/redraw-connections/redraw-connections.execution.ts index b4111d83..eba6bea8 100644 --- a/projects/f-flow/src/domain/f-connection/redraw-connections/redraw-connections.execution.ts +++ b/projects/f-flow/src/domain/f-connection/redraw-connections/redraw-connections.execution.ts @@ -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() @@ -59,9 +59,9 @@ export class RedrawConnectionsExecution implements IExecution(new GetSelectionRequest())); + + this._emitSelectionChange(this._getSelection()); this._fDraggableDataContext.isSelectedChanged = false; this._fMediator.send(new NotifyTransformChangedRequest()); } + + private _getSelection(): ICurrentSelection { + return this._fMediator.send(new GetCurrentSelectionRequest()); + } + + private _emitSelectionChange(selection: ICurrentSelection): void { + this._fSelectionChange.emit( + new FSelectionChangeEvent(selection.nodes, selection.groups, selection.connections) + ); + } } diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/get-flow-state-connections-request.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/get-flow-state-connections-request.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/get-flow-state-connections-request.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/get-flow-state-connections-request.ts diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts similarity index 93% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts index 9451cfb0..ed861f4c 100644 --- a/projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts +++ b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/get-flow-state-connections.execution.ts @@ -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() diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/index.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/index.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-connections/index.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-connections/index.ts diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/get-flow-state-nodes-request.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes-request.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/get-flow-state-nodes-request.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes-request.ts diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts similarity index 96% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts index 4dcddcd2..b17608f8 100644 --- a/projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts +++ b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/get-flow-state-nodes.execution.ts @@ -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() diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/index.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/index.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state-nodes/index.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state-nodes/index.ts diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state.execution.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state.execution.ts similarity index 91% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state.execution.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state.execution.ts index 7498564a..45df0dad 100644 --- a/projects/f-flow/src/domain/get-flow-state/get-flow-state.execution.ts +++ b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state.execution.ts @@ -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'; diff --git a/projects/f-flow/src/domain/get-flow-state/get-flow-state.request.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state.request.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/get-flow-state.request.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/get-flow-state.request.ts diff --git a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connection.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connection.ts similarity index 71% rename from projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connection.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connection.ts index 63e1379f..05db2529 100644 --- a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connection.ts +++ b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connection.ts @@ -1,4 +1,4 @@ -import { EFConnectionBehavior, EFConnectionType } from '../../f-connection'; +import { EFConnectionBehavior, EFConnectionType } from '../../../f-connection'; export interface IFFlowStateConnection { diff --git a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connector.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connector.ts similarity index 62% rename from projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connector.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connector.ts index 4d4778a7..edc38aae 100644 --- a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state-connector.ts +++ b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-connector.ts @@ -1,4 +1,4 @@ -import { EFConnectableSide } from '../../f-connectors'; +import { EFConnectableSide } from '../../../f-connectors'; export interface IFFlowStateConnector { diff --git a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state-node.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-node.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/i-f-flow-state-node.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state-node.ts diff --git a/projects/f-flow/src/domain/get-flow-state/i-f-flow-state.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/i-f-flow-state.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/i-f-flow-state.ts diff --git a/projects/f-flow/src/domain/get-flow-state/index.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/index.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/index.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/index.ts diff --git a/projects/f-flow/src/domain/get-flow-state/providers.ts b/projects/f-flow/src/domain/f-flow/get-flow-state/providers.ts similarity index 100% rename from projects/f-flow/src/domain/get-flow-state/providers.ts rename to projects/f-flow/src/domain/f-flow/get-flow-state/providers.ts diff --git a/projects/f-flow/src/domain/f-flow/index.ts b/projects/f-flow/src/domain/f-flow/index.ts index 02870ffd..c37ed777 100644 --- a/projects/f-flow/src/domain/f-flow/index.ts +++ b/projects/f-flow/src/domain/f-flow/index.ts @@ -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'; diff --git a/projects/f-flow/src/domain/f-flow/providers.ts b/projects/f-flow/src/domain/f-flow/providers.ts index 3550a177..763db152 100644 --- a/projects/f-flow/src/domain/f-flow/providers.ts +++ b/projects/f-flow/src/domain/f-flow/providers.ts @@ -2,6 +2,7 @@ import { GetFlowHostElementExecution } from './get-flow-host-element'; import { AddFlowToStoreExecution } from './add-flow-to-store'; import { RemoveFlowFromStoreExecution } from './remove-flow-from-store'; import { GetFlowExecution } from './get-flow'; +import { GET_FLOW_STATE_PROVIDERS } from './get-flow-state'; export const F_FLOW_FEATURES = [ @@ -11,5 +12,7 @@ export const F_FLOW_FEATURES = [ GetFlowHostElementExecution, + ...GET_FLOW_STATE_PROVIDERS, + RemoveFlowFromStoreExecution ]; diff --git a/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.execution.ts b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.execution.ts new file mode 100644 index 00000000..16149d28 --- /dev/null +++ b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.execution.ts @@ -0,0 +1,27 @@ +import { IRect, RectExtensions } from '@foblex/2d'; +import { CalculateNodesBoundingBoxNormalizedPositionRequest } from './calculate-nodes-bounding-box-normalized-position.request'; +import { inject, Injectable } from '@angular/core'; +import { FComponentsStore } from '../../../f-storage'; +import { FExecutionRegister, IExecution } from '@foblex/mediator'; +import { FNodeBase } from '../../../f-node'; + +@Injectable() +@FExecutionRegister(CalculateNodesBoundingBoxNormalizedPositionRequest) +export class CalculateNodesBoundingBoxNormalizedPositionExecution implements IExecution { + + private _fComponentsStore = inject(FComponentsStore); + + public handle(request: CalculateNodesBoundingBoxNormalizedPositionRequest): IRect | null { + return RectExtensions.union(this._getNodesRects()); + } + + private _getNodesRects(): IRect[] { + return this._fComponentsStore.fNodes.map((x) => { + return this._getElementRect(x, RectExtensions.fromElement(x.hostElement)); + }); + } + + private _getElementRect(fNode: FNodeBase, rect: IRect): IRect { + return RectExtensions.initialize(fNode.position.x, fNode.position.y, rect.width, rect.height) + } +} diff --git a/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.request.ts b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.request.ts new file mode 100644 index 00000000..a935ca7a --- /dev/null +++ b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/calculate-nodes-bounding-box-normalized-position.request.ts @@ -0,0 +1,3 @@ +export class CalculateNodesBoundingBoxNormalizedPositionRequest { + +} diff --git a/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/index.ts b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/index.ts new file mode 100644 index 00000000..8ed180dc --- /dev/null +++ b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box-normalized-position/index.ts @@ -0,0 +1,3 @@ +export * from './calculate-nodes-bounding-box-normalized-position.execution'; + +export * from './calculate-nodes-bounding-box-normalized-position.request'; diff --git a/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box/calculate-nodes-bounding-box.execution.ts b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box/calculate-nodes-bounding-box.execution.ts index db2a58fd..80fbe2aa 100644 --- a/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box/calculate-nodes-bounding-box.execution.ts +++ b/projects/f-flow/src/domain/f-node/calculate-nodes-bounding-box/calculate-nodes-bounding-box.execution.ts @@ -15,10 +15,12 @@ export class CalculateNodesBoundingBoxExecution implements IExecution this._getElementRect(x.hostElement)); + return this._fComponentsStore.fNodes.map((x) => { + return this._getElementRect(x.hostElement); + }); } - private _getElementRect(element: HTMLElement): IRect { - return RectExtensions.fromElement(element); + private _getElementRect(element: HTMLElement | SVGElement): IRect { + return RectExtensions.fromElement(element) } } diff --git a/projects/f-flow/src/domain/f-node/index.ts b/projects/f-flow/src/domain/f-node/index.ts index ca4cc6cc..e8ff1678 100644 --- a/projects/f-flow/src/domain/f-node/index.ts +++ b/projects/f-flow/src/domain/f-node/index.ts @@ -2,6 +2,8 @@ export * from './add-node-to-store'; export * from './calculate-nodes-bounding-box'; +export * from './calculate-nodes-bounding-box-normalized-position'; + export * from './get-nodes'; export * from './update-node-when-state-or-size-changed'; diff --git a/projects/f-flow/src/domain/f-node/providers.ts b/projects/f-flow/src/domain/f-node/providers.ts index 3ab8602e..590f4958 100644 --- a/projects/f-flow/src/domain/f-node/providers.ts +++ b/projects/f-flow/src/domain/f-node/providers.ts @@ -3,6 +3,9 @@ import { RemoveNodeFromStoreExecution } from './remove-node-from-store'; import { UpdateNodeWhenStateOrSizeChangedExecution } from './update-node-when-state-or-size-changed'; import { GetNodesExecution } from './get-nodes'; import { CalculateNodesBoundingBoxExecution } from './calculate-nodes-bounding-box'; +import { + CalculateNodesBoundingBoxNormalizedPositionExecution +} from './calculate-nodes-bounding-box-normalized-position'; export const F_NODE_FEATURES = [ @@ -10,6 +13,8 @@ export const F_NODE_FEATURES = [ CalculateNodesBoundingBoxExecution, + CalculateNodesBoundingBoxNormalizedPositionExecution, + GetNodesExecution, UpdateNodeWhenStateOrSizeChangedExecution, diff --git a/projects/f-flow/src/domain/f-selection/clear-selection/clear-selection.execution.spec.ts b/projects/f-flow/src/domain/f-selection/clear-selection/clear-selection.execution.spec.ts index 69ca4776..798e3957 100644 --- a/projects/f-flow/src/domain/f-selection/clear-selection/clear-selection.execution.spec.ts +++ b/projects/f-flow/src/domain/f-selection/clear-selection/clear-selection.execution.spec.ts @@ -2,8 +2,9 @@ import { TestBed } from '@angular/core/testing'; import { FMediator } from '@foblex/mediator'; import { ClearSelectionRequest } from './clear-selection.request'; import { ClearSelectionExecution } from './clear-selection.execution'; -import { FDraggableDataContext, ICanChangeSelection } from '@foblex/flow'; import { setupTestModule } from '../../test-setup'; +import { ICanChangeSelection } from '../../../mixins'; +import { FDraggableDataContext } from '../../../f-draggable'; export const MOCK_SELECTABLE_ITEM: ICanChangeSelection = { fId: '1', diff --git a/projects/f-flow/src/domain/get-can-be-selected-items/get-can-be-selected-items-request.ts b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/get-can-be-selected-items-request.ts similarity index 100% rename from projects/f-flow/src/domain/get-can-be-selected-items/get-can-be-selected-items-request.ts rename to projects/f-flow/src/domain/f-selection/get-can-be-selected-items/get-can-be-selected-items-request.ts diff --git a/projects/f-flow/src/domain/get-can-be-selected-items/get-can-be-selected-items.execution.ts b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/get-can-be-selected-items.execution.ts similarity index 54% rename from projects/f-flow/src/domain/get-can-be-selected-items/get-can-be-selected-items.execution.ts rename to projects/f-flow/src/domain/f-selection/get-can-be-selected-items/get-can-be-selected-items.execution.ts index 9dd49ff8..6bf0dc34 100644 --- a/projects/f-flow/src/domain/get-can-be-selected-items/get-can-be-selected-items.execution.ts +++ b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/get-can-be-selected-items.execution.ts @@ -1,61 +1,62 @@ -import { Injectable } from '@angular/core'; +import { inject, Injectable } from '@angular/core'; import { IRect, ITransformModel, RectExtensions } from '@foblex/2d'; -import { ISelectableWithRect } from './i-selectable-with-rect'; +import { ICanBeSelected } from './i-can-be-selected'; import { GetCanBeSelectedItemsRequest } from './get-can-be-selected-items-request'; -import { FNodeBase } from '../../f-node'; -import { FConnectionBase } from '../../f-connection'; +import { FNodeBase } from '../../../f-node'; +import { FConnectionBase } from '../../../f-connection'; import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator'; -import { FComponentsStore } from '../../f-storage'; -import { FDraggableDataContext } from '../../f-draggable'; -import { GetElementRectInFlowRequest } from '../get-element-rect-in-flow'; +import { FComponentsStore } from '../../../f-storage'; +import { FDraggableDataContext } from '../../../f-draggable'; +import { GetNormalizedElementRectRequest } from '../../get-normalized-element-rect'; @Injectable() @FExecutionRegister(GetCanBeSelectedItemsRequest) -export class GetCanBeSelectedItemsExecution implements IExecution { +export class GetCanBeSelectedItemsExecution implements IExecution { + + private _fMediator = inject(FMediator); + private _fComponentsStore = inject(FComponentsStore); private get fNodes(): FNodeBase[] { - return this.fComponentsStore.fNodes; + return this._fComponentsStore.fNodes; } private get fConnections(): FConnectionBase[] { - return this.fComponentsStore.fConnections; + return this._fComponentsStore.fConnections; } private get transform(): ITransformModel { - return this.fComponentsStore.fCanvas!.transform; + return this._fComponentsStore.fCanvas!.transform; } constructor( - private fComponentsStore: FComponentsStore, private fDraggableDataContext: FDraggableDataContext, - private fMediator: FMediator, ) { } - public handle(): ISelectableWithRect[] { + public handle(): ICanBeSelected[] { return [ ...this.getNodesWithRects(), ...this.getConnectionsWithRects() ].filter((x) => { return !this.fDraggableDataContext.selectedItems.includes(x.element); }); } - private getNodesWithRects(): ISelectableWithRect[] { + private getNodesWithRects(): ICanBeSelected[] { return this.fNodes.filter((x) => !x.fSelectionDisabled).map((x) => { return { element: x, rect: RectExtensions.mult( - this.fMediator.send(new GetElementRectInFlowRequest(x.hostElement)), + this._fMediator.send(new GetNormalizedElementRectRequest(x.hostElement)), this.transform.scale ) }; }); } - private getConnectionsWithRects(): ISelectableWithRect[] { + private getConnectionsWithRects(): ICanBeSelected[] { return this.fConnections.filter((x) => !x.fSelectionDisabled).map((x) => { return { element: x, rect: RectExtensions.mult( - this.fMediator.send(new GetElementRectInFlowRequest(x.boundingElement)), + this._fMediator.send(new GetNormalizedElementRectRequest(x.boundingElement)), this.transform.scale ) }; diff --git a/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/i-can-be-selected.ts b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/i-can-be-selected.ts new file mode 100644 index 00000000..54263dfa --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/i-can-be-selected.ts @@ -0,0 +1,9 @@ +import { IRect } from '@foblex/2d'; +import { ICanChangeSelection } from '../../../mixins'; + +export interface ICanBeSelected { + + element: ICanChangeSelection; + + rect: IRect; +} diff --git a/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/index.ts b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/index.ts new file mode 100644 index 00000000..89ded6e1 --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-can-be-selected-items/index.ts @@ -0,0 +1,5 @@ +export * from './get-can-be-selected-items.execution'; + +export * from './get-can-be-selected-items-request'; + +export * from './i-can-be-selected'; diff --git a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.spec.ts b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.spec.ts similarity index 70% rename from projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.spec.ts rename to projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.spec.ts index 47bf048f..10ca4982 100644 --- a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.spec.ts +++ b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.spec.ts @@ -1,16 +1,16 @@ import { TestBed } from '@angular/core/testing'; import { FMediator } from '@foblex/mediator'; -import { GetSelectionExecution } from './get-selection.execution'; -import { GetSelectionRequest } from './get-selection.request'; +import { GetCurrentSelectionExecution } from './get-current-selection.execution'; +import { GetCurrentSelectionRequest } from './get-current-selection.request'; import { setupTestModule } from '../../test-setup'; -import { FDraggableDataContext, FSelectionChangeEvent } from '@foblex/flow'; +import { FDraggableDataContext, FSelectionChangeEvent } from '../../../f-draggable'; describe('GetSelectionExecution', () => { let fDraggableDataContext: FDraggableDataContext; let fMediator: FMediator; beforeEach(() => { - setupTestModule([ GetSelectionExecution ]); + setupTestModule([ GetCurrentSelectionExecution ]); fDraggableDataContext = TestBed.inject(FDraggableDataContext) as jasmine.SpyObj; fMediator = TestBed.inject(FMediator) as jasmine.SpyObj; }); @@ -26,7 +26,14 @@ describe('GetSelectionExecution', () => { }, { hostElement: { - classList: { contains: (className: string) => className !== 'f-node' }, + classList: { contains: (className: string) => className === 'f-group' }, + dataset: { fGroupId: 'group1' }, + id: 'group1' + } + }, + { + hostElement: { + classList: { contains: (className: string) => className === 'f-connection' }, dataset: {}, id: 'connection2' } @@ -34,16 +41,17 @@ describe('GetSelectionExecution', () => { ]; fDraggableDataContext.selectedItems = mockSelectedItems as any; - const result = fMediator.send(new GetSelectionRequest()); + const result = fMediator.send(new GetCurrentSelectionRequest()); expect(result.nodes).toEqual([ 'node1' ]); + expect(result.groups).toEqual([ 'group1' ]); expect(result.connections).toEqual([ 'connection2' ]); }); it('should return empty FSelectionChangeEvent when no items are selected', () => { fDraggableDataContext.selectedItems = []; - const result = fMediator.send(new GetSelectionRequest()); + const result = fMediator.send(new GetCurrentSelectionRequest()); expect(result.nodes).toEqual([]); expect(result.connections).toEqual([]); diff --git a/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.ts b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.ts new file mode 100644 index 00000000..a1bec4ba --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.execution.ts @@ -0,0 +1,38 @@ +import { GetCurrentSelectionRequest } from './get-current-selection.request'; +import { inject, Injectable } from '@angular/core'; +import { FExecutionRegister, IExecution } from '@foblex/mediator'; +import { FDraggableDataContext, FSelectionChangeEvent } from '../../../f-draggable'; +import { ICurrentSelection } from './i-current-selection'; + +@Injectable() +@FExecutionRegister(GetCurrentSelectionRequest) +export class GetCurrentSelectionExecution implements IExecution { + + private _fDraggableDataContext = inject(FDraggableDataContext); + + public handle(): ICurrentSelection { + return { + nodes: this._getSelectedNodes(), + groups: this._getSelectedGroups(), + connections: this._getSelectedConnections() + } + } + + private _getSelectedNodes(): string[] { + return this._fDraggableDataContext.selectedItems + .filter(x => x.hostElement.classList.contains('f-node')) + .map(x => x.hostElement.dataset[ 'fNodeId' ]!); + } + + private _getSelectedGroups(): string[] { + return this._fDraggableDataContext.selectedItems + .filter(x => x.hostElement.classList.contains('f-group')) + .map(x => x.hostElement.dataset[ 'fGroupId' ]!); + } + + private _getSelectedConnections(): string[] { + return this._fDraggableDataContext.selectedItems + .filter(x => !x.hostElement.classList.contains('f-node') && !x.hostElement.classList.contains('f-group')) + .map(x => x.hostElement.id); + } +} diff --git a/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.request.ts b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.request.ts new file mode 100644 index 00000000..bf1ec36f --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-current-selection/get-current-selection.request.ts @@ -0,0 +1,3 @@ +export class GetCurrentSelectionRequest { + +} diff --git a/projects/f-flow/src/domain/f-selection/get-current-selection/i-current-selection.ts b/projects/f-flow/src/domain/f-selection/get-current-selection/i-current-selection.ts new file mode 100644 index 00000000..7a83494b --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-current-selection/i-current-selection.ts @@ -0,0 +1,8 @@ +export interface ICurrentSelection { + + nodes: string[]; + + groups: string[]; + + connections: string[]; +} diff --git a/projects/f-flow/src/domain/f-selection/get-current-selection/index.ts b/projects/f-flow/src/domain/f-selection/get-current-selection/index.ts new file mode 100644 index 00000000..99e38571 --- /dev/null +++ b/projects/f-flow/src/domain/f-selection/get-current-selection/index.ts @@ -0,0 +1,5 @@ +export * from './get-current-selection.execution'; + +export * from './get-current-selection.request'; + +export * from './i-current-selection'; diff --git a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.ts b/projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.ts deleted file mode 100644 index 3cda36dc..00000000 --- a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.execution.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { GetSelectionRequest } from './get-selection.request'; -import { Injectable } from '@angular/core'; -import { FExecutionRegister, IExecution } from '@foblex/mediator'; -import { FDraggableDataContext, FSelectionChangeEvent } from '../../../f-draggable'; - -@Injectable() -@FExecutionRegister(GetSelectionRequest) -export class GetSelectionExecution implements IExecution { - - constructor( - private fDraggableDataContext: FDraggableDataContext, - ) { - } - - public handle(): FSelectionChangeEvent { - - let selectedNodes: string[] = []; - let selectedConnections: string[] = []; - - this.fDraggableDataContext.selectedItems.forEach((x) => { - if (x.hostElement.classList.contains('f-node')) { - selectedNodes.push(x.hostElement.dataset['fNodeId']!) - } else { - selectedConnections.push(x.hostElement.id); - } - }); - - return new FSelectionChangeEvent(selectedNodes, selectedConnections); - } -} diff --git a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.request.ts b/projects/f-flow/src/domain/f-selection/get-selection/get-selection.request.ts deleted file mode 100644 index 370acf94..00000000 --- a/projects/f-flow/src/domain/f-selection/get-selection/get-selection.request.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class GetSelectionRequest { - -} diff --git a/projects/f-flow/src/domain/f-selection/get-selection/index.ts b/projects/f-flow/src/domain/f-selection/get-selection/index.ts deleted file mode 100644 index 245f4eac..00000000 --- a/projects/f-flow/src/domain/f-selection/get-selection/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-selection.execution'; - -export * from './get-selection.request'; diff --git a/projects/f-flow/src/domain/f-selection/index.ts b/projects/f-flow/src/domain/f-selection/index.ts index cf4d2117..bee5b7b9 100644 --- a/projects/f-flow/src/domain/f-selection/index.ts +++ b/projects/f-flow/src/domain/f-selection/index.ts @@ -1,6 +1,8 @@ export * from './clear-selection'; -export * from './get-selection'; +export * from './get-can-be-selected-items'; + +export * from './get-current-selection'; export * from './select'; diff --git a/projects/f-flow/src/domain/f-selection/providers.ts b/projects/f-flow/src/domain/f-selection/providers.ts index 52bc07c2..e7d9b8ca 100644 --- a/projects/f-flow/src/domain/f-selection/providers.ts +++ b/projects/f-flow/src/domain/f-selection/providers.ts @@ -1,16 +1,17 @@ import { ClearSelectionExecution } from './clear-selection'; -import { GetSelectionExecution } from './get-selection'; +import { GetCurrentSelectionExecution } from './get-current-selection'; import { SelectExecution } from './select'; import { SelectAllExecution } from './select-all'; -import { - SelectAndUpdateNodeLayerExecution -} from './select-and-update-node-layer/select-and-update-node-layer.execution'; +import { SelectAndUpdateNodeLayerExecution } from './select-and-update-node-layer'; +import { GetCanBeSelectedItemsExecution } from './get-can-be-selected-items'; export const F_SELECTION_FEATURES = [ ClearSelectionExecution, - GetSelectionExecution, + GetCanBeSelectedItemsExecution, + + GetCurrentSelectionExecution, SelectExecution, diff --git a/projects/f-flow/src/domain/f-selection/select-all/select-all.execution.spec.ts b/projects/f-flow/src/domain/f-selection/select-all/select-all.execution.spec.ts index 6d480af3..23a9784c 100644 --- a/projects/f-flow/src/domain/f-selection/select-all/select-all.execution.spec.ts +++ b/projects/f-flow/src/domain/f-selection/select-all/select-all.execution.spec.ts @@ -2,8 +2,9 @@ import { TestBed } from '@angular/core/testing'; import { SelectAllRequest } from './select-all.request'; import { FMediator } from '@foblex/mediator'; import { SelectAllExecution } from './select-all.execution'; -import { FComponentsStore, FDraggableDataContext } from '@foblex/flow'; import { setupTestModule } from '../../test-setup'; +import { FDraggableDataContext } from '../../../f-draggable'; +import { FComponentsStore } from '../../../f-storage'; describe('SelectAllExecution', () => { let fDraggableDataContext: FDraggableDataContext; diff --git a/projects/f-flow/src/domain/get-can-be-selected-items/i-selectable-with-rect.ts b/projects/f-flow/src/domain/get-can-be-selected-items/i-selectable-with-rect.ts deleted file mode 100644 index 157748f9..00000000 --- a/projects/f-flow/src/domain/get-can-be-selected-items/i-selectable-with-rect.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IRect } from '@foblex/2d'; -import { ICanChangeSelection } from '../../mixins'; - -export interface ISelectableWithRect { - - element: ICanChangeSelection; - - rect: IRect; -} diff --git a/projects/f-flow/src/domain/get-can-be-selected-items/index.ts b/projects/f-flow/src/domain/get-can-be-selected-items/index.ts deleted file mode 100644 index 5cc0d65e..00000000 --- a/projects/f-flow/src/domain/get-can-be-selected-items/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-can-be-selected-items.execution'; - -export * from './i-selectable-with-rect'; diff --git a/projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.ts b/projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.ts deleted file mode 100644 index 1fafa071..00000000 --- a/projects/f-flow/src/domain/get-connection-line/get-connection-line.execution.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { GetConnectionLineRequest } from './get-connection-line.request'; -import { Injectable } from '@angular/core'; -import { EFConnectionBehavior } from '../../f-connection'; -import { EFConnectableSide } from '../../f-connectors'; -import { FExecutionRegister, IExecution } from '@foblex/mediator'; -import { GetIntersections, ILine, IPoint, IRect, IRoundedRect, Line, Point } from '@foblex/2d'; - -@Injectable() -@FExecutionRegister(GetConnectionLineRequest) -export class GetConnectionLineExecution implements IExecution { - - private behaviorHandlers = { - - [ EFConnectionBehavior.FLOATING.toString() ]: this.floatingBehavior, - - [ EFConnectionBehavior.FIXED_CENTER.toString() ]: this.fixedCenterBehavior, - - [ EFConnectionBehavior.FIXED.toString() ]: this.fixedOutboundBehaviour, - } - - public handle(payload: GetConnectionLineRequest): ILine { - return this.behaviorHandlers[ payload.behavior ](payload); - } - - private floatingBehavior(payload: GetConnectionLineRequest): ILine { - const fromResult = GetIntersections.getRoundedRectIntersections(payload.outputRect.gravityCenter, payload.inputRect.gravityCenter, payload.outputRect)[ 0 ]; - const toResult = GetIntersections.getRoundedRectIntersections(payload.inputRect.gravityCenter, payload.outputRect.gravityCenter, payload.inputRect)[ 0 ]; - return new Line( - fromResult ? fromResult : payload.outputRect.gravityCenter, - toResult ? toResult : payload.inputRect.gravityCenter - ); - } - - private fixedCenterBehavior(payload: GetConnectionLineRequest): ILine { - return new Line( - payload.outputRect.gravityCenter, - payload.inputRect.gravityCenter - ); - } - - private fixedOutboundBehaviour(payload: GetConnectionLineRequest): ILine { - return new Line( - positionFixedOutbound[ payload.outputSide === EFConnectableSide.AUTO ? EFConnectableSide.BOTTOM : payload.outputSide ](payload.outputRect as IRoundedRect), - positionFixedOutbound[ payload.inputSide === EFConnectableSide.AUTO ? EFConnectableSide.TOP : payload.inputSide ](payload.inputRect as IRoundedRect) - ); - } -} - -const positionFixedOutbound = { - [ 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; - }, -}; - - - - diff --git a/projects/f-flow/src/domain/get-connection-line/get-connection-line.request.ts b/projects/f-flow/src/domain/get-connection-line/get-connection-line.request.ts deleted file mode 100644 index 1956eba7..00000000 --- a/projects/f-flow/src/domain/get-connection-line/get-connection-line.request.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { EFConnectionBehavior } from '../../f-connection'; -import { EFConnectableSide } from '../../f-connectors'; -import { IRoundedRect } from '@foblex/2d'; - -export class GetConnectionLineRequest { - - constructor( - public outputRect: IRoundedRect, - public inputRect: IRoundedRect, - public behavior: EFConnectionBehavior | string, - public outputSide: EFConnectableSide, - public inputSide: EFConnectableSide, - ) { - - } -} diff --git a/projects/f-flow/src/domain/get-connection-line/index.ts b/projects/f-flow/src/domain/get-connection-line/index.ts deleted file mode 100644 index 3015a4d1..00000000 --- a/projects/f-flow/src/domain/get-connection-line/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-connection-line.execution'; - -export * from './get-connection-line.request'; diff --git a/projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow.execution.ts b/projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow.execution.ts deleted file mode 100644 index 0f0328cc..00000000 --- a/projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow.execution.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { inject, Injectable } from '@angular/core'; -import { GetElementRectInFlowRequest } from './get-element-rect-in-flow-request'; -import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator'; -import { FComponentsStore } from '../../f-storage'; -import { IRoundedRect, RoundedRect, IPoint, ISize, Point, SizeExtensions, ITransformModel } from '@foblex/2d'; -import { CreateRoundedRectFromElementRequest } from '../create-rounded-rect-from-element'; - -@Injectable() -@FExecutionRegister(GetElementRectInFlowRequest) -export class GetElementRectInFlowExecution implements IExecution { - - private _fComponentsStore = inject(FComponentsStore); - - private _fMediator = inject(FMediator); - - private get _transform(): ITransformModel { - return this._fComponentsStore.fCanvas!.transform; - } - - private get flowHost(): HTMLElement { - return this._fComponentsStore.flowHost; - } - - public handle(request: GetElementRectInFlowRequest): IRoundedRect { - const systemRect = this._getElementRoundRect(request.element); - const position = this.transformElementPositionInFlow(systemRect); - const size = this.transformElementSizeInFlow(systemRect); - - return new RoundedRect( - position.x, position.y, size.width, size.height, - systemRect.radius1, systemRect.radius2, systemRect.radius3, systemRect.radius4 - ); - } - - private _getElementRoundRect(element: HTMLElement | SVGElement): IRoundedRect { - return this._fMediator.send( - new CreateRoundedRectFromElementRequest(element) - ); - } - - private transformElementPositionInFlow(rect: IRoundedRect): IPoint { - return Point.fromPoint(rect).elementTransform(this.flowHost).sub(this._transform.scaledPosition).sub(this._transform.position).div(this._transform.scale); - } - - private transformElementSizeInFlow(rect: IRoundedRect): ISize { - return SizeExtensions.initialize(rect.width / this._transform.scale, rect.height / this._transform.scale); - } -} diff --git a/projects/f-flow/src/domain/get-element-rect-in-flow/index.ts b/projects/f-flow/src/domain/get-element-rect-in-flow/index.ts deleted file mode 100644 index febe8503..00000000 --- a/projects/f-flow/src/domain/get-element-rect-in-flow/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-element-rect-in-flow.execution'; - -export * from './get-element-rect-in-flow-request'; diff --git a/projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element-request.ts b/projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect-request.ts similarity index 58% rename from projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element-request.ts rename to projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect-request.ts index 567e3e10..2bf2a74b 100644 --- a/projects/f-flow/src/domain/create-rounded-rect-from-element/create-rounded-rect-from-element-request.ts +++ b/projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect-request.ts @@ -1,4 +1,4 @@ -export class CreateRoundedRectFromElementRequest { +export class GetElementRoundedRectRequest { constructor( public element: HTMLElement | SVGElement, ) { diff --git a/projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect.execution.ts b/projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect.execution.ts new file mode 100644 index 00000000..8fbedb2d --- /dev/null +++ b/projects/f-flow/src/domain/get-element-rounded-rect/get-element-rounded-rect.execution.ts @@ -0,0 +1,39 @@ +import { inject, Injectable } from '@angular/core'; +import { GetElementRoundedRectRequest } from './get-element-rounded-rect-request'; +import { FExecutionRegister, IExecution } from '@foblex/mediator'; +import { BrowserService } from '@foblex/platform'; +import { RoundedRect, RectExtensions, IRect } from '@foblex/2d'; + +@Injectable() +@FExecutionRegister(GetElementRoundedRectRequest) +export class GetElementRoundedRectExecution implements IExecution { + + private _fBrowser = inject(BrowserService); + + public handle(request: GetElementRoundedRectRequest): RoundedRect { + return this._getRoundedRect( + RectExtensions.fromElement(request.element), request.element, this._getComputedStyle(request.element) + ); + } + + private _getRoundedRect(rect: IRect, element: HTMLElement | SVGElement, styles: CSSStyleDeclaration): RoundedRect { + return new RoundedRect( + rect.x, + rect.y, + rect.width, + rect.height, + this._toPixels(styles.borderTopLeftRadius, element, styles.fontSize), + this._toPixels(styles.borderTopRightRadius, element, styles.fontSize), + this._toPixels(styles.borderBottomRightRadius, element, styles.fontSize), + this._toPixels(styles.borderBottomLeftRadius, element, styles.fontSize) + ); + } + + private _getComputedStyle(element: HTMLElement | SVGElement): CSSStyleDeclaration { + return this._fBrowser.window.getComputedStyle(element); + } + + private _toPixels(value: string, element: HTMLElement | SVGElement, fontSize: string): number { + return this._fBrowser.toPixels(value, element.clientWidth, element.clientHeight, fontSize) || 0 + } +} diff --git a/projects/f-flow/src/domain/get-element-rounded-rect/index.ts b/projects/f-flow/src/domain/get-element-rounded-rect/index.ts new file mode 100644 index 00000000..55818da2 --- /dev/null +++ b/projects/f-flow/src/domain/get-element-rounded-rect/index.ts @@ -0,0 +1,3 @@ +export * from './get-element-rounded-rect.execution'; + +export * from './get-element-rounded-rect-request'; diff --git a/projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow-request.ts b/projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect-request.ts similarity index 63% rename from projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow-request.ts rename to projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect-request.ts index bf13ba97..6051e1c2 100644 --- a/projects/f-flow/src/domain/get-element-rect-in-flow/get-element-rect-in-flow-request.ts +++ b/projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect-request.ts @@ -1,4 +1,4 @@ -export class GetElementRectInFlowRequest { +export class GetNormalizedElementRectRequest { constructor( public element: HTMLElement | SVGElement ) { diff --git a/projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect.execution.ts b/projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect.execution.ts new file mode 100644 index 00000000..32ccc56f --- /dev/null +++ b/projects/f-flow/src/domain/get-normalized-element-rect/get-normalized-element-rect.execution.ts @@ -0,0 +1,43 @@ +import { inject, Injectable } from '@angular/core'; +import { GetNormalizedElementRectRequest } from './get-normalized-element-rect-request'; +import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator'; +import { FComponentsStore } from '../../f-storage'; +import { IRoundedRect, RoundedRect, IPoint, ISize, Point, SizeExtensions, ITransformModel } from '@foblex/2d'; +import { GetElementRoundedRectRequest } from '../get-element-rounded-rect'; + +@Injectable() +@FExecutionRegister(GetNormalizedElementRectRequest) +export class GetNormalizedElementRectExecution implements IExecution { + + private _fComponentsStore = inject(FComponentsStore); + private _fMediator = inject(FMediator); + + private get _transform(): ITransformModel { + return this._fComponentsStore.fCanvas!.transform; + } + + public handle(request: GetNormalizedElementRectRequest): IRoundedRect { + const systemRect = this._getElementRoundedRect(request.element); + const position = this._normalizePosition(systemRect); + const size = this._normalizeSize(systemRect); + + return new RoundedRect( + position.x, position.y, size.width, size.height, + systemRect.radius1, systemRect.radius2, systemRect.radius3, systemRect.radius4 + ); + } + + private _getElementRoundedRect(element: HTMLElement | SVGElement): IRoundedRect { + return this._fMediator.send( + new GetElementRoundedRectRequest(element) + ); + } + + private _normalizePosition(rect: IRoundedRect): IPoint { + return Point.fromPoint(rect).elementTransform(this._fComponentsStore.flowHost).sub(this._transform.scaledPosition).sub(this._transform.position).div(this._transform.scale); + } + + private _normalizeSize(rect: IRoundedRect): ISize { + return SizeExtensions.initialize(rect.width / this._transform.scale, rect.height / this._transform.scale); + } +} diff --git a/projects/f-flow/src/domain/get-normalized-element-rect/index.ts b/projects/f-flow/src/domain/get-normalized-element-rect/index.ts new file mode 100644 index 00000000..4bb869ac --- /dev/null +++ b/projects/f-flow/src/domain/get-normalized-element-rect/index.ts @@ -0,0 +1,3 @@ +export * from './get-normalized-element-rect.execution'; + +export * from './get-normalized-element-rect-request'; diff --git a/projects/f-flow/src/domain/get-normalized-point/get-normalized-point-request.ts b/projects/f-flow/src/domain/get-normalized-point/get-normalized-point-request.ts new file mode 100644 index 00000000..f63b08c0 --- /dev/null +++ b/projects/f-flow/src/domain/get-normalized-point/get-normalized-point-request.ts @@ -0,0 +1,8 @@ +import { IPoint } from '@foblex/2d'; + +export class GetNormalizedPointRequest { + constructor( + public position: IPoint + ) { + } +} diff --git a/projects/f-flow/src/domain/get-normalized-point/get-normalized-point.execution.ts b/projects/f-flow/src/domain/get-normalized-point/get-normalized-point.execution.ts new file mode 100644 index 00000000..25d75412 --- /dev/null +++ b/projects/f-flow/src/domain/get-normalized-point/get-normalized-point.execution.ts @@ -0,0 +1,21 @@ +import { IPoint, ITransformModel, Point } from '@foblex/2d'; +import { inject, Injectable } from '@angular/core'; +import { GetNormalizedPointRequest } from './get-normalized-point-request'; +import { FComponentsStore } from '../../f-storage'; +import { FExecutionRegister, IExecution } from '@foblex/mediator'; + +@Injectable() +@FExecutionRegister(GetNormalizedPointRequest) +export class GetNormalizedPointExecution implements IExecution { + + private _fComponentsStore = inject(FComponentsStore); + + private get _transform(): ITransformModel { + return this._fComponentsStore.fCanvas!.transform; + } + + public handle(request: GetNormalizedPointRequest): IPoint { + return Point.fromPoint(request.position).elementTransform(this._fComponentsStore.flowHost) + .sub(this._transform.scaledPosition).sub(this._transform.position).div(this._transform.scale); + } +} diff --git a/projects/f-flow/src/domain/get-normalized-point/index.ts b/projects/f-flow/src/domain/get-normalized-point/index.ts new file mode 100644 index 00000000..542250de --- /dev/null +++ b/projects/f-flow/src/domain/get-normalized-point/index.ts @@ -0,0 +1,3 @@ +export * from './get-normalized-point.execution'; + +export * from './get-normalized-point-request'; diff --git a/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow-request.ts b/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow-request.ts deleted file mode 100644 index b4ac8121..00000000 --- a/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow-request.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPoint } from '@foblex/2d'; - -export class GetPositionInFlowRequest { - constructor( - public position: IPoint - ) { - } -} diff --git a/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow.execution.ts b/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow.execution.ts deleted file mode 100644 index ec4ee6bc..00000000 --- a/projects/f-flow/src/domain/get-position-in-flow/get-position-in-flow.execution.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IPoint, ITransformModel, Point } from '@foblex/2d'; -import { Injectable } from '@angular/core'; -import { GetPositionInFlowRequest } from './get-position-in-flow-request'; -import { FComponentsStore } from '../../f-storage'; -import { FExecutionRegister, IExecution } from '@foblex/mediator'; - -@Injectable() -@FExecutionRegister(GetPositionInFlowRequest) -export class GetPositionInFlowExecution implements IExecution { - - private get transform(): ITransformModel { - return this.fComponentsStore.fCanvas!.transform; - } - - private get flowHost(): HTMLElement { - return this.fComponentsStore.flowHost; - } - - constructor( - private fComponentsStore: FComponentsStore, - ) { - } - - public handle(request: GetPositionInFlowRequest): IPoint { - return Point.fromPoint(request.position).elementTransform(this.flowHost) - .sub(this.transform.scaledPosition).sub(this.transform.position).div(this.transform.scale); - } -} diff --git a/projects/f-flow/src/domain/get-position-in-flow/index.ts b/projects/f-flow/src/domain/get-position-in-flow/index.ts deleted file mode 100644 index f1e19205..00000000 --- a/projects/f-flow/src/domain/get-position-in-flow/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-position-in-flow.execution'; - -export * from './get-position-in-flow-request'; diff --git a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.execution.ts b/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.execution.ts deleted file mode 100644 index 10fc3732..00000000 --- a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.execution.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IRect, RectExtensions } from '@foblex/2d'; -import { GetScaledNodeRectsWithFlowPositionRequest } from './get-scaled-node-rects-with-flow-position.request'; -import { Injectable } from '@angular/core'; -import { FComponentsStore } from '../../f-storage'; -import { FExecutionRegister, IExecution } from '@foblex/mediator'; -import { FNodeBase } from '../../f-node'; - -@Injectable() -@FExecutionRegister(GetScaledNodeRectsWithFlowPositionRequest) -export class GetScaledNodeRectsWithFlowPositionExecution implements IExecution { - - constructor( - private fComponentsStore: FComponentsStore, - ) { - } - - public handle(request: GetScaledNodeRectsWithFlowPositionRequest): IRect | null { - return RectExtensions.union(this.getNodesRects()); - } - - private getNodesRects(): IRect[] { - return this.getNodes().map((x) => { - const rect = RectExtensions.fromElement(x.hostElement); - return RectExtensions.initialize(x.position.x, x.position.y, rect.width, rect.height); - }); - } - - private getNodes(): FNodeBase[] { - return this.fComponentsStore.fNodes; - } -} diff --git a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.request.ts b/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.request.ts deleted file mode 100644 index 2a30da4f..00000000 --- a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/get-scaled-node-rects-with-flow-position.request.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class GetScaledNodeRectsWithFlowPositionRequest { - -} diff --git a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/index.ts b/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/index.ts deleted file mode 100644 index 9665cb10..00000000 --- a/projects/f-flow/src/domain/get-scaled-node-rects-with-flow-position/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './get-scaled-node-rects-with-flow-position.execution'; - -export * from './get-scaled-node-rects-with-flow-position.request'; diff --git a/projects/f-flow/src/domain/index.ts b/projects/f-flow/src/domain/index.ts index a309781b..cf0a03c7 100644 --- a/projects/f-flow/src/domain/index.ts +++ b/projects/f-flow/src/domain/index.ts @@ -1,4 +1,4 @@ -export * from './create-rounded-rect-from-element'; +export * from './get-element-rounded-rect'; export * from './f-background'; @@ -18,19 +18,11 @@ export * from './f-node'; export * from './f-selection'; -export * from './get-can-be-selected-items'; - export * from './get-deep-children-nodes-and-groups'; -export * from './get-connection-line'; - -export * from './get-element-rect-in-flow'; - -export * from './get-flow-state'; - -export * from './get-scaled-node-rects-with-flow-position'; +export * from './get-normalized-element-rect'; -export * from './get-position-in-flow'; +export * from './get-normalized-point'; export * from './sort-item-layers'; diff --git a/projects/f-flow/src/domain/providers.ts b/projects/f-flow/src/domain/providers.ts index 2f0818fa..dbc197cc 100644 --- a/projects/f-flow/src/domain/providers.ts +++ b/projects/f-flow/src/domain/providers.ts @@ -1,16 +1,12 @@ -import { GetConnectionLineExecution } from './get-connection-line'; -import { GetElementRectInFlowExecution } from './get-element-rect-in-flow'; +import { GetNormalizedElementRectExecution } from './get-normalized-element-rect'; import { MoveFrontElementsBeforeTargetElementExecution, UpdateItemAndChildrenLayersExecution } from './update-item-and-children-layers'; -import { GetPositionInFlowExecution } from './get-position-in-flow'; -import { GetCanBeSelectedItemsExecution } from './get-can-be-selected-items'; -import { GetScaledNodeRectsWithFlowPositionExecution } from './get-scaled-node-rects-with-flow-position'; +import { GetNormalizedPointExecution } from './get-normalized-point'; import { SortItemLayersExecution, SortItemsByParentExecution, SortNodeLayersExecution } from './sort-item-layers'; import { GetDeepChildrenNodesAndGroupsExecution } from './get-deep-children-nodes-and-groups'; -import { CreateRoundedRectFromElementExecution } from './create-rounded-rect-from-element'; -import { GET_FLOW_STATE_PROVIDERS } from './get-flow-state'; +import { GetElementRoundedRectExecution } from './get-element-rounded-rect'; import { F_SELECTION_FEATURES } from './f-selection'; import { F_BACKGROUND_FEATURES } from './f-background'; import { F_CANVAS_FEATURES } from './f-canvas'; @@ -39,23 +35,15 @@ export const COMMON_PROVIDERS = [ ...F_NODE_FEATURES, - CreateRoundedRectFromElementExecution, + GetElementRoundedRectExecution, ...F_SELECTION_FEATURES, - GetCanBeSelectedItemsExecution, - GetDeepChildrenNodesAndGroupsExecution, - GetConnectionLineExecution, - - GetElementRectInFlowExecution, - - ...GET_FLOW_STATE_PROVIDERS, - - GetScaledNodeRectsWithFlowPositionExecution, + GetNormalizedElementRectExecution, - GetPositionInFlowExecution, + GetNormalizedPointExecution, SortItemLayersExecution, diff --git a/projects/f-flow/src/f-draggable/connections/create-connection/create-connection.drag-handler.ts b/projects/f-flow/src/f-draggable/connections/create-connection/create-connection.drag-handler.ts index d228a087..fbcf260e 100644 --- a/projects/f-flow/src/f-draggable/connections/create-connection/create-connection.drag-handler.ts +++ b/projects/f-flow/src/f-draggable/connections/create-connection/create-connection.drag-handler.ts @@ -2,7 +2,7 @@ import { IDraggableItem } from '../../i-draggable-item'; import { FindClosestInputUsingSnapThresholdRequest, GetAllCanBeConnectedInputPositionsRequest, - GetConnectionLineRequest, + CalculateConnectionLineByBehaviorRequest, GetConnectorWithRectRequest, IConnectorWithRect } from '../../../domain'; @@ -66,7 +66,7 @@ export class CreateConnectionDragHandler implements IDraggableItem { } private drawTempConnection(fInputRect: RoundedRect): void { - const line = this.fMediator.send(new GetConnectionLineRequest( + const line = this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( this.fOutputWithRect.fRect, fInputRect, this.fConnection.fBehavior, @@ -81,7 +81,7 @@ export class CreateConnectionDragHandler implements IDraggableItem { private drawSnapConnection(fInputWithRect: IConnectorWithRect | undefined): void { if (fInputWithRect) { - const line = this.fMediator.send(new GetConnectionLineRequest( + const line = this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( this.fOutputWithRect.fRect, fInputWithRect.fRect, this.fSnapConnection!.fBehavior, diff --git a/projects/f-flow/src/f-draggable/connections/reassign-connection/reassign-connection.drag-handler.ts b/projects/f-flow/src/f-draggable/connections/reassign-connection/reassign-connection.drag-handler.ts index 745583dc..c6124187 100644 --- a/projects/f-flow/src/f-draggable/connections/reassign-connection/reassign-connection.drag-handler.ts +++ b/projects/f-flow/src/f-draggable/connections/reassign-connection/reassign-connection.drag-handler.ts @@ -2,7 +2,7 @@ import { IDraggableItem } from '../../i-draggable-item'; import { FindClosestInputUsingSnapThresholdRequest, GetAllCanBeConnectedInputPositionsRequest, - GetConnectionLineRequest, GetConnectorWithRectRequest, + CalculateConnectionLineByBehaviorRequest, GetConnectorWithRectRequest, IConnectorWithRect } from '../../../domain'; import { FConnectionBase, FSnapConnectionComponent } from '../../../f-connection'; @@ -66,7 +66,7 @@ export class ReassignConnectionDragHandler implements IDraggableItem { } private drawConnection(fInputWithRect: IConnectorWithRect): void { - const line = this.fMediator.send(new GetConnectionLineRequest( + const line = this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( this.fOutputWithRect.fRect, fInputWithRect.fRect, this.fConnection.fBehavior, @@ -81,7 +81,7 @@ export class ReassignConnectionDragHandler implements IDraggableItem { private drawSnapConnection(fInputWithRect: IConnectorWithRect | undefined): void { if (fInputWithRect) { - const line = this.fMediator.send(new GetConnectionLineRequest( + const line = this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( this.fOutputWithRect.fRect, fInputWithRect.fRect, this.fSnapConnection!.fBehavior, diff --git a/projects/f-flow/src/f-draggable/domain/is-connection-under-node/is-connection-under-node.execution.ts b/projects/f-flow/src/f-draggable/domain/is-connection-under-node/is-connection-under-node.execution.ts index 388ab9f4..2a75627c 100644 --- a/projects/f-flow/src/f-draggable/domain/is-connection-under-node/is-connection-under-node.execution.ts +++ b/projects/f-flow/src/f-draggable/domain/is-connection-under-node/is-connection-under-node.execution.ts @@ -7,7 +7,7 @@ import { FDraggableDataContext, FNodeIntersectedWithConnections, NodeDragHandler import { FNodeBase } from '../../../f-node'; import { FConnectorBase } from '../../../f-connectors'; import { FConnectionBase } from '../../../f-connection'; -import { GetElementRectInFlowRequest } from '../../../domain'; +import { GetNormalizedElementRectRequest } from '../../../domain'; @Injectable() @FExecutionRegister(IsConnectionUnderNodeRequest) @@ -80,7 +80,7 @@ export class IsConnectionUnderNodeExecution implements IExecution(new GetElementRectInFlowRequest(fNode.hostElement)); + const fNodeRect = this._fMediator.send(new GetNormalizedElementRectRequest(fNode.hostElement)); return this._fComponentsStore.fConnections.filter((x) => { return this._isConnectionHasIntersectionsWithNode(x, fNodeRect); }); diff --git a/projects/f-flow/src/f-draggable/f-selection-change-event.ts b/projects/f-flow/src/f-draggable/f-selection-change-event.ts index 1c888111..cf5c40f9 100644 --- a/projects/f-flow/src/f-draggable/f-selection-change-event.ts +++ b/projects/f-flow/src/f-draggable/f-selection-change-event.ts @@ -1,7 +1,10 @@ -export class FSelectionChangeEvent { +import { ICurrentSelection } from '../domain'; + +export class FSelectionChangeEvent implements ICurrentSelection{ constructor( public nodes: string[], + public groups: string[], public connections: string[], ) { } diff --git a/projects/f-flow/src/f-draggable/node/connection-source.drag-handler.ts b/projects/f-flow/src/f-draggable/node/connection-source.drag-handler.ts index ec2d2597..0759ec8c 100644 --- a/projects/f-flow/src/f-draggable/node/connection-source.drag-handler.ts +++ b/projects/f-flow/src/f-draggable/node/connection-source.drag-handler.ts @@ -1,6 +1,6 @@ import { ILine, IPoint, RoundedRect } from '@foblex/2d'; import { - GetConnectionLineRequest + CalculateConnectionLineByBehaviorRequest } from '../../domain'; import { FConnectionBase } from '../../f-connection'; import { FMediator } from '@foblex/mediator'; @@ -24,7 +24,7 @@ export class ConnectionSourceDragHandler extends ConnectionBaseDragHandler { } private getNewLineValue(difference: IPoint): ILine { - return this.fMediator.send(new GetConnectionLineRequest( + return this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( RoundedRect.fromRoundedRect(this.fOutputWithRect.fRect).addPoint(this.getDifference({ ...difference }, { min: this.minDistance, max: this.maxDistance })), RoundedRect.fromRoundedRect(this.fInputWithRect.fRect), this.connection.fBehavior, diff --git a/projects/f-flow/src/f-draggable/node/connection-target.drag-handler.ts b/projects/f-flow/src/f-draggable/node/connection-target.drag-handler.ts index 33a604d9..0f394e0b 100644 --- a/projects/f-flow/src/f-draggable/node/connection-target.drag-handler.ts +++ b/projects/f-flow/src/f-draggable/node/connection-target.drag-handler.ts @@ -1,6 +1,6 @@ import { ILine, IPoint, RoundedRect } from '@foblex/2d'; import { - GetConnectionLineRequest, + CalculateConnectionLineByBehaviorRequest, } from '../../domain'; import { FConnectionBase } from '../../f-connection'; import { FMediator } from '@foblex/mediator'; @@ -24,7 +24,7 @@ export class ConnectionTargetDragHandler extends ConnectionBaseDragHandler { } private getNewLineValue(difference: IPoint): ILine { - return this.fMediator.send(new GetConnectionLineRequest( + return this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( RoundedRect.fromRoundedRect(this.fOutputWithRect.fRect), RoundedRect.fromRoundedRect(this.fInputWithRect.fRect).addPoint(this.getDifference({ ...difference }, { min: this.minDistance, max: this.maxDistance })), this.connection.fBehavior, diff --git a/projects/f-flow/src/f-draggable/node/connection.drag-handler.ts b/projects/f-flow/src/f-draggable/node/connection.drag-handler.ts index 7ac77fa9..415c0d1f 100644 --- a/projects/f-flow/src/f-draggable/node/connection.drag-handler.ts +++ b/projects/f-flow/src/f-draggable/node/connection.drag-handler.ts @@ -2,7 +2,7 @@ import { ILine, IPoint, RoundedRect } from '@foblex/2d'; import { FConnectionBase } from '../../f-connection'; import { FMediator } from '@foblex/mediator'; import { - GetConnectionLineRequest, + CalculateConnectionLineByBehaviorRequest, } from '../../domain'; import { ConnectionBaseDragHandler } from './connection-base-drag-handler'; import { INodeMoveRestrictions } from './create-move-nodes-drag-model-from-selection'; @@ -34,7 +34,7 @@ export class ConnectionDragHandler extends ConnectionBaseDragHandler { } private getNewLineValue(difference: IPoint): ILine { - return this.fMediator.send(new GetConnectionLineRequest( + return this.fMediator.send(new CalculateConnectionLineByBehaviorRequest( RoundedRect.fromRoundedRect(this.fOutputWithRect.fRect).addPoint(this.getDifference({ ...difference }, this.sourceRestrictions)), RoundedRect.fromRoundedRect(this.fInputWithRect.fRect).addPoint(this.getDifference({ ...difference }, this.targetRestrictions)), this.connection.fBehavior, diff --git a/projects/f-flow/src/f-draggable/node/node-drag-to-parent-preparation/node-drag-to-parent-preparation.execution.ts b/projects/f-flow/src/f-draggable/node/node-drag-to-parent-preparation/node-drag-to-parent-preparation.execution.ts index 19630ce5..97d03dfb 100644 --- a/projects/f-flow/src/f-draggable/node/node-drag-to-parent-preparation/node-drag-to-parent-preparation.execution.ts +++ b/projects/f-flow/src/f-draggable/node/node-drag-to-parent-preparation/node-drag-to-parent-preparation.execution.ts @@ -4,7 +4,7 @@ import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator'; import { FComponentsStore } from '../../../f-storage'; import { INodeWithRect } from '../../domain'; import { IPoint, IRect, ITransformModel, PointExtensions, RectExtensions } from '@foblex/2d'; -import { GetElementRectInFlowRequest } from '../../../domain'; +import { GetNormalizedElementRectRequest } from '../../../domain'; import { FNodeBase } from '../../../f-node'; import { FDraggableDataContext } from '../../f-draggable-data-context'; import { NodeDragToParentDragHandler } from '../node-drag-to-parent.drag-handler'; @@ -51,7 +51,7 @@ export class NodeDragToParentPreparationExecution private getNotDraggedNodesRects(): INodeWithRect[] { return this.getNotDraggedNodes(this.getDraggedNodes()).map((x) => { - const rect = this.fMediator.send(new GetElementRectInFlowRequest(x.hostElement)); + const rect = this.fMediator.send(new GetNormalizedElementRectRequest(x.hostElement)); return { node: x, rect: RectExtensions.initialize( diff --git a/projects/f-flow/src/f-external-item/domain/external-item-finalize/external-item-finalize.execution.ts b/projects/f-flow/src/f-external-item/domain/external-item-finalize/external-item-finalize.execution.ts index b961f71e..4f448272 100644 --- a/projects/f-flow/src/f-external-item/domain/external-item-finalize/external-item-finalize.execution.ts +++ b/projects/f-flow/src/f-external-item/domain/external-item-finalize/external-item-finalize.execution.ts @@ -5,7 +5,7 @@ import { FExecutionRegister, FMediator, IExecution } from '@foblex/mediator'; import { FComponentsStore } from '../../../f-storage'; import { ExternalItemDragHandler } from '../external-item.drag-handler'; import { FCreateNodeEvent } from '../f-create-node.event'; -import { GetElementRectInFlowRequest } from '../../../domain'; +import { GetNormalizedElementRectRequest } from '../../../domain'; import { FDraggableDataContext } from '../../../f-draggable'; import { BrowserService } from '@foblex/platform'; @@ -59,6 +59,6 @@ export class ExternalItemFinalizeExecution implements IExecution(new GetElementRectInFlowRequest(this.dragHandler.placeholder!)); + return this.fMediator.send(new GetNormalizedElementRectRequest(this.dragHandler.placeholder!)); } } diff --git a/projects/f-flow/src/f-flow/f-flow.component.ts b/projects/f-flow/src/f-flow/f-flow.component.ts index 8134d092..5ac3af93 100644 --- a/projects/f-flow/src/f-flow/f-flow.component.ts +++ b/projects/f-flow/src/f-flow/f-flow.component.ts @@ -7,19 +7,19 @@ import { import { F_FLOW, FFlowBase } from './f-flow-base'; import { ClearSelectionRequest, - GetScaledNodeRectsWithFlowPositionRequest, - GetPositionInFlowRequest, - GetSelectionRequest, + CalculateNodesBoundingBoxNormalizedPositionRequest, + GetNormalizedPointRequest, + GetCurrentSelectionRequest, RedrawConnectionsRequest, SelectAllRequest, SelectRequest, IFFlowState, - GetFlowStateRequest, RemoveFlowFromStoreRequest, AddFlowToStoreRequest, SortItemLayersRequest + GetFlowStateRequest, RemoveFlowFromStoreRequest, AddFlowToStoreRequest, SortItemLayersRequest, ICurrentSelection } from '../domain'; import { IPoint, IRect } from '@foblex/2d'; import { FMediator } from '@foblex/mediator'; import { - FDraggableDataContext, FSelectionChangeEvent + FDraggableDataContext } from '../f-draggable'; import { FConnectionFactory } from '../f-connection'; import { @@ -125,16 +125,16 @@ export class FFlowComponent extends FFlowBase implements OnInit, AfterContentIni this._isLoaded = false; } - public getAllNodesRect(): IRect | null { - return this._fMediator.send(new GetScaledNodeRectsWithFlowPositionRequest()); + public getNodesBoundingBox(): IRect | null { + return this._fMediator.send(new CalculateNodesBoundingBoxNormalizedPositionRequest()); } - public getSelection(): FSelectionChangeEvent { - return this._fMediator.send(new GetSelectionRequest()); + public getSelection(): ICurrentSelection { + return this._fMediator.send(new GetCurrentSelectionRequest()); } public getPositionInFlow(position: IPoint): IRect { - return this._fMediator.send(new GetPositionInFlowRequest(position)); + return this._fMediator.send(new GetNormalizedPointRequest(position)); } public getState(): IFFlowState { diff --git a/projects/f-flow/src/f-line-alignment/f-line-alignment.component.ts b/projects/f-flow/src/f-line-alignment/f-line-alignment.component.ts index 2c301964..fa34d3e7 100644 --- a/projects/f-flow/src/f-line-alignment/f-line-alignment.component.ts +++ b/projects/f-flow/src/f-line-alignment/f-line-alignment.component.ts @@ -4,7 +4,7 @@ import { ILineAlignmentResult, LineService, NearestCoordinateFinder } from './do import { F_LINE_ALIGNMENT, FLineAlignmentBase } from './f-line-alignment-base'; import { FDraggableDataContext } from '../f-draggable'; import { FNodeBase } from '../f-node'; -import { GetCanvasRequest, GetElementRectInFlowRequest, GetFlowHostElementRequest } from '../domain'; +import { GetCanvasRequest, GetNormalizedElementRectRequest, GetFlowHostElementRequest } from '../domain'; import { FMediator } from '@foblex/mediator'; import { BrowserService } from '@foblex/platform'; import { FCanvasBase } from '../f-canvas'; @@ -68,7 +68,7 @@ export class FLineAlignmentComponent extends FLineAlignmentBase implements After this.size = this._fFlowHostElement.getBoundingClientRect(); this.rects = []; const draggedNodeRects = currentNodes.map((x) => { - return this._fMediator.send(new GetElementRectInFlowRequest(x.hostElement)); + return this._fMediator.send(new GetNormalizedElementRectRequest(x.hostElement)); }); this.draggedNodeRect = RectExtensions.union(draggedNodeRects) || RectExtensions.initialize(); @@ -77,7 +77,7 @@ export class FLineAlignmentComponent extends FLineAlignmentBase implements After }); this.rects = allNodesExcludeCurrents.map((x) => { - return this._fMediator.send(new GetElementRectInFlowRequest(x.hostElement)); + return this._fMediator.send(new GetNormalizedElementRectRequest(x.hostElement)); }); } diff --git a/projects/f-flow/src/f-selection-area/domain/selection-area.drag-handle.ts b/projects/f-flow/src/f-selection-area/domain/selection-area.drag-handle.ts index 7b470165..6d77a7d4 100644 --- a/projects/f-flow/src/f-selection-area/domain/selection-area.drag-handle.ts +++ b/projects/f-flow/src/f-selection-area/domain/selection-area.drag-handle.ts @@ -1,20 +1,19 @@ import { IPoint, Point, RectExtensions } from '@foblex/2d'; import { FComponentsStore, NotifyTransformChangedRequest } from '../../f-storage'; -import { ISelectableWithRect } from '../../domain'; +import { GetCanBeSelectedItemsRequest, ICanBeSelected } from '../../domain'; import { FMediator } from '@foblex/mediator'; -import { GetCanBeSelectedItemsRequest } from '../../domain/get-can-be-selected-items/get-can-be-selected-items-request'; import { FDraggableDataContext, IDraggableItem } from '../../f-draggable'; import { FSelectionAreaBase } from '../f-selection-area-base'; import { ICanChangeSelection } from '../../mixins'; export class SelectionAreaDragHandle implements IDraggableItem { - private canBeSelected: ISelectableWithRect[] = []; - - private selectedByMove: ICanChangeSelection[] = []; + private _canBeSelected: ICanBeSelected[] = []; + private _selectedByMove: ICanChangeSelection[] = []; private get canvasPosition(): Point { - return Point.fromPoint(this.fComponentsStore.fCanvas!.transform.position).add(this.fComponentsStore.fCanvas!.transform.scaledPosition); + return Point.fromPoint(this.fComponentsStore.fCanvas!.transform.position) + .add(this.fComponentsStore.fCanvas!.transform.scaledPosition); } constructor( @@ -26,7 +25,7 @@ export class SelectionAreaDragHandle implements IDraggableItem { } public prepareDragSequence(): void { - this.canBeSelected = this.fMediator.send(new GetCanBeSelectedItemsRequest()); + this._canBeSelected = this.fMediator.send(new GetCanBeSelectedItemsRequest()); this.fSelectionArea.show(); this.fSelectionArea.draw( @@ -48,8 +47,8 @@ export class SelectionAreaDragHandle implements IDraggableItem { this.fSelectionArea.draw( RectExtensions.initialize(x, y, width, height) ); - this.selectedByMove = []; - this.canBeSelected.forEach((item) => { + this._selectedByMove = []; + this._canBeSelected.forEach((item) => { item.element.deselect(); const itemRect = RectExtensions.addPoint(item.rect, this.canvasPosition); @@ -58,7 +57,7 @@ export class SelectionAreaDragHandle implements IDraggableItem { if (isIntersect) { item.element.select(); - this.selectedByMove.push(item.element); + this._selectedByMove.push(item.element); } }); this.fMediator.send(new NotifyTransformChangedRequest()); @@ -66,8 +65,8 @@ export class SelectionAreaDragHandle implements IDraggableItem { public onPointerUp(): void { this.fSelectionArea.hide(); - this.fDraggableDataContext.selectedItems.push(...this.selectedByMove); - if (this.selectedByMove.length > 0) { + this.fDraggableDataContext.selectedItems.push(...this._selectedByMove); + if (this._selectedByMove.length > 0) { this.fDraggableDataContext.isSelectedChanged = true; } } diff --git a/src/app/home-page/home-page-background/home-page-background.component.ts b/src/app/home-page/home-page-background/home-page-background.component.ts index 190348fc..0fcc0270 100644 --- a/src/app/home-page/home-page-background/home-page-background.component.ts +++ b/src/app/home-page/home-page-background/home-page-background.component.ts @@ -84,7 +84,7 @@ export class HomePageBackgroundComponent implements OnInit, OnDestroy { private modifyPosition(): void { const result = new GetNewCanvasTransformHandler(this.fBrowser).handle( - new GetNewCanvasTransformRequest(this.fFlowComponent.getAllNodesRect() || RectExtensions.initialize()) + new GetNewCanvasTransformRequest(this.fFlowComponent.getNodesBoundingBox() || RectExtensions.initialize()) ); this.scale = result.scale; this.canvasPosition = result.position;