@ship-ui/core 0.15.19 → 0.15.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ship-ui-core.mjs +54 -25
- package/fesm2022/ship-ui-core.mjs.map +1 -1
- package/index.d.ts +5 -2
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, signal, DestroyRef, InjectionToken, input, computed, viewChild, effect, HostListener, NgModule, Injectable, DOCUMENT, model, output, ApplicationRef, createComponent, isSignal, OutputEmitterRef, PLATFORM_ID, ViewChild, contentChild, contentChildren, afterNextRender, assertInInjectionContext, Injector, HostBinding, TemplateRef, runInInjectionContext, Directive, ChangeDetectorRef, viewChildren, ViewContainerRef, EnvironmentInjector } from '@angular/core';
|
|
3
3
|
import { isPlatformBrowser, JsonPipe, DatePipe, NgTemplateOutlet } from '@angular/common';
|
|
4
|
-
import { ShipCardComponent as ShipCardComponent$1, ShipIconComponent as ShipIconComponent$1, ShipButtonComponent as ShipButtonComponent$1 } from 'ship-ui';
|
|
5
4
|
import { NgModel } from '@angular/forms';
|
|
6
5
|
import { SIGNAL } from '@angular/core/primitives/signals';
|
|
7
6
|
|
|
@@ -477,9 +476,10 @@ class ShipDialogService {
|
|
|
477
476
|
open(component, options) {
|
|
478
477
|
const environmentInjector = this.#appRef.injector;
|
|
479
478
|
const hostElement = this.#createEl();
|
|
479
|
+
let closingCalled = false;
|
|
480
480
|
const { data, closed, ...rest } = options || {};
|
|
481
481
|
if (this.compRef) {
|
|
482
|
-
this.#cleanupRefs();
|
|
482
|
+
this.#cleanupRefs(true);
|
|
483
483
|
}
|
|
484
484
|
this.insertedCompRef = createComponent(component, {
|
|
485
485
|
environmentInjector,
|
|
@@ -501,8 +501,12 @@ class ShipDialogService {
|
|
|
501
501
|
}
|
|
502
502
|
if (closedField instanceof OutputEmitterRef) {
|
|
503
503
|
this.closedFieldSub = closedField.subscribe((...args) => {
|
|
504
|
-
closed?.(...args);
|
|
505
504
|
this.#cleanupRefs();
|
|
505
|
+
if (closingCalled)
|
|
506
|
+
return;
|
|
507
|
+
closingCalled = true;
|
|
508
|
+
closed?.(...args);
|
|
509
|
+
this.compRef?.instance.closed.emit(...args);
|
|
506
510
|
});
|
|
507
511
|
}
|
|
508
512
|
this.#appRef.attachView(this.insertedCompRef.hostView);
|
|
@@ -511,20 +515,22 @@ class ShipDialogService {
|
|
|
511
515
|
this.compRef.changeDetectorRef.detectChanges();
|
|
512
516
|
this.compRef.instance.isOpen.set(true);
|
|
513
517
|
this.compRef.setInput('options', rest);
|
|
514
|
-
this.compRef.instance.closed.subscribe(() => closeAction());
|
|
518
|
+
this.compClosedSub = this.compRef.instance.closed.subscribe(() => closeAction());
|
|
515
519
|
const _self = this;
|
|
516
|
-
function closeAction() {
|
|
520
|
+
function closeAction(arg = undefined) {
|
|
521
|
+
_self.#cleanupRefs();
|
|
522
|
+
if (closingCalled)
|
|
523
|
+
return;
|
|
524
|
+
closingCalled = true;
|
|
517
525
|
if (closedField && closedField instanceof OutputEmitterRef) {
|
|
518
|
-
closedField.emit(
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
closed?.(undefined);
|
|
526
|
+
closedField.emit(arg);
|
|
522
527
|
}
|
|
523
|
-
|
|
528
|
+
closed?.(arg);
|
|
524
529
|
}
|
|
525
530
|
return {
|
|
526
531
|
component: this.insertedCompRef.instance,
|
|
527
532
|
close: closeAction,
|
|
533
|
+
closed: this.compRef.instance.closed,
|
|
528
534
|
};
|
|
529
535
|
}
|
|
530
536
|
#createEl() {
|
|
@@ -535,20 +541,24 @@ class ShipDialogService {
|
|
|
535
541
|
}
|
|
536
542
|
return this.#document.getElementById('sh-dialog-ref');
|
|
537
543
|
}
|
|
538
|
-
#cleanupRefs() {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
544
|
+
#cleanupRefs(instant = false) {
|
|
545
|
+
const _self = this;
|
|
546
|
+
instant ? cleanup : queueMicrotask(() => cleanup());
|
|
547
|
+
function cleanup() {
|
|
548
|
+
if (_self.insertedCompRef) {
|
|
549
|
+
_self.#appRef.detachView(_self.insertedCompRef.hostView);
|
|
550
|
+
_self.closedFieldSub?.unsubscribe();
|
|
551
|
+
_self.insertedCompRef.destroy();
|
|
552
|
+
}
|
|
553
|
+
if (!_self.compRef)
|
|
554
|
+
return;
|
|
555
|
+
_self.#appRef.detachView(_self.compRef.hostView);
|
|
556
|
+
_self.compClosedSub?.unsubscribe();
|
|
557
|
+
_self.compRef.destroy();
|
|
543
558
|
}
|
|
544
|
-
if (!this.compRef)
|
|
545
|
-
return;
|
|
546
|
-
this.#appRef.detachView(this.compRef.hostView);
|
|
547
|
-
this.compClosedSub?.unsubscribe();
|
|
548
|
-
this.compRef.destroy();
|
|
549
559
|
}
|
|
550
560
|
ngOnDestroy() {
|
|
551
|
-
this.#cleanupRefs();
|
|
561
|
+
this.#cleanupRefs(true);
|
|
552
562
|
}
|
|
553
563
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipDialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
554
564
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipDialogService, providedIn: 'root' }); }
|
|
@@ -716,6 +726,7 @@ function findDuplicateNodeIDs(nodes) {
|
|
|
716
726
|
const TEST_NODES = [
|
|
717
727
|
{
|
|
718
728
|
id: 'a1',
|
|
729
|
+
name: 'hello a1',
|
|
719
730
|
coordinates: [0, 0],
|
|
720
731
|
inputs: [],
|
|
721
732
|
outputs: [{ id: 'out-1', name: 'Start Output' }],
|
|
@@ -736,6 +747,7 @@ const TEST_NODES = [
|
|
|
736
747
|
},
|
|
737
748
|
{
|
|
738
749
|
id: 'c6',
|
|
750
|
+
name: 'hello c6',
|
|
739
751
|
coordinates: [0, 0],
|
|
740
752
|
inputs: [{ id: 'in-1', name: 'Input C' }],
|
|
741
753
|
outputs: [{ id: 'out-1', name: 'Output D' }],
|
|
@@ -1384,6 +1396,23 @@ class ShipBlueprintComponent {
|
|
|
1384
1396
|
}
|
|
1385
1397
|
return false;
|
|
1386
1398
|
}
|
|
1399
|
+
getNewNodeCoordinates(panToCoordinates = false) {
|
|
1400
|
+
let lowestY = 0;
|
|
1401
|
+
if (this.nodes().length > 0) {
|
|
1402
|
+
lowestY = this.nodes().reduce((max, node) => Math.max(max, node.coordinates[1]), 0);
|
|
1403
|
+
}
|
|
1404
|
+
const newCoordinates = [20, lowestY + 200];
|
|
1405
|
+
if (panToCoordinates) {
|
|
1406
|
+
this.#panToCoordinates(newCoordinates);
|
|
1407
|
+
}
|
|
1408
|
+
return newCoordinates;
|
|
1409
|
+
}
|
|
1410
|
+
#panToCoordinates(coords) {
|
|
1411
|
+
const [x, y] = coords;
|
|
1412
|
+
const rect = this.#selfRef.nativeElement.getBoundingClientRect();
|
|
1413
|
+
this.panX.set(rect.width / 2 - x * this.zoomLevel());
|
|
1414
|
+
this.panY.set(rect.height / 2 - y * this.zoomLevel());
|
|
1415
|
+
}
|
|
1387
1416
|
#getDistance(touch1, touch2) {
|
|
1388
1417
|
const dx = touch1.clientX - touch2.clientX;
|
|
1389
1418
|
const dy = touch1.clientY - touch2.clientY;
|
|
@@ -1434,7 +1463,7 @@ class ShipBlueprintComponent {
|
|
|
1434
1463
|
(mouseenter)="isHoveringNode.set(true)"
|
|
1435
1464
|
(mouseleave)="isHoveringNode.set(false)">
|
|
1436
1465
|
<header (mousedown)="startNodeDrag($event, node.id)" (touchstart)="startNodeDrag($event, node.id)">
|
|
1437
|
-
<span class="node-title">{{ node.id }}</span>
|
|
1466
|
+
<span class="node-title">{{ node.name ? node.name : node.id }}</span>
|
|
1438
1467
|
<sh-icon>list</sh-icon>
|
|
1439
1468
|
</header>
|
|
1440
1469
|
<div class="ports">
|
|
@@ -1479,13 +1508,13 @@ class ShipBlueprintComponent {
|
|
|
1479
1508
|
</div>
|
|
1480
1509
|
}
|
|
1481
1510
|
</div>
|
|
1482
|
-
`, isInline: true, dependencies: [{ kind: "component", type: ShipCardComponent
|
|
1511
|
+
`, isInline: true, dependencies: [{ kind: "component", type: ShipCardComponent, selector: "sh-card" }, { kind: "component", type: ShipIconComponent, selector: "sh-icon" }, { kind: "component", type: ShipButtonComponent, selector: "[shButton]" }, { kind: "pipe", type: JsonPipe, name: "json" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
1483
1512
|
}
|
|
1484
1513
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipBlueprintComponent, decorators: [{
|
|
1485
1514
|
type: Component,
|
|
1486
1515
|
args: [{
|
|
1487
1516
|
selector: 'sh-blueprint',
|
|
1488
|
-
imports: [ShipCardComponent
|
|
1517
|
+
imports: [ShipCardComponent, ShipIconComponent, JsonPipe, ShipButtonComponent],
|
|
1489
1518
|
template: `
|
|
1490
1519
|
<div
|
|
1491
1520
|
class="canvas-container"
|
|
@@ -1527,7 +1556,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
|
|
|
1527
1556
|
(mouseenter)="isHoveringNode.set(true)"
|
|
1528
1557
|
(mouseleave)="isHoveringNode.set(false)">
|
|
1529
1558
|
<header (mousedown)="startNodeDrag($event, node.id)" (touchstart)="startNodeDrag($event, node.id)">
|
|
1530
|
-
<span class="node-title">{{ node.id }}</span>
|
|
1559
|
+
<span class="node-title">{{ node.name ? node.name : node.id }}</span>
|
|
1531
1560
|
<sh-icon>list</sh-icon>
|
|
1532
1561
|
</header>
|
|
1533
1562
|
<div class="ports">
|