@worktile/gantt 14.0.3 → 14.0.4

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.
@@ -474,8 +474,8 @@ class GanttView {
474
474
  }
475
475
  // 根据X坐标获取对应时间
476
476
  getDateByXPoint(x) {
477
- const indexOfSecondaryDate = Math.floor(x / this.getCellWidth());
478
- const matchDate = this.secondaryDatePoints[indexOfSecondaryDate];
477
+ const indexOfSecondaryDate = Math.max(Math.floor(x / this.getCellWidth()), 0);
478
+ const matchDate = this.secondaryDatePoints[Math.min(this.secondaryDatePoints.length - 1, indexOfSecondaryDate)];
479
479
  const dayWidth = this.getDayOccupancyWidth(matchDate === null || matchDate === void 0 ? void 0 : matchDate.start);
480
480
  if (dayWidth === this.getCellWidth()) {
481
481
  return matchDate === null || matchDate === void 0 ? void 0 : matchDate.start;
@@ -2101,6 +2101,7 @@ class GanttDomService {
2101
2101
  this.container = this.root.getElementsByClassName('gantt-container')[0];
2102
2102
  this.sideContainer = this.root.getElementsByClassName('gantt-side-container')[0];
2103
2103
  this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
2104
+ this.mainItems = this.root.getElementsByClassName('gantt-main-items')[0];
2104
2105
  this.calendarOverlay = this.root.getElementsByClassName('gantt-calendar-overlay')[0];
2105
2106
  this.monitorScrollChange();
2106
2107
  this.disableBrowserWheelEvent();
@@ -2555,6 +2556,7 @@ class GanttBarDrag {
2555
2556
  createBarDrag() {
2556
2557
  const dragRef = this.dragDrop.createDrag(this.barElement);
2557
2558
  dragRef.lockAxis = 'x';
2559
+ dragRef.withBoundaryElement(this.dom.mainItems);
2558
2560
  dragRef.started.subscribe(() => {
2559
2561
  this.setDraggingStyles();
2560
2562
  this.dragContainer.dragStarted.emit({ item: this.item.origin });
@@ -2571,7 +2573,6 @@ class GanttBarDrag {
2571
2573
  start = start.addDays(1);
2572
2574
  end = end.addDays(1);
2573
2575
  }
2574
- // this.openDragBackdrop(this.barElement, start, end);
2575
2576
  this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(currentX), this.ganttUpper.view.getDateByXPoint(currentX + this.item.refs.width));
2576
2577
  this.item.updateDate(start, end);
2577
2578
  this.dragContainer.dragMoved.emit({ item: this.item.origin });
@@ -2592,7 +2593,7 @@ class GanttBarDrag {
2592
2593
  const isBefore = index === 0;
2593
2594
  const dragRef = this.dragDrop.createDrag(handle);
2594
2595
  dragRef.lockAxis = 'x';
2595
- dragRef.withBoundaryElement(this.dom.root);
2596
+ dragRef.withBoundaryElement(this.dom.mainItems);
2596
2597
  dragRef.started.subscribe(() => {
2597
2598
  this.setDraggingStyles();
2598
2599
  this.dragContainer.dragStarted.emit({ item: this.item.origin });
@@ -2601,20 +2602,22 @@ class GanttBarDrag {
2601
2602
  if (isBefore) {
2602
2603
  const x = this.item.refs.x + event.distance.x;
2603
2604
  const width = this.item.refs.width + event.distance.x * -1;
2605
+ const start = this.ganttUpper.view.getDateByXPoint(x);
2604
2606
  if (width > dragMinWidth) {
2605
2607
  this.barElement.style.width = width + 'px';
2606
2608
  this.barElement.style.left = x + 'px';
2607
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), this.item.end);
2608
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(x), this.item.end);
2609
+ this.openDragBackdrop(this.barElement, start, this.item.end);
2610
+ this.item.updateDate(start, this.item.end);
2609
2611
  }
2610
2612
  }
2611
2613
  else {
2612
2614
  const width = this.item.refs.width + event.distance.x;
2615
+ const end = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width);
2613
2616
  if (width > dragMinWidth) {
2614
2617
  this.barElement.style.width = width + 'px';
2615
- this.openDragBackdrop(this.barElement, this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
2618
+ this.openDragBackdrop(this.barElement, this.item.start, end);
2619
+ this.item.updateDate(this.item.start, end);
2616
2620
  }
2617
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
2618
2621
  }
2619
2622
  this.dragContainer.dragMoved.emit({ item: this.item.origin });
2620
2623
  event.source.reset();
@@ -2622,19 +2625,13 @@ class GanttBarDrag {
2622
2625
  dragRef.ended.subscribe((event) => {
2623
2626
  if (isBefore) {
2624
2627
  const width = this.item.refs.width + event.distance.x * -1;
2625
- if (width > dragMinWidth) {
2626
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
2627
- }
2628
- else {
2628
+ if (width <= dragMinWidth) {
2629
2629
  this.item.updateDate(this.item.end.startOfDay(), this.item.end);
2630
2630
  }
2631
2631
  }
2632
2632
  else {
2633
2633
  const width = this.item.refs.width + event.distance.x;
2634
- if (width > dragMinWidth) {
2635
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x));
2636
- }
2637
- else {
2634
+ if (width <= dragMinWidth) {
2638
2635
  this.item.updateDate(this.item.start, this.item.start.endOfDay());
2639
2636
  }
2640
2637
  }
@@ -2861,7 +2858,16 @@ class NgxGanttBarComponent extends GanttItemUpper {
2861
2858
  });
2862
2859
  }
2863
2860
  ngAfterViewInit() {
2864
- this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
2861
+ // Note: the zone may be nooped through `BootstrapOptions` when bootstrapping the root module. This means
2862
+ // the `onStable` will never emit any value.
2863
+ const onStable$ = this.ngZone.isStable ? from(Promise.resolve()) : this.ngZone.onStable.pipe(take(1));
2864
+ // Normally this isn't in the zone, but it can cause performance regressions for apps
2865
+ // using `zone-patch-rxjs` because it'll trigger a change detection when it unsubscribes.
2866
+ this.ngZone.runOutsideAngular(() => {
2867
+ onStable$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2868
+ this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
2869
+ });
2870
+ });
2865
2871
  this.setContentBackground();
2866
2872
  this.handles.changes
2867
2873
  .pipe(startWith(this.handles), switchMap(() =>