You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2026/10/02 13:33:10 UTC
(streampipes) 01/01: refactor: Eliminate dependency on JQuery in pipeline editor
This is an automated email from the ASF dual-hosted git repository.
dominikriemer pushed a commit to branch eliminate-jquery-dependencies
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 12812e0266f906dff9bf78a6c54174ed2c428945
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Fri Oct 2 15:32:42 2026 +0200
refactor: Eliminate dependency on JQuery in pipeline editor
---
ui/angular.json | 6 +-
ui/package-lock.json | 35 -----
ui/package.json | 3 -
.../pipeline-assembly.component.html | 6 +-
.../pipeline-assembly.component.scss | 5 +
.../pipeline-assembly.component.ts | 2 +
.../pipeline-element-icon-stand-row.component.html | 17 +++
.../pipeline-element-icon-stand-row.component.scss | 2 +-
...peline-element-icon-stand-row.component.spec.ts | 135 +++++++++++++++++++
.../pipeline-element-icon-stand-row.component.ts | 24 ++++
.../pipeline-element-icon-stand.component.html | 3 +
.../pipeline-element-icon-stand.component.ts | 51 +------
.../components/pipeline/pipeline.component.spec.ts | 149 +++++++++++++++++++++
.../components/pipeline/pipeline.component.ts | 112 +++++++++-------
ui/src/app/editor/services/jsplumb.service.ts | 20 +--
.../services/pipeline-editor.service.spec.ts | 68 ++++++++++
.../app/editor/services/pipeline-editor.service.ts | 45 +++----
.../services/pipeline-positioning.service.ts | 27 ++--
.../editor/services/pipeline-validation.service.ts | 2 +-
ui/src/main.ts | 2 -
ui/src/scss/sp/main.scss | 4 -
ui/tsconfig.spec.json | 2 +-
22 files changed, 523 insertions(+), 197 deletions(-)
diff --git a/ui/angular.json b/ui/angular.json
index a575a9aaa0..949b2a72db 100644
--- a/ui/angular.json
+++ b/ui/angular.json
@@ -37,11 +37,7 @@
}
],
"styles": ["src/scss/main.scss"],
- "scripts": [
- "node_modules/jquery/dist/jquery.min.js",
- "node_modules/jquery-ui-dist/jquery-ui.js",
- "node_modules/quill/dist/quill.js"
- ]
+ "scripts": ["node_modules/quill/dist/quill.js"]
},
"configurations": {
"production": {
diff --git a/ui/package-lock.json b/ui/package-lock.json
index 0b749774e6..f0e572c98c 100644
--- a/ui/package-lock.json
+++ b/ui/package-lock.json
@@ -40,8 +40,6 @@
"echarts-simple-transform": "^1.0.0",
"file-saver": "2.0.5",
"gridstack": "^12.6.0",
- "jquery": "^3.7.0",
- "jquery-ui-dist": "1.13.2",
"katex": "^0.16.47",
"leaflet": "1.9.3",
"lodash.clonedeep": "^4.5.0",
@@ -75,7 +73,6 @@
"@angular/compiler-cli": "^22.1.6",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^10.0.1",
- "@types/jqueryui": "^1.12.16",
"@types/leaflet": "^1.9.0",
"@types/node": "^22.12.0",
"@typescript-eslint/eslint-plugin": "^8.46.1",
@@ -5474,23 +5471,6 @@
"integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==",
"license": "MIT"
},
- "node_modules/@types/jquery": {
- "version": "4.0.1",
- "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-4.0.1.tgz",
- "integrity": "sha512-9a59A/tycXgYuPABcp6/3spSShn0NT2UOM4EfHvMumjYi4lJWTsK5SZWjhx3yRm9IHGCeWXdV2YfNsrWrft/CA==",
- "dev": true,
- "license": "MIT"
- },
- "node_modules/@types/jqueryui": {
- "version": "1.12.24",
- "resolved": "https://registry.npmjs.org/@types/jqueryui/-/jqueryui-1.12.24.tgz",
- "integrity": "sha512-E2sGULwzMhg4kAeOV+gYcXjg988RuPkviWCt09jLe6GGK9sHM7dTqS8H7JMuUWoZQBucIBzBAgM5o/ezKUFkeg==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "@types/jquery": "*"
- }
- },
"node_modules/@types/jsesc": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/@types/jsesc/-/jsesc-2.5.1.tgz",
@@ -9531,21 +9511,6 @@
"url": "https://github.com/sponsors/panva"
}
},
- "node_modules/jquery": {
- "version": "3.7.1",
- "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz",
- "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==",
- "license": "MIT"
- },
- "node_modules/jquery-ui-dist": {
- "version": "1.13.2",
- "resolved": "https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.13.2.tgz",
- "integrity": "sha512-oVDRd1NLtTbBwpRKAYdIRgpWVDzeBhfy7Gu0RmY6JEaZtmBq6kDn1pm5SgDiAotrnDS+RoTRXO6xvcNTxA9tOA==",
- "license": "MIT",
- "dependencies": {
- "jquery": ">=1.8.0 <4.0.0"
- }
- },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
diff --git a/ui/package.json b/ui/package.json
index 5b570cea8d..ab01f18da8 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -64,8 +64,6 @@
"echarts-simple-transform": "^1.0.0",
"gridstack": "^12.6.0",
"file-saver": "2.0.5",
- "jquery": "^3.7.0",
- "jquery-ui-dist": "1.13.2",
"leaflet": "1.9.3",
"lodash.clonedeep": "^4.5.0",
"marked": "^18.0.3",
@@ -98,7 +96,6 @@
"@angular/compiler-cli": "^22.1.6",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^10.0.1",
- "@types/jqueryui": "^1.12.16",
"@types/leaflet": "^1.9.0",
"@types/node": "^22.12.0",
"@typescript-eslint/eslint-plugin": "^8.46.1",
diff --git a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
index e525960a8f..13f303419f 100644
--- a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
+++ b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
@@ -116,7 +116,11 @@
<div class="pipeline-assembly__palette" fxLayout="column">
<ng-content select="[editorPalette]"></ng-content>
</div>
- <div id="outerAssemblyArea" class="outerAssembly">
+ <div
+ id="outerAssemblyArea"
+ class="outerAssembly"
+ [class.palette-drag-active]="pipelineEditorService.dragging()"
+ >
@if (rawPipelineModel) {
<sp-pipeline-assembly-drawing-area
#drawingAreaComponent
diff --git a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.scss b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.scss
index a4deb2d67c..b4689f1fb5 100644
--- a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.scss
+++ b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.scss
@@ -77,3 +77,8 @@
flex-basis: 12rem;
}
}
+
+.outerAssembly.palette-drag-active {
+ outline: 2px dashed var(--color-primary);
+ outline-offset: -2px;
+}
diff --git a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.ts b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.ts
index ab5ca6e812..746c884511 100644
--- a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.ts
+++ b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.ts
@@ -28,6 +28,7 @@ import {
} from '@angular/core';
import { JsplumbBridge } from '../../services/jsplumb-bridge.service';
import { PipelinePositioningService } from '../../services/pipeline-positioning.service';
+import { PipelineEditorService } from '../../services/pipeline-editor.service';
import { PipelineValidationService } from '../../services/pipeline-validation.service';
import {
InvocablePipelineElementUnion,
@@ -107,6 +108,7 @@ export class PipelineAssemblyComponent implements AfterViewInit, OnDestroy {
private pipelinePositioningService = inject(PipelinePositioningService);
private objectProvider = inject(ObjectProvider);
editorService = inject(EditorService);
+ protected pipelineEditorService = inject(PipelineEditorService);
pipelineValidationService = inject(PipelineValidationService);
private dialogService = inject(DialogService);
private router = inject(Router);
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.html b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.html
index fb2923d22d..f9148c4208 100644
--- a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.html
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.html
@@ -16,6 +16,9 @@
~
-->
<div
+ cdkDrag
+ (cdkDragStarted)="pipelineEditorService.dragging.set(true)"
+ (cdkDragReleased)="releaseDrag()"
class="draggable-pipeline-element"
id="{{ element.appId || element.name.toLowerCase().replaceAll(' ', '_') }}"
[attr.data-pe]="element.elementId"
@@ -23,6 +26,18 @@
(mouseleave)="updateMouseOver('')"
data-cy="pipeline-element-icon-stand-row"
>
+ <ng-template cdkDragPreview>
+ <div
+ class="draggable-icon-drag pipeline-element-drag-preview"
+ [ngClass]="activeCssClass"
+ >
+ <span class="pe-container-drag">
+ <sp-pipeline-element
+ [pipelineElement]="element"
+ ></sp-pipeline-element>
+ </span>
+ </div>
+ </ng-template>
<div
matTooltip="{{ element.name }}"
[matTooltipPosition]="'above'"
@@ -76,6 +91,8 @@
[matTooltip]="'Help'"
[matTooltipPosition]="'above'"
(click)="openHelpDialog(element)"
+ (mousedown)="$event.stopPropagation()"
+ (touchstart)="$event.stopPropagation()"
>
<mat-icon>help</mat-icon>
</button>
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.scss b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.scss
index 48bbb026c6..4e4ebb3bf6 100644
--- a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.scss
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.scss
@@ -39,6 +39,7 @@
}
.draggable-icon-drag {
+ box-shadow: var(--shadow-overlay);
cursor: pointer;
vertical-align: top;
background: var(--color-pe);
@@ -51,7 +52,6 @@
line-height: 1;
border: 1px solid var(--color-border-subtle);
border-radius: var(--radius-sm);
- box-shadow: none;
text-align: center;
z-index: 100;
transition:
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.spec.ts b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.spec.ts
new file mode 100644
index 0000000000..10bacc244f
--- /dev/null
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.spec.ts
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { Component, Input } from '@angular/core';
+import { TestBed } from '@angular/core/testing';
+import { CdkDropList } from '@angular/cdk/drag-drop';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ PipelineElementComponent,
+ SpAssetBrowserService,
+ SpTableAssetContextService,
+} from '@streampipes/shared-ui';
+import { DataProcessorInvocation } from '@streampipes/platform-services';
+import { PipelineElementIconStandRowComponent } from './pipeline-element-icon-stand-row.component';
+import { PipelineEditorService } from '../../../services/pipeline-editor.service';
+import { EditorService } from '../../../services/editor.service';
+
+@Component({ selector: 'sp-pipeline-element', template: '' })
+class IconStubComponent {
+ @Input() pipelineElement: unknown;
+ @Input() iconStandSize: boolean;
+}
+
+@Component({
+ imports: [CdkDropList, PipelineElementIconStandRowComponent],
+ template: `<div cdkDropList [cdkDropListSortingDisabled]="true">
+ <sp-pe-icon-stand-row [element]="element" />
+ </div>`,
+})
+class PaletteHostComponent {
+ element = Object.assign(new DataProcessorInvocation(), {
+ name: 'Processor',
+ elementId: 'processor',
+ appId: 'processor',
+ });
+}
+
+describe('Pipeline palette dragging without jQuery', () => {
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [PaletteHostComponent],
+ providers: [
+ EditorService,
+ SpAssetBrowserService,
+ SpTableAssetContextService,
+ ].map(provide => ({ provide, useValue: {} })),
+ }).overrideComponent(PipelineElementIconStandRowComponent, {
+ remove: { imports: [PipelineElementComponent] },
+ add: { imports: [IconStubComponent] },
+ });
+ });
+
+ it('emits the icon bounds on release and keeps the palette item reusable', async () => {
+ const fixture = TestBed.createComponent(PaletteHostComponent);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const service = TestBed.inject(PipelineEditorService);
+ const dropped = vi.fn();
+ service.paletteDrop$.subscribe(dropped);
+ const row = fixture.nativeElement.querySelector(
+ '.draggable-pipeline-element',
+ ) as HTMLElement;
+ vi.spyOn(row, 'getBoundingClientRect').mockReturnValue(
+ new DOMRect(0, 0, 200, 40),
+ );
+ for (let count = 1; count <= 2; count++) {
+ row.dispatchEvent(
+ new MouseEvent('mousedown', {
+ detail: 1,
+ bubbles: true,
+ button: 0,
+ buttons: 1,
+ clientX: 10,
+ clientY: 10,
+ }),
+ );
+ document.dispatchEvent(
+ new MouseEvent('mousemove', {
+ bubbles: true,
+ buttons: 1,
+ clientX: 30,
+ clientY: 30,
+ }),
+ );
+ document.dispatchEvent(
+ new MouseEvent('mousemove', {
+ bubbles: true,
+ buttons: 1,
+ clientX: 300,
+ clientY: 200,
+ }),
+ );
+ const preview = document.querySelector(
+ '.pipeline-element-drag-preview',
+ );
+ expect(preview).not.toBeNull();
+ expect(service.dragging()).toBe(true);
+ const bounds = new DOMRect(300, 200, 70, 70);
+ vi.spyOn(preview, 'getBoundingClientRect').mockReturnValue(bounds);
+ document.dispatchEvent(
+ new MouseEvent('mouseup', {
+ bubbles: true,
+ clientX: 300,
+ clientY: 200,
+ }),
+ );
+ await fixture.whenStable();
+ expect(dropped).toHaveBeenCalledTimes(count);
+ expect(dropped).toHaveBeenLastCalledWith({
+ element: fixture.componentInstance.element,
+ bounds,
+ });
+ expect(service.dragging()).toBe(false);
+ expect(
+ document.querySelector('.pipeline-element-drag-preview'),
+ ).toBeNull();
+ expect(fixture.nativeElement.contains(row)).toBe(true);
+ }
+ });
+});
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.ts b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.ts
index 03e4b0e672..b5506dc264 100644
--- a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.ts
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand-row/pipeline-element-icon-stand-row.component.ts
@@ -44,6 +44,8 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { SpDataStream } from '@streampipes/platform-services';
import { SpTableResolvedAssetContext } from '@streampipes/shared-ui';
import { map } from 'rxjs';
+import { CdkDrag, CdkDragPreview } from '@angular/cdk/drag-drop';
+import { PipelineEditorService } from '../../../services/pipeline-editor.service';
@Component({
selector: 'sp-pe-icon-stand-row',
@@ -51,6 +53,8 @@ import { map } from 'rxjs';
styleUrls: ['./pipeline-element-icon-stand-row.component.scss'],
changeDetection: ChangeDetectionStrategy.Eager,
imports: [
+ CdkDrag,
+ CdkDragPreview,
MatTooltip,
NgClass,
PipelineElementComponent,
@@ -60,6 +64,7 @@ import { map } from 'rxjs';
],
})
export class PipelineElementIconStandRowComponent implements OnInit {
+ protected pipelineEditorService = inject(PipelineEditorService);
private editorService = inject(EditorService);
private assetBrowserService = inject(SpAssetBrowserService);
private assetContextService = inject(SpTableAssetContextService);
@@ -74,6 +79,12 @@ export class PipelineElementIconStandRowComponent implements OnInit {
currentMouseOver = false;
assetContext?: SpTableResolvedAssetContext;
+ constructor() {
+ this.destroyRef.onDestroy(() =>
+ this.pipelineEditorService.dragging.set(false),
+ );
+ }
+
ngOnInit(): void {
const activeType = PipelineElementTypeUtils.fromClassName(
this.element['@class'],
@@ -96,6 +107,19 @@ export class PipelineElementIconStandRowComponent implements OnInit {
}
}
+ releaseDrag(): void {
+ this.pipelineEditorService.dragging.set(false);
+ const preview = document.querySelector(
+ '.pipeline-element-drag-preview',
+ );
+ if (preview) {
+ this.pipelineEditorService.paletteDrop$.next({
+ element: this.element,
+ bounds: preview.getBoundingClientRect(),
+ });
+ }
+ }
+
makeActiveCssClass(elementType: PipelineElementType): string {
return PipelineElementTypeUtils.toCssShortHand(elementType);
}
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.html b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.html
index bb6b2e28d7..9a56e21dc3 100644
--- a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.html
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.html
@@ -16,6 +16,9 @@
~
-->
<div
+ cdkDropList
+ [cdkDropListSortingDisabled]="true"
+ [cdkDropListAutoScrollDisabled]="true"
fxFlex="100"
fxLayout="column"
[attr.data-cy]="'sp-pipeline-element-selection'"
diff --git a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.ts b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.ts
index 43b2653a7f..9d2e5b1e60 100644
--- a/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.ts
+++ b/ui/src/app/editor/components/pipeline-element-icon-stand/pipeline-element-icon-stand.component.ts
@@ -17,12 +17,9 @@
*/
import {
- AfterViewInit,
Component,
Input,
OnInit,
- OnChanges,
- SimpleChanges,
inject,
ChangeDetectionStrategy,
} from '@angular/core';
@@ -32,6 +29,7 @@ import {
PipelineElementUnion,
} from '../../model/editor.model';
import { EditorService } from '../../services/editor.service';
+import { CdkDropList } from '@angular/cdk/drag-drop';
import { zip } from 'rxjs';
import { Router } from '@angular/router';
import {
@@ -56,6 +54,7 @@ import { PipelineElementTypeFilterPipe } from '../../services/pipeline-element-t
styleUrls: ['./pipeline-element-icon-stand.component.scss'],
changeDetection: ChangeDetectionStrategy.Eager,
imports: [
+ CdkDropList,
FlexDirective,
LayoutDirective,
MatIcon,
@@ -73,9 +72,7 @@ import { PipelineElementTypeFilterPipe } from '../../services/pipeline-element-t
PipelineElementTypeFilterPipe,
],
})
-export class PipelineElementIconStandComponent
- implements OnInit, AfterViewInit, OnChanges
-{
+export class PipelineElementIconStandComponent implements OnInit {
private editorService = inject(EditorService);
private router = inject(Router);
@@ -120,16 +117,6 @@ export class PipelineElementIconStandComponent
this.loadOptions();
}
- ngOnChanges(changes: SimpleChanges): void {
- if (changes.elementFilter && !changes.elementFilter.firstChange) {
- this.makeDraggable();
- }
- }
-
- ngAfterViewInit() {
- this.makeDraggable();
- }
-
loadOptions() {
zip(
this.editorService.getEpCategories(),
@@ -174,44 +161,12 @@ export class PipelineElementIconStandComponent
});
}
- makeDraggable() {
- setTimeout(() => {
- ($('.draggable-pipeline-element') as any).draggable({
- revert: 'invalid',
- helper: ev => {
- const draggable = $(ev.currentTarget)
- .find('.draggable-icon-editor')
- .first()
- .clone();
- const draggableContainer = $(draggable)
- .find('.pe-container')
- .first();
- $(draggable).removeClass('draggable-icon-editor');
- $(draggable).addClass('draggable-icon-drag');
- $(draggableContainer).removeClass('pe-container');
- $(draggableContainer).addClass('pe-container-drag');
- return draggable.clone();
- },
- stack: '.draggable-pipeline-element',
- start(el, ui) {
- ui.helper.appendTo('#content');
- $('#outerAssemblyArea').css('border', '2px dashed #39b54a');
- },
- stop(_el, _ui) {
- $('#outerAssemblyArea').css('border', '0');
- },
- });
- });
- }
-
toggleOpen(availableType: any): void {
availableType.open = !availableType.open;
- this.makeDraggable();
}
changeSorting(availableType: any, sortMode: string) {
availableType.sort = sortMode;
- this.makeDraggable();
}
navigateToConnect() {
diff --git a/ui/src/app/editor/components/pipeline/pipeline.component.spec.ts b/ui/src/app/editor/components/pipeline/pipeline.component.spec.ts
new file mode 100644
index 0000000000..92f5db4f00
--- /dev/null
+++ b/ui/src/app/editor/components/pipeline/pipeline.component.spec.ts
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { TestBed } from '@angular/core/testing';
+import { MatDialog } from '@angular/material/dialog';
+import { DialogService, KeyboardShortcutService } from '@streampipes/shared-ui';
+import { DataProcessorInvocation } from '@streampipes/platform-services';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { PipelineComponent } from './pipeline.component';
+import { PipelineEditorService } from '../../services/pipeline-editor.service';
+import { JsplumbService } from '../../services/jsplumb.service';
+import { JsplumbFactoryService } from '../../services/jsplumb-factory.service';
+import { ObjectProvider } from '../../services/object-provider.service';
+import { EditorService } from '../../services/editor.service';
+import { PipelineStyleService } from '../../services/pipeline-style.service';
+import { PipelineValidationService } from '../../services/pipeline-validation.service';
+import { IdGeneratorService } from '../../../core-services/id-generator/id-generator.service';
+
+describe('Pipeline palette drops', () => {
+ const create = vi.fn();
+ beforeEach(() => {
+ create.mockReset().mockReturnValue({
+ type: 'stream',
+ payload: { dom: 'new-stream' },
+ });
+ TestBed.configureTestingModule({
+ providers: [
+ ...[
+ ObjectProvider,
+ PipelineStyleService,
+ PipelineValidationService,
+ DialogService,
+ MatDialog,
+ KeyboardShortcutService,
+ ].map(provide => ({ provide, useValue: {} })),
+ {
+ provide: JsplumbService,
+ useValue: { createNewPipelineElementConfig: create },
+ },
+ {
+ provide: JsplumbFactoryService,
+ useValue: { destroy: vi.fn() },
+ },
+ {
+ provide: EditorService,
+ useValue: { makePipelineAssemblyEmpty: vi.fn() },
+ },
+ {
+ provide: IdGeneratorService,
+ useValue: { generate: () => 'unique' },
+ },
+ ],
+ }).overrideComponent(PipelineComponent, {
+ set: { template: '', imports: [] },
+ });
+ });
+
+ function setup() {
+ const fixture = TestBed.createComponent(PipelineComponent);
+ const component = fixture.componentInstance;
+ const element = Object.assign(new DataProcessorInvocation(), {
+ elementId: 'processor',
+ });
+ component.allElements = [element];
+ component.rawPipelineModel = [];
+ component.JsplumbBridge = {
+ repaintEverything: vi.fn(),
+ } as unknown as PipelineComponent['JsplumbBridge'];
+ vi.spyOn(component, 'checkTopicModel').mockImplementation(() => {});
+ vi.spyOn(component, 'validatePipeline').mockImplementation(() => {});
+ const canvas = fixture.nativeElement as HTMLElement;
+ Object.defineProperty(canvas, 'offsetWidth', { value: 1000 });
+ vi.spyOn(canvas, 'getBoundingClientRect').mockReturnValue(
+ new DOMRect(100, 100, 500, 500),
+ );
+ vi.spyOn(canvas.parentElement, 'getBoundingClientRect').mockReturnValue(
+ new DOMRect(100, 100, 400, 400),
+ );
+ component.initAssembly();
+ const service = TestBed.inject(PipelineEditorService);
+ return { fixture, component, element, service };
+ }
+
+ it('adds an element at canvas coordinates and updates the cache', () => {
+ const { component, element, service } = setup();
+ const cacheUpdate = vi.spyOn(
+ component.triggerPipelineCacheUpdateEmitter,
+ 'emit',
+ );
+ service.paletteDrop$.next({
+ element,
+ bounds: new DOMRect(200, 250, 70, 70),
+ });
+ expect(create).toHaveBeenCalledWith(
+ element,
+ { x: 200, y: 300 },
+ false,
+ false,
+ 'processor:unique',
+ );
+ expect(component.rawPipelineModel).toHaveLength(1);
+ expect(cacheUpdate).toHaveBeenCalledOnce();
+ });
+
+ it('ignores drops outside the visible canvas', () => {
+ const { component, element, service } = setup();
+ service.paletteDrop$.next({
+ element,
+ bounds: new DOMRect(450, 200, 70, 70),
+ });
+ expect(component.rawPipelineModel).toHaveLength(0);
+ expect(create).not.toHaveBeenCalled();
+ });
+
+ it('ignores drops in read-only mode', () => {
+ const { component, element, service } = setup();
+ component.readonly = true;
+ service.paletteDrop$.next({
+ element,
+ bounds: new DOMRect(200, 200, 70, 70),
+ });
+ expect(create).not.toHaveBeenCalled();
+ });
+
+ it('unsubscribes when the editor is destroyed', () => {
+ const { fixture, element, service } = setup();
+ fixture.destroy();
+ service.paletteDrop$.next({
+ element,
+ bounds: new DOMRect(200, 200, 70, 70),
+ });
+ expect(create).not.toHaveBeenCalled();
+ });
+});
diff --git a/ui/src/app/editor/components/pipeline/pipeline.component.ts b/ui/src/app/editor/components/pipeline/pipeline.component.ts
index ca8ee7ea5b..2ee290631e 100644
--- a/ui/src/app/editor/components/pipeline/pipeline.component.ts
+++ b/ui/src/app/editor/components/pipeline/pipeline.component.ts
@@ -16,12 +16,15 @@
*
*/
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { PipelineValidationService } from '../../services/pipeline-validation.service';
import { JsplumbService } from '../../services/jsplumb.service';
import { PipelineEditorService } from '../../services/pipeline-editor.service';
import { JsplumbBridge } from '../../services/jsplumb-bridge.service';
import {
Component,
+ DestroyRef,
+ ElementRef,
EventEmitter,
HostListener,
Input,
@@ -98,6 +101,8 @@ import { EnabledPipelineElementFilter } from '../../filter/enabled-pipeline-elem
],
})
export class PipelineComponent implements OnInit, OnDestroy {
+ private destroyRef = inject(DestroyRef);
+ private elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
private jsplumbService = inject(JsplumbService);
private pipelineEditorService = inject(PipelineEditorService);
private jsplumbFactoryService = inject(JsplumbFactoryService);
@@ -138,7 +143,6 @@ export class PipelineComponent implements OnInit, OnDestroy {
currentMouseOverElement = '';
currentPipelineModel: Pipeline;
idCounter: any;
- currentZoomLevel: any;
JsplumbBridge: JsplumbBridge;
@@ -154,8 +158,6 @@ export class PipelineComponent implements OnInit, OnDestroy {
constructor() {
this.currentPipelineModel = new Pipeline();
this.idCounter = 0;
-
- this.currentZoomLevel = 1;
}
ngOnInit() {
@@ -253,59 +255,71 @@ export class PipelineComponent implements OnInit, OnDestroy {
}
initAssembly() {
- ($('#assembly') as any).droppable({
- tolerance: 'fit',
- drop: (element, ui) => {
- const pipelineElementId = ui.draggable.data('pe');
- const pipelineElement: PipelineElementUnion =
- this.findPipelineElementByElementId(pipelineElementId);
- if (ui.draggable.hasClass('draggable-pipeline-element')) {
- this.editorService.makePipelineAssemblyEmpty(false);
- const newElementId =
- pipelineElement.elementId +
- ':' +
- this.idGeneratorService.generate(5);
- const pipelineElementConfig =
- this.jsplumbService.createNewPipelineElementConfig(
- pipelineElement,
- this.pipelineEditorService.getCoordinates(
- ui,
- this.currentZoomLevel,
- ),
+ this.pipelineEditorService.paletteDrop$
+ .pipe(takeUntilDestroyed(this.destroyRef))
+ .subscribe(({ element: pipelineElement, bounds }) => {
+ const canvas = this.elementRef.nativeElement;
+ if (
+ this.readonly ||
+ !this.allElements.some(
+ element =>
+ element.elementId === pipelineElement.elementId,
+ ) ||
+ !this.pipelineEditorService.fitsInside(
+ bounds,
+ canvas.getBoundingClientRect(),
+ ) ||
+ !this.pipelineEditorService.fitsInside(
+ bounds,
+ canvas.parentElement.getBoundingClientRect(),
+ )
+ ) {
+ return;
+ }
+ this.editorService.makePipelineAssemblyEmpty(false);
+ const newElementId =
+ pipelineElement.elementId +
+ ':' +
+ this.idGeneratorService.generate(5);
+ const pipelineElementConfig =
+ this.jsplumbService.createNewPipelineElementConfig(
+ pipelineElement,
+ this.pipelineEditorService.getCoordinates(
+ bounds,
+ canvas,
+ ),
+ false,
+ false,
+ newElementId,
+ );
+
+ this.rawPipelineModel.push(pipelineElementConfig);
+
+ if (pipelineElementConfig.type === 'stream') {
+ this.checkTopicModel(pipelineElementConfig);
+ } else if (pipelineElementConfig.type === 'sepa') {
+ setTimeout(() => {
+ this.jsplumbService.dataProcessorDropped(
+ pipelineElementConfig.payload.dom,
+ pipelineElementConfig.payload as DataProcessorInvocation,
+ true,
false,
+ );
+ }, 10);
+ } else if (pipelineElementConfig.type === 'action') {
+ setTimeout(() => {
+ this.jsplumbService.dataSinkDropped(
+ pipelineElementConfig.payload.dom,
+ pipelineElementConfig.payload as DataSinkInvocation,
+ true,
false,
- newElementId,
);
-
- this.rawPipelineModel.push(pipelineElementConfig);
-
- if (pipelineElementConfig.type === 'stream') {
- this.checkTopicModel(pipelineElementConfig);
- } else if (pipelineElementConfig.type === 'sepa') {
- setTimeout(() => {
- this.jsplumbService.dataProcessorDropped(
- pipelineElementConfig.payload.dom,
- pipelineElementConfig.payload as DataProcessorInvocation,
- true,
- false,
- );
- }, 10);
- } else if (pipelineElementConfig.type === 'action') {
- setTimeout(() => {
- this.jsplumbService.dataSinkDropped(
- pipelineElementConfig.payload.dom,
- pipelineElementConfig.payload as DataSinkInvocation,
- true,
- false,
- );
- }, 10);
- }
+ }, 10);
}
this.JsplumbBridge.repaintEverything();
this.validatePipeline();
this.triggerPipelineCacheUpdateEmitter.emit();
- },
- });
+ });
}
checkTopicModel(pipelineElementConfig: PipelineElementConfig) {
diff --git a/ui/src/app/editor/services/jsplumb.service.ts b/ui/src/app/editor/services/jsplumb.service.ts
index 787e246b92..c3b2a46eab 100644
--- a/ui/src/app/editor/services/jsplumb.service.ts
+++ b/ui/src/app/editor/services/jsplumb.service.ts
@@ -115,7 +115,10 @@ export class JsplumbService {
pipelineElement: InvocablePipelineElementUnion,
sourceElementDomId: string,
) {
- const sourceElement = $('#' + sourceElementDomId);
+ const sourceElement = document.getElementById(sourceElementDomId);
+ if (!sourceElement) {
+ return;
+ }
const pipelineElementConfig =
this.createNewPipelineElementConfigWithFixedCoordinates(
@@ -173,15 +176,14 @@ export class JsplumbService {
}
connectNodes(
- sourceElementSelector,
+ sourceElement: HTMLElement,
targetElementId,
previewConfig: boolean,
openCustomize = false,
) {
- const sourceElement = sourceElementSelector.get()[0];
const jsplumbBridge = this.getBridge(previewConfig);
const jsplumbConfig = this.jsplumbEndpointService.getJsplumbConfig();
- const options = sourceElementSelector.hasClass('stream')
+ const options = sourceElement.classList.contains('stream')
? jsplumbConfig.streamEndpointOptions
: jsplumbConfig.sepaEndpointOptions;
const selectedEndpoints = jsplumbBridge.selectEndpoints({
@@ -193,8 +195,8 @@ export class JsplumbService {
? jsplumbBridge
.selectEndpoints({ source: sourceElement })
.get(0)
- : jsplumbBridge.addEndpoint(sourceElement, options)
- : jsplumbBridge.addEndpoint(sourceElement, options);
+ : jsplumbBridge.addEndpoint(sourceElement.id, options)
+ : jsplumbBridge.addEndpoint(sourceElement.id, options);
const targetElement = document.getElementById(targetElementId);
const targetEndPoint = jsplumbBridge
@@ -213,12 +215,12 @@ export class JsplumbService {
}
createNewPipelineElementConfigWithFixedCoordinates(
- sourceElement,
+ sourceElement: HTMLElement,
pipelineElement: InvocablePipelineElementUnion,
isPreview,
): PipelineElementConfig {
- const x = sourceElement.position().left;
- const y = sourceElement.position().top;
+ const x = sourceElement.offsetLeft;
+ const y = sourceElement.offsetTop;
return this.createNewPipelineElementConfigAtPosition(
x,
y,
diff --git a/ui/src/app/editor/services/pipeline-editor.service.spec.ts b/ui/src/app/editor/services/pipeline-editor.service.spec.ts
new file mode 100644
index 0000000000..14aab182af
--- /dev/null
+++ b/ui/src/app/editor/services/pipeline-editor.service.spec.ts
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { describe, expect, it, vi } from 'vitest';
+import { PipelineEditorService } from './pipeline-editor.service';
+
+describe('Pipeline palette drop coordinates', () => {
+ const service = new PipelineEditorService();
+
+ it.each([0.5, 0.75, 1, 1.5, 2])(
+ 'accounts for pan and zoom at scale %s',
+ zoom => {
+ const canvas = document.createElement('div');
+ Object.defineProperty(canvas, 'offsetWidth', { value: 4000 });
+ vi.spyOn(canvas, 'getBoundingClientRect').mockReturnValue(
+ new DOMRect(-120, 75, 4000 * zoom, 3000 * zoom),
+ );
+ const preview = new DOMRect(
+ -120 + 300 * zoom,
+ 75 + 150 * zoom,
+ 70,
+ 70,
+ );
+ expect(service.getCoordinates(preview, canvas)).toEqual({
+ x: 300,
+ y: 150,
+ });
+ },
+ );
+
+ it('accepts a preview exactly inside the visible canvas', () => {
+ expect(
+ service.fitsInside(
+ new DOMRect(100, 200, 70, 70),
+ new DOMRect(100, 200, 70, 70),
+ ),
+ ).toBe(true);
+ });
+
+ it.each([
+ [99, 200],
+ [100, 199],
+ [431, 200],
+ [100, 431],
+ ])('rejects a preview extending outside the canvas at %s, %s', (x, y) => {
+ expect(
+ service.fitsInside(
+ new DOMRect(x, y, 70, 70),
+ new DOMRect(100, 200, 400, 300),
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/ui/src/app/editor/services/pipeline-editor.service.ts b/ui/src/app/editor/services/pipeline-editor.service.ts
index 2290787c7b..8d0d50d0df 100644
--- a/ui/src/app/editor/services/pipeline-editor.service.ts
+++ b/ui/src/app/editor/services/pipeline-editor.service.ts
@@ -16,42 +16,33 @@
*
*/
-import { Injectable } from '@angular/core';
+import { Injectable, signal } from '@angular/core';
+import { Subject } from 'rxjs';
+import { PipelineElementUnion } from '../model/editor.model';
@Injectable({ providedIn: 'root' })
export class PipelineEditorService {
- constructor() {}
+ readonly dragging = signal(false);
+ readonly paletteDrop$ = new Subject<{
+ element: PipelineElementUnion;
+ bounds: DOMRect;
+ }>();
- getCoordinates(ui, currentZoomLevel) {
- const newLeft = this.getDropPositionX(ui.helper, currentZoomLevel);
- const newTop = this.getDropPositionY(ui.helper, currentZoomLevel);
+ getCoordinates(bounds: DOMRect, canvas: HTMLElement) {
+ const canvasBounds = canvas.getBoundingClientRect();
+ const zoom = canvasBounds.width / canvas.offsetWidth;
return {
- x: newLeft,
- y: newTop,
+ x: (bounds.left - canvasBounds.left) / zoom,
+ y: (bounds.top - canvasBounds.top) / zoom,
};
}
- getDropPositionY(helper, currentZoomLevel) {
- const helperPos = helper.offset();
- const divPos = this.getDivPos();
+ fitsInside(bounds: DOMRect, target: DOMRect): boolean {
return (
- helperPos.top -
- divPos.top +
- (1 - currentZoomLevel) * ((helperPos.top - divPos.top) * 2)
+ bounds.left >= target.left &&
+ bounds.top >= target.top &&
+ bounds.right <= target.right &&
+ bounds.bottom <= target.bottom
);
}
-
- getDropPositionX(helper, currentZoomLevel) {
- const helperPos = helper.offset();
- const divPos = this.getDivPos();
- return (
- helperPos.left -
- divPos.left +
- (1 - currentZoomLevel) * ((helperPos.left - divPos.left) * 2)
- );
- }
-
- getDivPos() {
- return $('#assembly').offset();
- }
}
diff --git a/ui/src/app/editor/services/pipeline-positioning.service.ts b/ui/src/app/editor/services/pipeline-positioning.service.ts
index 440ef54c68..8b175d38b1 100644
--- a/ui/src/app/editor/services/pipeline-positioning.service.ts
+++ b/ui/src/app/editor/services/pipeline-positioning.service.ts
@@ -55,10 +55,10 @@ export class PipelinePositioningService {
domId: string,
pipelineCanvasMetadata: PipelineCanvasMetadata,
) {
- const elementRef = $(`#${domId}`);
- if (elementRef && elementRef.position()) {
- const leftPos = elementRef.position().left;
- const topPos = elementRef.position().top;
+ const elementRef = document.getElementById(domId);
+ if (elementRef) {
+ const leftPos = elementRef.offsetLeft;
+ const topPos = elementRef.offsetTop;
if (!pipelineCanvasMetadata.pipelineElementMetadata) {
pipelineCanvasMetadata.pipelineElementMetadata = {};
}
@@ -143,7 +143,9 @@ export class PipelinePositioningService {
g.setDefaultEdgeLabel(() => {
return {};
});
- const nodes = $(canvasId).find(nodeIdentifier).get();
+ const nodes = document.querySelectorAll(
+ `${canvasId} ${nodeIdentifier}`,
+ );
nodes.forEach(n => {
g.setNode(n.id, {
label: n.id,
@@ -159,9 +161,12 @@ export class PipelinePositioningService {
dagre.layout(g);
g.nodes().forEach(v => {
- const elementRef = $(`#${v}`);
- elementRef.css('left', g.node(v).x + 'px');
- elementRef.css('top', g.node(v).y + 'px');
+ const elementRef = document.getElementById(v);
+ if (!elementRef) {
+ return;
+ }
+ elementRef.style.left = g.node(v).x + 'px';
+ elementRef.style.top = g.node(v).y + 'px';
});
jsPlumbBridge.repaintEverything();
}
@@ -171,10 +176,10 @@ export class PipelinePositioningService {
) {
Object.entries(pipelineCanvasMetadata.pipelineElementMetadata).forEach(
([key, value]) => {
- const elementRef = $(`#${key}`);
+ const elementRef = document.getElementById(key);
if (elementRef) {
- elementRef.css('left', value.position.x + 'px');
- elementRef.css('top', value.position.y + 'px');
+ elementRef.style.left = value.position.x + 'px';
+ elementRef.style.top = value.position.y + 'px';
}
},
);
diff --git a/ui/src/app/editor/services/pipeline-validation.service.ts b/ui/src/app/editor/services/pipeline-validation.service.ts
index 7c36bce2c3..f6eb6c97b3 100644
--- a/ui/src/app/editor/services/pipeline-validation.service.ts
+++ b/ui/src/app/editor/services/pipeline-validation.service.ts
@@ -221,7 +221,7 @@ export class PipelineValidationService {
g.setDefaultEdgeLabel(() => {
return {};
});
- const nodes = $('#assembly').find("div[id^='jsplumb']").get();
+ const nodes = document.querySelectorAll("#assembly div[id^='jsplumb']");
for (let i = 0; i < nodes.length; i++) {
const n = nodes[i];
const elementOptions = this.getElementOptions(
diff --git a/ui/src/main.ts b/ui/src/main.ts
index 3d547386c4..dd47ccd31a 100644
--- a/ui/src/main.ts
+++ b/ui/src/main.ts
@@ -46,8 +46,6 @@ echarts.registerTransform(RoundValuesTransform);
echarts.registerTransform(MapTransform);
echarts.registerTransform(PieAggregateTransform);
-import 'jquery';
-
bootstrapApplication(AppComponent, {
...appConfig,
providers: [provideZoneChangeDetection(), ...appConfig.providers],
diff --git a/ui/src/scss/sp/main.scss b/ui/src/scss/sp/main.scss
index 23c690d9cc..5f5d67a541 100644
--- a/ui/src/scss/sp/main.scss
+++ b/ui/src/scss/sp/main.scss
@@ -639,10 +639,6 @@ ul.circleMenu-closed {
opacity: 1;
}
-.ui-draggable-dragging {
- box-shadow: var(--shadow-overlay);
-}
-
#submit {
position: absolute;
bottom: 5px;
diff --git a/ui/tsconfig.spec.json b/ui/tsconfig.spec.json
index abda9b158f..7cee305d63 100644
--- a/ui/tsconfig.spec.json
+++ b/ui/tsconfig.spec.json
@@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
- "types": ["node", "jquery"]
+ "types": ["node"]
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts", "src/test-setup.ts"],
"angularCompilerOptions": {