fixed tab rearranging conditions

This commit is contained in:
Eugene Pankov 2022-02-09 20:30:40 +01:00
parent c736a84835
commit f27e1ec62d
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -4,6 +4,7 @@ import { AppService } from '../services/app.service'
import { BaseTabComponent } from './baseTab.component' import { BaseTabComponent } from './baseTab.component'
import { SelfPositioningComponent } from './selfPositioning.component' import { SelfPositioningComponent } from './selfPositioning.component'
import { SplitDropZoneInfo } from './splitTab.component' import { SplitDropZoneInfo } from './splitTab.component'
import { SplitTabComponent } from './splitTab.component'
/** @hidden */ /** @hidden */
@Component({ @Component({
@ -22,7 +23,7 @@ import { SplitDropZoneInfo } from './splitTab.component'
}) })
export class SplitTabDropZoneComponent extends SelfPositioningComponent { export class SplitTabDropZoneComponent extends SelfPositioningComponent {
@Input() dropZone: SplitDropZoneInfo @Input() dropZone: SplitDropZoneInfo
@Input() parent: BaseTabComponent @Input() parent: SplitTabComponent
@Output() tabDropped = new EventEmitter<BaseTabComponent>() @Output() tabDropped = new EventEmitter<BaseTabComponent>()
@HostBinding('class.active') isActive = false @HostBinding('class.active') isActive = false
@HostBinding('class.highlighted') isHighlighted = false @HostBinding('class.highlighted') isHighlighted = false
@ -34,11 +35,21 @@ export class SplitTabDropZoneComponent extends SelfPositioningComponent {
) { ) {
super(element) super(element)
this.subscribeUntilDestroyed(app.tabDragActive$, tab => { this.subscribeUntilDestroyed(app.tabDragActive$, tab => {
this.isActive = !!tab && tab !== this.parent && (this.dropZone.type === 'relative' || tab !== this.dropZone.container.children[this.dropZone.position]) this.isActive = !!tab && this.canActivateFor(tab)
this.layout() this.layout()
}) })
} }
canActivateFor (tab: BaseTabComponent): boolean {
const allTabs = this.parent.getAllTabs()
return !(
tab === this.parent ||
allTabs.length === 1 && allTabs.includes(tab) ||
this.dropZone.type === 'relative' && tab === this.dropZone.relativeTo ||
this.dropZone.type === 'absolute' && tab === this.dropZone.container.children[this.dropZone.position]
)
}
ngOnChanges () { ngOnChanges () {
this.layout() this.layout()
} }