Skip to content

Commit 669568e

Browse files
Merge pull request #123 from Foblex/f-draggable-refactoring
F draggable refactoring
2 parents b7864fa + 1681e47 commit 669568e

File tree

174 files changed

+1535
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+1535
-1151
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@foblex/m-render": "2.5.4",
7272
"@foblex/mediator": "1.1.2",
7373
"@foblex/platform": "1.0.4",
74-
"@foblex/utils": "1.1.0",
74+
"@foblex/utils": "1.1.1",
7575
"dagre": "^0.8.5",
7676
"elkjs": "^0.9.3",
7777
"express": "^4.18.2",

projects/f-examples/_flow-common.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,20 @@
216216
line-height: normal;
217217
}
218218
}
219+
220+
@mixin overlay {
221+
overflow: auto;
222+
width: 260px;
223+
height: calc(100% - 20px);
224+
position: absolute;
225+
padding: 10px;
226+
right: 10px;
227+
top: 10px;
228+
font-size: 12px;
229+
border-radius: 4px;
230+
background-color: var(--node-background-color);
231+
box-shadow: var(--node-shadow);
232+
display: flex;
233+
flex-direction: column;
234+
gap: 10px;
235+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<f-flow fDraggable
2+
(fLoaded)="onLoaded()"
3+
(fDragStarted)="onDragStarted($event)"
4+
(fDragEnded)="onDragEnded()"
5+
(fCreateConnection)="onConnectionCreated($event)"
6+
(fReassignConnection)="onConnectionReassigned($event)">
7+
<f-canvas fZoom>
8+
<f-connection-for-create fBehavior="fixed" fType="segment">
9+
<svg viewBox="0 0 6 7" fMarker [type]="eMarkerType.END" class="connection-marker"
10+
[height]="7" [width]="6"
11+
[refX]="5.5" [refY]="3.5" markerUnits="strokeWidth" orient="auto">
12+
<path d="M0.000391006 0L6 3.5L0.000391006 7L0.000391006 0Z"/>
13+
</svg>
14+
<svg viewBox="0 0 6 7" fMarker [type]="eMarkerType.SELECTED_END" class="connection-marker"
15+
[height]="7" [width]="6"
16+
[refX]="5.5" [refY]="3.5" markerUnits="strokeWidth" orient="auto">
17+
<path d="M0.000391006 0L6 3.5L0.000391006 7L0.000391006 0Z"/>
18+
</svg>
19+
</f-connection-for-create>
20+
@for (connection of connections; track connection.id) {
21+
<f-connection [fConnectionId]="connection.id"
22+
[fOutputId]="connection.source"
23+
[fInputId]="connection.target" fBehavior="fixed" fType="segment">
24+
<svg viewBox="0 0 6 7" fMarker [type]="eMarkerType.END" class="connection-marker"
25+
[height]="7" [width]="6"
26+
[refX]="5.5" [refY]="3.5" markerUnits="strokeWidth" orient="auto">
27+
<path d="M0.000391006 0L6 3.5L0.000391006 7L0.000391006 0Z"/>
28+
</svg>
29+
<svg viewBox="0 0 6 7" fMarker [type]="eMarkerType.SELECTED_END" class="connection-marker"
30+
[height]="7" [width]="6"
31+
[refX]="5.5" [refY]="3.5" markerUnits="strokeWidth" orient="auto">
32+
<path d="M0.000391006 0L6 3.5L0.000391006 7L0.000391006 0Z"/>
33+
</svg>
34+
</f-connection>
35+
}
36+
@for (node of nodes; track node.id) {
37+
<div fNode [fNodePosition]="node.position"
38+
fDragHandle fConnectOnNode="false">{{ node.text }}
39+
<div fNodeInput fInputConnectableSide="left" class="left"></div>
40+
<div fNodeOutput [isSelfConnectable]="false" fOutputConnectableSide="top" class="top"></div>
41+
<div fNodeInput fInputConnectableSide="right" class="right"></div>
42+
<div fNodeOutput [isSelfConnectable]="false" fOutputConnectableSide="bottom" class="bottom"></div>
43+
</div>
44+
}
45+
</f-canvas>
46+
47+
</f-flow>
48+
<div class="overlay">
49+
<div>Event list:</div>
50+
@for (item of events; track item) {
51+
<div>{{ item }}</div>
52+
}
53+
</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@use "../../flow-common";
2+
3+
::ng-deep drag-start-end-events {
4+
@include flow-common.connection;
5+
6+
.connection-marker {
7+
circle, rect, path {
8+
fill: var(--connection-color);
9+
}
10+
}
11+
12+
.f-connection {
13+
&.f-selected {
14+
15+
.f-connection-path {
16+
stroke: var(--minimap-node-selected-color);
17+
}
18+
.connection-marker {
19+
circle, rect, path {
20+
fill: var(--minimap-node-selected-color);
21+
}
22+
}
23+
}
24+
}
25+
}
26+
27+
.f-node {
28+
@include flow-common.node;
29+
}
30+
31+
.f-node-input, .f-node-output {
32+
&:not(.f-node) {
33+
@include flow-common.connectors;
34+
}
35+
}
36+
37+
.f-node-output {
38+
&:not(.f-node) {
39+
border-radius: 4px;
40+
}
41+
}
42+
43+
.overlay {
44+
@include flow-common.overlay;
45+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {
2+
ChangeDetectionStrategy, ChangeDetectorRef,
3+
Component, inject,
4+
ViewChild
5+
} from '@angular/core';
6+
import {
7+
EFMarkerType,
8+
FCanvasComponent, FCreateConnectionEvent, FDragStartedEvent,
9+
FFlowModule, FReassignConnectionEvent,
10+
} from '@foblex/flow';
11+
import { generateGuid } from '@foblex/utils';
12+
13+
@Component({
14+
selector: 'drag-start-end-events',
15+
styleUrls: [ './drag-start-end-events.component.scss' ],
16+
templateUrl: './drag-start-end-events.component.html',
17+
changeDetection: ChangeDetectionStrategy.OnPush,
18+
standalone: true,
19+
imports: [
20+
FFlowModule,
21+
]
22+
})
23+
export class DragStartEndEventsComponent {
24+
private _changeDetectorRef = inject(ChangeDetectorRef);
25+
26+
@ViewChild(FCanvasComponent, { static: true })
27+
protected fCanvas!: FCanvasComponent;
28+
29+
protected readonly eMarkerType = EFMarkerType;
30+
31+
protected events: string[] = [];
32+
33+
protected nodes = [ {
34+
id: '1',
35+
position: { x: 0, y: 200 },
36+
text: 'Node 1',
37+
}, {
38+
id: '2',
39+
position: { x: 200, y: 200 },
40+
text: 'Node 2',
41+
} ];
42+
protected connections = [ {
43+
id: '1',
44+
source: 'f-node-output-0',
45+
target: 'f-node-input-2',
46+
} ];
47+
48+
protected onLoaded(): void {
49+
this.fCanvas.resetScaleAndCenter(false);
50+
}
51+
52+
protected onDragStarted(event: FDragStartedEvent): void {
53+
this.events.push(`EVENT: ${ event.fEventType }, DATA: ${ JSON.stringify(event.fData) }`);
54+
this._changeDetectorRef.markForCheck();
55+
}
56+
57+
protected onDragEnded(): void {
58+
this.events.push(`EVENT: drag-ended`);
59+
}
60+
61+
protected onConnectionCreated(event: FCreateConnectionEvent): void {
62+
console.log('onConnectionCreated', event);
63+
if (event.fInputId) {
64+
this._createConnection(event.fOutputId, event.fInputId);
65+
}
66+
}
67+
68+
protected onConnectionReassigned(event: FReassignConnectionEvent): void {
69+
if (event.newFInputId) {
70+
this._removeConnection(event.fConnectionId);
71+
this._createConnection(event.fOutputId, event.newFInputId);
72+
}
73+
}
74+
75+
private _removeConnection(connectionId: string): void {
76+
const index = this.connections.findIndex((x) => x.id === connectionId);
77+
this.connections.splice(index, 1);
78+
}
79+
80+
private _createConnection(source: string, target: string): void {
81+
this.connections.push({ id: generateGuid(), source, target });
82+
}
83+
}

0 commit comments

Comments
 (0)