@ship-ui/core 0.15.19 → 0.15.22

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.
@@ -477,9 +477,10 @@ class ShipDialogService {
477
477
  open(component, options) {
478
478
  const environmentInjector = this.#appRef.injector;
479
479
  const hostElement = this.#createEl();
480
+ let closingCalled = false;
480
481
  const { data, closed, ...rest } = options || {};
481
482
  if (this.compRef) {
482
- this.#cleanupRefs();
483
+ this.#cleanupRefs(true);
483
484
  }
484
485
  this.insertedCompRef = createComponent(component, {
485
486
  environmentInjector,
@@ -501,8 +502,12 @@ class ShipDialogService {
501
502
  }
502
503
  if (closedField instanceof OutputEmitterRef) {
503
504
  this.closedFieldSub = closedField.subscribe((...args) => {
504
- closed?.(...args);
505
505
  this.#cleanupRefs();
506
+ if (closingCalled)
507
+ return;
508
+ closingCalled = true;
509
+ closed?.(...args);
510
+ this.compRef?.instance.closed.emit(...args);
506
511
  });
507
512
  }
508
513
  this.#appRef.attachView(this.insertedCompRef.hostView);
@@ -511,20 +516,22 @@ class ShipDialogService {
511
516
  this.compRef.changeDetectorRef.detectChanges();
512
517
  this.compRef.instance.isOpen.set(true);
513
518
  this.compRef.setInput('options', rest);
514
- this.compRef.instance.closed.subscribe(() => closeAction());
519
+ this.compClosedSub = this.compRef.instance.closed.subscribe(() => closeAction());
515
520
  const _self = this;
516
- function closeAction() {
521
+ function closeAction(arg = undefined) {
522
+ _self.#cleanupRefs();
523
+ if (closingCalled)
524
+ return;
525
+ closingCalled = true;
517
526
  if (closedField && closedField instanceof OutputEmitterRef) {
518
- closedField.emit(false);
519
- }
520
- else {
521
- closed?.(undefined);
527
+ closedField.emit(arg);
522
528
  }
523
- _self.#cleanupRefs();
529
+ closed?.(arg);
524
530
  }
525
531
  return {
526
532
  component: this.insertedCompRef.instance,
527
533
  close: closeAction,
534
+ closed: this.compRef.instance.closed,
528
535
  };
529
536
  }
530
537
  #createEl() {
@@ -535,20 +542,24 @@ class ShipDialogService {
535
542
  }
536
543
  return this.#document.getElementById('sh-dialog-ref');
537
544
  }
538
- #cleanupRefs() {
539
- if (this.insertedCompRef) {
540
- this.#appRef.detachView(this.insertedCompRef.hostView);
541
- this.closedFieldSub?.unsubscribe();
542
- this.insertedCompRef.destroy();
545
+ #cleanupRefs(instant = false) {
546
+ const _self = this;
547
+ instant ? cleanup : queueMicrotask(() => cleanup());
548
+ function cleanup() {
549
+ if (_self.insertedCompRef) {
550
+ _self.#appRef.detachView(_self.insertedCompRef.hostView);
551
+ _self.closedFieldSub?.unsubscribe();
552
+ _self.insertedCompRef.destroy();
553
+ }
554
+ if (!_self.compRef)
555
+ return;
556
+ _self.#appRef.detachView(_self.compRef.hostView);
557
+ _self.compClosedSub?.unsubscribe();
558
+ _self.compRef.destroy();
543
559
  }
544
- if (!this.compRef)
545
- return;
546
- this.#appRef.detachView(this.compRef.hostView);
547
- this.compClosedSub?.unsubscribe();
548
- this.compRef.destroy();
549
560
  }
550
561
  ngOnDestroy() {
551
- this.#cleanupRefs();
562
+ this.#cleanupRefs(true);
552
563
  }
553
564
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipDialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
554
565
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipDialogService, providedIn: 'root' }); }
@@ -716,6 +727,7 @@ function findDuplicateNodeIDs(nodes) {
716
727
  const TEST_NODES = [
717
728
  {
718
729
  id: 'a1',
730
+ name: 'hello a1',
719
731
  coordinates: [0, 0],
720
732
  inputs: [],
721
733
  outputs: [{ id: 'out-1', name: 'Start Output' }],
@@ -736,6 +748,7 @@ const TEST_NODES = [
736
748
  },
737
749
  {
738
750
  id: 'c6',
751
+ name: 'hello c6',
739
752
  coordinates: [0, 0],
740
753
  inputs: [{ id: 'in-1', name: 'Input C' }],
741
754
  outputs: [{ id: 'out-1', name: 'Output D' }],
@@ -1384,6 +1397,23 @@ class ShipBlueprintComponent {
1384
1397
  }
1385
1398
  return false;
1386
1399
  }
1400
+ getNewNodeCoordinates(panToCoordinates = false) {
1401
+ let lowestY = 0;
1402
+ if (this.nodes().length > 0) {
1403
+ lowestY = this.nodes().reduce((max, node) => Math.max(max, node.coordinates[1]), 0);
1404
+ }
1405
+ const newCoordinates = [20, lowestY + 200];
1406
+ if (panToCoordinates) {
1407
+ this.#panToCoordinates(newCoordinates);
1408
+ }
1409
+ return newCoordinates;
1410
+ }
1411
+ #panToCoordinates(coords) {
1412
+ const [x, y] = coords;
1413
+ const rect = this.#selfRef.nativeElement.getBoundingClientRect();
1414
+ this.panX.set(rect.width / 2 - x * this.zoomLevel());
1415
+ this.panY.set(rect.height / 2 - y * this.zoomLevel());
1416
+ }
1387
1417
  #getDistance(touch1, touch2) {
1388
1418
  const dx = touch1.clientX - touch2.clientX;
1389
1419
  const dy = touch1.clientY - touch2.clientY;
@@ -1434,7 +1464,7 @@ class ShipBlueprintComponent {
1434
1464
  (mouseenter)="isHoveringNode.set(true)"
1435
1465
  (mouseleave)="isHoveringNode.set(false)">
1436
1466
  <header (mousedown)="startNodeDrag($event, node.id)" (touchstart)="startNodeDrag($event, node.id)">
1437
- <span class="node-title">{{ node.id }}</span>
1467
+ <span class="node-title">{{ node.name ? node.name : node.id }}</span>
1438
1468
  <sh-icon>list</sh-icon>
1439
1469
  </header>
1440
1470
  <div class="ports">
@@ -1527,7 +1557,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
1527
1557
  (mouseenter)="isHoveringNode.set(true)"
1528
1558
  (mouseleave)="isHoveringNode.set(false)">
1529
1559
  <header (mousedown)="startNodeDrag($event, node.id)" (touchstart)="startNodeDrag($event, node.id)">
1530
- <span class="node-title">{{ node.id }}</span>
1560
+ <span class="node-title">{{ node.name ? node.name : node.id }}</span>
1531
1561
  <sh-icon>list</sh-icon>
1532
1562
  </header>
1533
1563
  <div class="ports">