@worktile/gantt 14.0.3 → 14.0.5

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?.start);
480
480
  if (dayWidth === this.getCellWidth()) {
481
481
  return matchDate?.start;
@@ -857,13 +857,12 @@ class GanttUpper {
857
857
  this.dragEnded = new EventEmitter();
858
858
  this.barClick = new EventEmitter();
859
859
  this.viewChange = new EventEmitter();
860
+ this.expandChange = new EventEmitter();
860
861
  this.linkDragEnded = new EventEmitter();
861
862
  this.items = [];
862
863
  this.groups = [];
863
864
  this.baselineItems = [];
864
865
  this.baselineItemsMap = {};
865
- // public viewChange = new EventEmitter<GanttView>();
866
- this.expandChange = new EventEmitter();
867
866
  this.firstChange = true;
868
867
  this.unsubscribe$ = new Subject();
869
868
  this._selectable = false;
@@ -897,6 +896,7 @@ class GanttUpper {
897
896
  get multiple() {
898
897
  return this._multiple;
899
898
  }
899
+ // public viewChange = new EventEmitter<GanttView>();
900
900
  get element() {
901
901
  return this.elementRef.nativeElement;
902
902
  }
@@ -1000,7 +1000,7 @@ class GanttUpper {
1000
1000
  this.groups.forEach((group) => {
1001
1001
  group.setExpand(expanded);
1002
1002
  });
1003
- this.expandChange.next();
1003
+ this.expandChange.next(null);
1004
1004
  this.cdr.detectChanges();
1005
1005
  }
1006
1006
  initSelectionModel() {
@@ -1083,7 +1083,7 @@ class GanttUpper {
1083
1083
  }
1084
1084
  expandGroup(group) {
1085
1085
  group.setExpand(!group.expanded);
1086
- this.expandChange.emit();
1086
+ this.expandChange.emit(group);
1087
1087
  this.cdr.detectChanges();
1088
1088
  }
1089
1089
  // public functions
@@ -1130,7 +1130,7 @@ class GanttUpper {
1130
1130
  }
1131
1131
  }
1132
1132
  GanttUpper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.11", ngImport: i0, type: GanttUpper, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: GANTT_GLOBAL_CONFIG }], target: i0.ɵɵFactoryTarget.Directive });
1133
- GanttUpper.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.11", type: GanttUpper, inputs: { originItems: ["items", "originItems"], originGroups: ["groups", "originGroups"], originBaselineItems: ["baselineItems", "originBaselineItems"], viewType: "viewType", start: "start", end: "end", showTodayLine: "showTodayLine", draggable: "draggable", styles: "styles", showToolbar: "showToolbar", toolbarOptions: "toolbarOptions", viewOptions: "viewOptions", linkOptions: "linkOptions", disabledLoadOnScroll: "disabledLoadOnScroll", selectable: "selectable", multiple: "multiple" }, outputs: { loadOnScroll: "loadOnScroll", dragStarted: "dragStarted", dragMoved: "dragMoved", dragEnded: "dragEnded", barClick: "barClick", viewChange: "viewChange" }, host: { properties: { "class.gantt": "this.ganttClass" } }, queries: [{ propertyName: "barTemplate", first: true, predicate: ["bar"], descendants: true, static: true }, { propertyName: "rangeTemplate", first: true, predicate: ["range"], descendants: true, static: true }, { propertyName: "itemTemplate", first: true, predicate: ["item"], descendants: true, static: true }, { propertyName: "groupTemplate", first: true, predicate: ["group"], descendants: true, static: true }, { propertyName: "groupHeaderTemplate", first: true, predicate: ["groupHeader"], descendants: true, static: true }, { propertyName: "toolbarTemplate", first: true, predicate: ["toolbar"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0 });
1133
+ GanttUpper.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.11", type: GanttUpper, inputs: { originItems: ["items", "originItems"], originGroups: ["groups", "originGroups"], originBaselineItems: ["baselineItems", "originBaselineItems"], viewType: "viewType", start: "start", end: "end", showTodayLine: "showTodayLine", draggable: "draggable", styles: "styles", showToolbar: "showToolbar", toolbarOptions: "toolbarOptions", viewOptions: "viewOptions", linkOptions: "linkOptions", disabledLoadOnScroll: "disabledLoadOnScroll", selectable: "selectable", multiple: "multiple" }, outputs: { loadOnScroll: "loadOnScroll", dragStarted: "dragStarted", dragMoved: "dragMoved", dragEnded: "dragEnded", barClick: "barClick", viewChange: "viewChange", expandChange: "expandChange" }, host: { properties: { "class.gantt": "this.ganttClass" } }, queries: [{ propertyName: "barTemplate", first: true, predicate: ["bar"], descendants: true, static: true }, { propertyName: "rangeTemplate", first: true, predicate: ["range"], descendants: true, static: true }, { propertyName: "itemTemplate", first: true, predicate: ["item"], descendants: true, static: true }, { propertyName: "groupTemplate", first: true, predicate: ["group"], descendants: true, static: true }, { propertyName: "groupHeaderTemplate", first: true, predicate: ["groupHeader"], descendants: true, static: true }, { propertyName: "toolbarTemplate", first: true, predicate: ["toolbar"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0 });
1134
1134
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.11", ngImport: i0, type: GanttUpper, decorators: [{
1135
1135
  type: Directive
1136
1136
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: undefined, decorators: [{
@@ -1183,6 +1183,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.11", ngImpo
1183
1183
  type: Output
1184
1184
  }], viewChange: [{
1185
1185
  type: Output
1186
+ }], expandChange: [{
1187
+ type: Output
1186
1188
  }], barTemplate: [{
1187
1189
  type: ContentChild,
1188
1190
  args: ['bar', { static: true }]
@@ -2093,6 +2095,7 @@ class GanttDomService {
2093
2095
  this.container = this.root.getElementsByClassName('gantt-container')[0];
2094
2096
  this.sideContainer = this.root.getElementsByClassName('gantt-side-container')[0];
2095
2097
  this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
2098
+ this.mainItems = this.root.getElementsByClassName('gantt-main-items')[0];
2096
2099
  this.calendarOverlay = this.root.getElementsByClassName('gantt-calendar-overlay')[0];
2097
2100
  this.monitorScrollChange();
2098
2101
  this.disableBrowserWheelEvent();
@@ -2536,6 +2539,7 @@ class GanttBarDrag {
2536
2539
  createBarDrag() {
2537
2540
  const dragRef = this.dragDrop.createDrag(this.barElement);
2538
2541
  dragRef.lockAxis = 'x';
2542
+ dragRef.withBoundaryElement(this.dom.mainItems);
2539
2543
  dragRef.started.subscribe(() => {
2540
2544
  this.setDraggingStyles();
2541
2545
  this.dragContainer.dragStarted.emit({ item: this.item.origin });
@@ -2552,7 +2556,6 @@ class GanttBarDrag {
2552
2556
  start = start.addDays(1);
2553
2557
  end = end.addDays(1);
2554
2558
  }
2555
- // this.openDragBackdrop(this.barElement, start, end);
2556
2559
  this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(currentX), this.ganttUpper.view.getDateByXPoint(currentX + this.item.refs.width));
2557
2560
  this.item.updateDate(start, end);
2558
2561
  this.dragContainer.dragMoved.emit({ item: this.item.origin });
@@ -2573,7 +2576,7 @@ class GanttBarDrag {
2573
2576
  const isBefore = index === 0;
2574
2577
  const dragRef = this.dragDrop.createDrag(handle);
2575
2578
  dragRef.lockAxis = 'x';
2576
- dragRef.withBoundaryElement(this.dom.root);
2579
+ dragRef.withBoundaryElement(this.dom.mainItems);
2577
2580
  dragRef.started.subscribe(() => {
2578
2581
  this.setDraggingStyles();
2579
2582
  this.dragContainer.dragStarted.emit({ item: this.item.origin });
@@ -2582,20 +2585,22 @@ class GanttBarDrag {
2582
2585
  if (isBefore) {
2583
2586
  const x = this.item.refs.x + event.distance.x;
2584
2587
  const width = this.item.refs.width + event.distance.x * -1;
2588
+ const start = this.ganttUpper.view.getDateByXPoint(x);
2585
2589
  if (width > dragMinWidth) {
2586
2590
  this.barElement.style.width = width + 'px';
2587
2591
  this.barElement.style.left = x + 'px';
2588
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), this.item.end);
2589
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(x), this.item.end);
2592
+ this.openDragBackdrop(this.barElement, start, this.item.end);
2593
+ this.item.updateDate(start, this.item.end);
2590
2594
  }
2591
2595
  }
2592
2596
  else {
2593
2597
  const width = this.item.refs.width + event.distance.x;
2598
+ const end = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width);
2594
2599
  if (width > dragMinWidth) {
2595
2600
  this.barElement.style.width = width + 'px';
2596
- this.openDragBackdrop(this.barElement, this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
2601
+ this.openDragBackdrop(this.barElement, this.item.start, end);
2602
+ this.item.updateDate(this.item.start, end);
2597
2603
  }
2598
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
2599
2604
  }
2600
2605
  this.dragContainer.dragMoved.emit({ item: this.item.origin });
2601
2606
  event.source.reset();
@@ -2603,19 +2608,13 @@ class GanttBarDrag {
2603
2608
  dragRef.ended.subscribe((event) => {
2604
2609
  if (isBefore) {
2605
2610
  const width = this.item.refs.width + event.distance.x * -1;
2606
- if (width > dragMinWidth) {
2607
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
2608
- }
2609
- else {
2611
+ if (width <= dragMinWidth) {
2610
2612
  this.item.updateDate(this.item.end.startOfDay(), this.item.end);
2611
2613
  }
2612
2614
  }
2613
2615
  else {
2614
2616
  const width = this.item.refs.width + event.distance.x;
2615
- if (width > dragMinWidth) {
2616
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x));
2617
- }
2618
- else {
2617
+ if (width <= dragMinWidth) {
2619
2618
  this.item.updateDate(this.item.start, this.item.start.endOfDay());
2620
2619
  }
2621
2620
  }
@@ -2841,7 +2840,16 @@ class NgxGanttBarComponent extends GanttItemUpper {
2841
2840
  });
2842
2841
  }
2843
2842
  ngAfterViewInit() {
2844
- this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
2843
+ // Note: the zone may be nooped through `BootstrapOptions` when bootstrapping the root module. This means
2844
+ // the `onStable` will never emit any value.
2845
+ const onStable$ = this.ngZone.isStable ? from(Promise.resolve()) : this.ngZone.onStable.pipe(take(1));
2846
+ // Normally this isn't in the zone, but it can cause performance regressions for apps
2847
+ // using `zone-patch-rxjs` because it'll trigger a change detection when it unsubscribes.
2848
+ this.ngZone.runOutsideAngular(() => {
2849
+ onStable$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2850
+ this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
2851
+ });
2852
+ });
2845
2853
  this.setContentBackground();
2846
2854
  this.handles.changes
2847
2855
  .pipe(startWith(this.handles), switchMap(() =>
@@ -3048,7 +3056,7 @@ class NgxGanttComponent extends GanttUpper {
3048
3056
  this.childrenResolve(item.origin)
3049
3057
  .pipe(take(1), finalize(() => {
3050
3058
  item.loading = false;
3051
- this.expandChange.emit();
3059
+ this.expandChange.emit(item);
3052
3060
  this.cdr.detectChanges();
3053
3061
  }))
3054
3062
  .subscribe((items) => {
@@ -3058,12 +3066,12 @@ class NgxGanttComponent extends GanttUpper {
3058
3066
  }
3059
3067
  else {
3060
3068
  this.computeItemsRefs(...item.children);
3061
- this.expandChange.emit();
3069
+ this.expandChange.emit(item);
3062
3070
  }
3063
3071
  }
3064
3072
  else {
3065
3073
  item.setExpand(false);
3066
- this.expandChange.emit();
3074
+ this.expandChange.emit(item);
3067
3075
  }
3068
3076
  }
3069
3077
  selectItem(selectEvent) {