-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk-experimental/table): experimental column resize (#16114)
- Loading branch information
Showing
58 changed files
with
2,895 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
ng_module( | ||
name = "column-resize", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/cdk-experimental/column-resize", | ||
deps = [ | ||
"//src/cdk-experimental/popover-edit", | ||
"//src/cdk/bidi", | ||
"//src/cdk/coercion", | ||
"//src/cdk/keycodes", | ||
"//src/cdk/overlay", | ||
"//src/cdk/portal", | ||
"//src/cdk/table", | ||
"@npm//@angular/common", | ||
"@npm//@angular/core", | ||
"@npm//rxjs", | ||
], | ||
) |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/column-resize-flex.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Explicitly enables column resizing for a flexbox-based cdk-table. | ||
* Individual columns must be annotated specifically. | ||
*/ | ||
@Directive({ | ||
selector: 'cdk-table[columnResize]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...FLEX_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkColumnResizeFlex}, | ||
], | ||
}) | ||
export class CdkColumnResizeFlex extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/column-resize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Explicitly enables column resizing for a table-based cdk-table. | ||
* Individual columns must be annotated specifically. | ||
*/ | ||
@Directive({ | ||
selector: 'table[cdk-table][columnResize]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...TABLE_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkColumnResize}, | ||
], | ||
}) | ||
export class CdkColumnResize extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/cdk-experimental/column-resize/column-resize-directives/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Provider} from '@angular/core'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import { | ||
TABLE_LAYOUT_FIXED_RESIZE_STRATEGY_PROVIDER, | ||
FLEX_RESIZE_STRATEGY_PROVIDER, | ||
} from '../resize-strategy'; | ||
|
||
const PROVIDERS: Provider[] = [ | ||
ColumnResizeNotifier, | ||
HeaderRowEventDispatcher, | ||
ColumnResizeNotifierSource, | ||
]; | ||
|
||
export const TABLE_PROVIDERS: Provider[] = [ | ||
...PROVIDERS, | ||
TABLE_LAYOUT_FIXED_RESIZE_STRATEGY_PROVIDER, | ||
]; | ||
export const FLEX_PROVIDERS: Provider[] = [...PROVIDERS, FLEX_RESIZE_STRATEGY_PROVIDER]; | ||
export const HOST_BINDINGS = { | ||
'[class.cdk-column-resize-rtl]': 'directionality.value === "rtl"', | ||
}; |
39 changes: 39 additions & 0 deletions
39
...experimental/column-resize/column-resize-directives/default-enabled-column-resize-flex.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Implicitly enables column resizing for a flex cdk-table. | ||
* Individual columns will be resizable unless opted out. | ||
*/ | ||
@Directive({ | ||
selector: 'cdk-table', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...FLEX_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResizeFlex}, | ||
], | ||
}) | ||
export class CdkDefaultEnabledColumnResizeFlex extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/default-enabled-column-resize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Implicitly enables column resizing for a table-based cdk-table. | ||
* Individual columns will be resizable unless opted out. | ||
*/ | ||
@Directive({ | ||
selector: 'table[cdk-table]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...TABLE_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResize}, | ||
], | ||
}) | ||
export class CdkDefaultEnabledColumnResize extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/cdk-experimental/column-resize/column-resize-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
|
||
import {CdkColumnResize} from './column-resize-directives/column-resize'; | ||
import {CdkColumnResizeFlex} from './column-resize-directives/column-resize-flex'; | ||
import { | ||
CdkDefaultEnabledColumnResize | ||
} from './column-resize-directives/default-enabled-column-resize'; | ||
import { | ||
CdkDefaultEnabledColumnResizeFlex | ||
} from './column-resize-directives/default-enabled-column-resize-flex'; | ||
|
||
/** | ||
* One of two NgModules for use with CdkColumnResize. | ||
* When using this module, columns are resizable by default. | ||
*/ | ||
@NgModule({ | ||
declarations: [CdkDefaultEnabledColumnResize, CdkDefaultEnabledColumnResizeFlex], | ||
exports: [CdkDefaultEnabledColumnResize, CdkDefaultEnabledColumnResizeFlex], | ||
}) | ||
export class CdkColumnResizeDefaultEnabledModule {} | ||
|
||
/** | ||
* One of two NgModules for use with CdkColumnResize. | ||
* When using this module, columns are not resizable by default. | ||
*/ | ||
@NgModule({ | ||
declarations: [CdkColumnResize, CdkColumnResizeFlex], | ||
exports: [CdkColumnResize, CdkColumnResizeFlex], | ||
}) | ||
export class CdkColumnResizeModule {} |
56 changes: 56 additions & 0 deletions
56
src/cdk-experimental/column-resize/column-resize-notifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Injectable} from '@angular/core'; | ||
import {Observable, Subject} from 'rxjs'; | ||
|
||
/** Indicates the width of a column. */ | ||
export interface ColumnSize { | ||
/** The ID/name of the column, as defined in CdkColumnDef. */ | ||
readonly columnId: string; | ||
|
||
/** The width in pixels of the column. */ | ||
readonly size: number; | ||
} | ||
|
||
/** Interface describing column size changes. */ | ||
export interface ColumnSizeAction extends ColumnSize { | ||
/** | ||
* Whether the resize action should be applied instantaneously. False for events triggered during | ||
* a UI-triggered resize (such as with the mouse) until the mouse button is released. True | ||
* for all programatically triggered resizes. | ||
*/ | ||
readonly completeImmediately?: boolean; | ||
} | ||
|
||
/** Originating source of column resize events within a table. */ | ||
@Injectable() | ||
export class ColumnResizeNotifierSource { | ||
/** Emits when an in-progress resize is canceled. */ | ||
readonly resizeCanceled = new Subject<ColumnSizeAction>(); | ||
|
||
/** Emits when a resize is applied. */ | ||
readonly resizeCompleted = new Subject<ColumnSize>(); | ||
|
||
/** Triggers a resize action. */ | ||
readonly triggerResize = new Subject<ColumnSizeAction>(); | ||
} | ||
|
||
/** Service for triggering column resizes imperatively or being notified of them. */ | ||
@Injectable() | ||
export class ColumnResizeNotifier { | ||
/** Emits whenever a column is resized. */ | ||
readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted.asObservable(); | ||
|
||
constructor(private readonly _source: ColumnResizeNotifierSource) {} | ||
|
||
/** Instantly resizes the specified column. */ | ||
resize(columnId: string, size: number): void { | ||
this._source.triggerResize.next({columnId, size, completeImmediately: true}); | ||
} | ||
} |
Oops, something went wrong.