3
3
ElementRef ,
4
4
Inject ,
5
5
Injector ,
6
+ NgZone ,
6
7
OnDestroy ,
7
8
Type ,
8
9
ViewContainerRef
@@ -20,7 +21,7 @@ import {closest} from '../popover-edit/polyfill';
20
21
import { HEADER_ROW_SELECTOR } from './constants' ;
21
22
import { ResizeOverlayHandle } from './overlay-handle' ;
22
23
import { ColumnResize } from './column-resize' ;
23
- import { ColumnSize , _ColumnResizeNotifierSource } from './column-resize-notifier' ;
24
+ import { ColumnSizeAction , _ColumnResizeNotifierSource } from './column-resize-notifier' ;
24
25
import { _HeaderRowEventDispatcher } from './event-dispatcher' ;
25
26
import { ResizeRef } from './resize-ref' ;
26
27
@@ -29,6 +30,7 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
29
30
minPx : number = 0 ;
30
31
maxPx : number = Number . MAX_SAFE_INTEGER ;
31
32
33
+ protected inlineHandle ?: HTMLElement ;
32
34
protected overlayRef ?: OverlayRef ;
33
35
protected readonly destroyed = new ReplaySubject < void > ( ) ;
34
36
protected readonly document : Document ;
@@ -42,6 +44,7 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
42
44
protected readonly elementRef : ElementRef ,
43
45
protected readonly eventDispatcher : _HeaderRowEventDispatcher ,
44
46
protected readonly injector : Injector ,
47
+ protected readonly ngZone : NgZone ,
45
48
protected readonly overlay : Overlay ,
46
49
protected readonly resizeNotifier : _ColumnResizeNotifierSource ,
47
50
protected readonly viewContainerRef : ViewContainerRef ) {
@@ -57,6 +60,10 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
57
60
ngOnDestroy ( ) : void {
58
61
this . destroyed . next ( ) ;
59
62
this . destroyed . complete ( ) ;
63
+
64
+ if ( this . inlineHandle ) {
65
+ this . elementRef . nativeElement ! . removeChild ( this . inlineHandle ) ;
66
+ }
60
67
61
68
if ( this . overlayRef ) {
62
69
this . overlayRef . dispose ( ) ;
@@ -77,14 +84,13 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
77
84
protected abstract getColumnCssClassName ( ) : string ;
78
85
79
86
private _listenForRowHoverEvents ( ) : void {
80
- console . log ( 'init' , this . columnDef . name ) ;
81
87
const element = this . elementRef . nativeElement ! ;
82
88
const takeUntilDestroyed = takeUntil < boolean > ( this . destroyed ) ;
83
89
84
90
85
91
this . eventDispatcher . resizeOverlayVisibleForHeaderRow ( closest ( element , HEADER_ROW_SELECTOR ) ! )
86
92
. pipe ( takeUntilDestroyed ) . subscribe ( hoveringRow => {
87
- if ( hoveringRow ) { console . log ( 'a' , hoveringRow , this . columnDef . name ) ;
93
+ if ( hoveringRow ) {
88
94
if ( ! this . overlayRef ) {
89
95
this . overlayRef = this . createOverlayForHandle ( ) ;
90
96
}
@@ -95,50 +101,44 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
95
101
this . overlayRef . detach ( ) ;
96
102
}
97
103
} ) ;
98
-
99
- this . eventDispatcher . cellOrRelatedOverlayHovered ( element )
100
- . pipe ( takeUntilDestroyed ) . subscribe ( hovering => {
101
- // TODO: Use toggle once we're off IE11.
102
- if ( hovering ) {
103
- element . classList . add ( 'resizable-hover' ) ;
104
- } else {
105
- element . classList . remove ( 'resizable-hover' ) ;
106
- }
107
- } ) ;
108
-
109
- this . eventDispatcher . nextCellOrRelatedOverlayHovered ( element )
110
- . pipe ( takeUntilDestroyed ) . subscribe ( hoveringNext => {
111
- // TODO: Use toggle once we're off IE11.
112
- if ( hoveringNext ) {
113
- element . classList . add ( 'next-resizable-hover' ) ;
114
- } else {
115
- element . classList . remove ( 'next-resizable-hover' ) ;
116
- }
117
- } ) ;
118
104
}
119
105
120
106
private _listenForResizeEvents ( ) {
121
- const takeUntilDestroyed = takeUntil < ColumnSize > ( this . destroyed ) ;
107
+ const takeUntilDestroyed = takeUntil < ColumnSizeAction > ( this . destroyed ) ;
122
108
123
109
merge (
124
110
this . resizeNotifier . resizeCanceled ,
125
111
this . resizeNotifier . triggerResize ,
126
112
) . pipe (
127
113
takeUntilDestroyed ,
128
114
filter ( columnSize => columnSize . columnId === this . columnDef . name ) ,
129
- ) . subscribe ( ( { size} ) => {
130
- this . _applySize ( size ) ;
115
+ ) . subscribe ( ( { size, completeImmediately} ) => {
131
116
this . elementRef . nativeElement ! . classList . add ( 'resizable-overlay-thumb-active' ) ;
117
+ this . _applySize ( size ) ;
118
+
119
+ if ( completeImmediately ) {
120
+ this . ngZone . run ( ( ) => {
121
+ this . resizeNotifier . resizeCompleted . next ( {
122
+ columnId : this . columnDef . name ,
123
+ size : this . elementRef . nativeElement ! . offsetWidth ,
124
+ } ) ;
125
+ } ) ;
126
+ }
132
127
} ) ;
133
128
134
129
merge (
135
130
this . resizeNotifier . resizeCanceled ,
136
131
this . resizeNotifier . resizeCompleted ,
137
- ) . pipe ( takeUntilDestroyed ) . subscribe ( ( ) => {
132
+ ) . pipe ( takeUntilDestroyed ) . subscribe ( columnSize => {
133
+ this . elementRef . nativeElement ! . classList . remove ( 'resizable-overlay-thumb-active' ) ;
134
+
138
135
if ( this . overlayRef && this . overlayRef . hasAttached ( ) ) {
139
136
this . _updateOverlayHandleHeight ( ) ;
140
- this . elementRef . nativeElement ! . classList . remove ( 'resizable-overlay-thumb-active' ) ;
141
137
this . overlayRef . updatePosition ( ) ;
138
+
139
+ if ( columnSize . columnId === this . columnDef . name ) {
140
+ this . inlineHandle ! . focus ( ) ;
141
+ }
142
142
}
143
143
} ) ;
144
144
}
@@ -150,9 +150,9 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
150
150
return new ComponentPortal ( this . getOverlayHandleComponentType ( ) , this . viewContainerRef , injector ) ;
151
151
}
152
152
153
- private _showHandleOverlay ( ) : void { console . log ( 'b' ) ;
153
+ private _showHandleOverlay ( ) : void {
154
154
this . _updateOverlayHandleHeight ( ) ;
155
- this . overlayRef ! . attach ( this . _createHandlePortal ( ) ) ; console . log ( 'c' ) ;
155
+ this . overlayRef ! . attach ( this . _createHandlePortal ( ) ) ;
156
156
}
157
157
158
158
private _updateOverlayHandleHeight ( ) {
@@ -161,20 +161,18 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
161
161
162
162
private _applySize ( sizeInPixels : number ) : void {
163
163
const sizeToApply = Math . min ( Math . max ( sizeInPixels , this . minPx , 0 ) , this . maxPx ) ;
164
- const columnClassName = this . getColumnCssClassName ( ) ;
164
+ /* const columnClassName = this.getColumnCssClassName();
165
165
const tableClassName = this.columnResize.getIdClass();
166
166
167
- const selector = `.${ tableClassName } .${ columnClassName } ` ;
167
+ const selector = `.${tableClassName} .${columnClassName}`;*/
168
168
const width = coerceCssPixelValue ( sizeToApply ) ;
169
169
170
- console . time ( 'apply size' ) ;
171
-
172
170
// approach 0 (issues if number or order of cols change)
173
171
// also does not work, seemingly
174
172
/* const table = document.querySelector(`.${tableClassName}`);
175
173
const cols = table!.querySelectorAll('col');
176
174
const index = Array.from(this.elementRef.nativeElement!.parentNode.childNodes).indexOf(this.elementRef.nativeElement!);
177
- console.log(cols, index);
175
+
178
176
cols[index].style.width = width;*/
179
177
180
178
// approach 1 (no subsequent updates though)
@@ -186,16 +184,29 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
186
184
// approach 1a
187
185
/* cells[0].style.width = width;*/
188
186
187
+ // approach 1b
188
+
189
+ // With table-layout: fixed, all we have to do is set the size on the
190
+ // header element and the whole column will update.
191
+ // This is by far the fastest way to resize a table column tested.
192
+ // Also tested: resizing by adding CSS selectors, selectors with CSS variables.
193
+ this . elementRef . nativeElement ! . style . boxSizing = 'border-box' ;
194
+ this . elementRef . nativeElement ! . style . width = width ;
195
+
196
+ //////////
197
+ // todo: for flex-based tables, we'll need a different approach.
198
+ //////////
199
+
189
200
// approach 2
190
- if ( ! this . _styleElement ) {
201
+ /* if (!this._styleElement) {
191
202
this._styleElement = this.document.createElement('style');
192
203
this._styleElement.appendChild(this.document.createTextNode(''));
193
204
this.document.head.appendChild(this._styleElement);
194
205
} else {
195
206
(this._styleElement.sheet as CSSStyleSheet).deleteRule(0);
196
207
}
197
208
(this._styleElement.sheet as CSSStyleSheet).insertRule(
198
- `${ selector } {box-sizing: border-box;width:${ width } }` , 0 ) ;
209
+ `${selector} {box-sizing: border-box;width:${width}}`, 0);*/
199
210
200
211
// approach 2.5
201
212
@@ -208,20 +219,18 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
208
219
209
220
210
221
const sheet = this._styleElement.sheet as CSSStyleSheet;
211
- console.log(`${selector} {width:${cssVar}}`);
222
+
212
223
sheet.insertRule(`${selector} {width:var(${cssVar})}`, 0);
213
224
}*/
214
-
215
- console . timeEnd ( 'apply size' ) ;
216
225
}
217
226
218
227
private _appendInlineHandle ( ) : void {
219
- const handle = document . createElement ( 'div' ) ;
220
- handle . tabIndex = 0 ;
221
- handle . className = this . getInlineHandleCssClassName ( ) ;
228
+ this . inlineHandle = document . createElement ( 'div' ) ;
229
+ this . inlineHandle . tabIndex = 0 ;
230
+ this . inlineHandle . className = this . getInlineHandleCssClassName ( ) ;
222
231
223
232
// TODO: Apply correct aria role (probably slider) after a11y spec questions resolved.
224
233
225
- this . elementRef . nativeElement ! . appendChild ( handle ) ;
234
+ this . elementRef . nativeElement ! . appendChild ( this . inlineHandle ) ;
226
235
}
227
236
}
0 commit comments