@scion/components 13.0.0
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.
- package/README.md +40 -0
- package/_components.scss +1 -0
- package/_index.scss +23 -0
- package/dimension/dimension.directive.d.ts +43 -0
- package/dimension/dimension.module.d.ts +13 -0
- package/dimension/package.json +10 -0
- package/dimension/public_api.d.ts +2 -0
- package/dimension/scion-components-dimension.d.ts +5 -0
- package/esm2020/dimension/dimension.directive.mjs +83 -0
- package/esm2020/dimension/dimension.module.mjs +40 -0
- package/esm2020/dimension/public_api.mjs +17 -0
- package/esm2020/dimension/scion-components-dimension.mjs +5 -0
- package/esm2020/public-api.mjs +11 -0
- package/esm2020/sashbox/element-ref.directive.mjs +27 -0
- package/esm2020/sashbox/public_api.mjs +18 -0
- package/esm2020/sashbox/sash-initializer.directive.mjs +32 -0
- package/esm2020/sashbox/sash.directive.mjs +144 -0
- package/esm2020/sashbox/sashbox-accessor.mjs +6 -0
- package/esm2020/sashbox/sashbox.component.mjs +278 -0
- package/esm2020/sashbox/sashbox.module.mjs +71 -0
- package/esm2020/sashbox/scion-components-sashbox.mjs +5 -0
- package/esm2020/scion-components.mjs +5 -0
- package/esm2020/splitter/public_api.mjs +17 -0
- package/esm2020/splitter/scion-components-splitter.mjs +5 -0
- package/esm2020/splitter/splitter.component.mjs +227 -0
- package/esm2020/splitter/splitter.module.mjs +44 -0
- package/esm2020/throbber/ellipsis-throbber/ellipsis-throbber.component.mjs +25 -0
- package/esm2020/throbber/public_api.mjs +17 -0
- package/esm2020/throbber/ripple-throbber/ripple-throbber.component.mjs +25 -0
- package/esm2020/throbber/roller-throbber/roller-throbber.component.mjs +25 -0
- package/esm2020/throbber/scion-components-throbber.mjs +5 -0
- package/esm2020/throbber/spinner-throbber/spinner-throbber.component.mjs +26 -0
- package/esm2020/throbber/throbber.component.mjs +67 -0
- package/esm2020/throbber/throbber.module.mjs +50 -0
- package/esm2020/viewport/native-scrollbar-track-size-provider.service.mjs +114 -0
- package/esm2020/viewport/public_api.mjs +20 -0
- package/esm2020/viewport/scion-components-viewport.mjs +5 -0
- package/esm2020/viewport/scrollable.directive.mjs +93 -0
- package/esm2020/viewport/scrollbar/scrollbar.component.mjs +322 -0
- package/esm2020/viewport/viewport.component.mjs +265 -0
- package/esm2020/viewport/viewport.module.mjs +52 -0
- package/fesm2015/scion-components-dimension.mjs +137 -0
- package/fesm2015/scion-components-dimension.mjs.map +1 -0
- package/fesm2015/scion-components-sashbox.mjs +556 -0
- package/fesm2015/scion-components-sashbox.mjs.map +1 -0
- package/fesm2015/scion-components-splitter.mjs +286 -0
- package/fesm2015/scion-components-splitter.mjs.map +1 -0
- package/fesm2015/scion-components-throbber.mjs +216 -0
- package/fesm2015/scion-components-throbber.mjs.map +1 -0
- package/fesm2015/scion-components-viewport.mjs +846 -0
- package/fesm2015/scion-components-viewport.mjs.map +1 -0
- package/fesm2015/scion-components.mjs +4 -0
- package/fesm2015/scion-components.mjs.map +1 -0
- package/fesm2020/scion-components-dimension.mjs +137 -0
- package/fesm2020/scion-components-dimension.mjs.map +1 -0
- package/fesm2020/scion-components-sashbox.mjs +556 -0
- package/fesm2020/scion-components-sashbox.mjs.map +1 -0
- package/fesm2020/scion-components-splitter.mjs +284 -0
- package/fesm2020/scion-components-splitter.mjs.map +1 -0
- package/fesm2020/scion-components-throbber.mjs +216 -0
- package/fesm2020/scion-components-throbber.mjs.map +1 -0
- package/fesm2020/scion-components-viewport.mjs +842 -0
- package/fesm2020/scion-components-viewport.mjs.map +1 -0
- package/fesm2020/scion-components.mjs +14 -0
- package/fesm2020/scion-components.mjs.map +1 -0
- package/package.json +93 -0
- package/public-api.d.ts +4 -0
- package/sashbox/element-ref.directive.d.ts +12 -0
- package/sashbox/package.json +10 -0
- package/sashbox/public_api.d.ts +3 -0
- package/sashbox/sash-initializer.directive.d.ts +14 -0
- package/sashbox/sash.directive.d.ts +60 -0
- package/sashbox/sashbox-accessor.d.ts +10 -0
- package/sashbox/sashbox.component.d.ts +90 -0
- package/sashbox/sashbox.module.d.ts +33 -0
- package/sashbox/scion-components-sashbox.d.ts +5 -0
- package/scion-components.d.ts +5 -0
- package/splitter/package.json +10 -0
- package/splitter/public_api.d.ts +2 -0
- package/splitter/scion-components-splitter.d.ts +5 -0
- package/splitter/splitter.component.d.ts +104 -0
- package/splitter/splitter.module.d.ts +17 -0
- package/throbber/ellipsis-throbber/ellipsis-throbber.component.d.ts +10 -0
- package/throbber/package.json +10 -0
- package/throbber/public_api.d.ts +2 -0
- package/throbber/ripple-throbber/ripple-throbber.component.d.ts +10 -0
- package/throbber/roller-throbber/roller-throbber.component.d.ts +10 -0
- package/throbber/scion-components-throbber.d.ts +5 -0
- package/throbber/spinner-throbber/spinner-throbber.component.d.ts +11 -0
- package/throbber/throbber.component.d.ts +43 -0
- package/throbber/throbber.module.d.ts +15 -0
- package/viewport/_index.scss +1 -0
- package/viewport/_scrollbar.scss +44 -0
- package/viewport/native-scrollbar-track-size-provider.service.d.ts +42 -0
- package/viewport/package.json +10 -0
- package/viewport/public_api.d.ts +5 -0
- package/viewport/scion-components-viewport.d.ts +5 -0
- package/viewport/scrollable.directive.d.ts +39 -0
- package/viewport/scrollbar/scrollbar.component.d.ts +106 -0
- package/viewport/viewport.component.d.ts +160 -0
- package/viewport/viewport.module.d.ts +14 -0
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Inject, NgZone, Component, ChangeDetectionStrategy, ViewChild, HostBinding, Input, Directive, EventEmitter, Output, HostListener, NgModule } from '@angular/core';
|
|
3
|
+
import * as i5 from '@angular/common';
|
|
4
|
+
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
5
|
+
import { coerceElement } from '@angular/cdk/coercion';
|
|
6
|
+
import { BehaviorSubject, Subject, fromEvent, of, merge, timer } from 'rxjs';
|
|
7
|
+
import { debounceTime, startWith, map, distinctUntilChanged, takeUntil, switchMap, first, withLatestFrom, takeWhile } from 'rxjs/operators';
|
|
8
|
+
import { fromDimension$, fromMutation$ } from '@scion/toolkit/observable';
|
|
9
|
+
import { subscribeInside, filterArray } from '@scion/toolkit/operators';
|
|
10
|
+
import * as i4 from '@angular/cdk/scrolling';
|
|
11
|
+
import { ScrollingModule } from '@angular/cdk/scrolling';
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
15
|
+
*
|
|
16
|
+
* This program and the accompanying materials are made
|
|
17
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
18
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
19
|
+
*
|
|
20
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Provides the native scrollbar tracksize.
|
|
24
|
+
*
|
|
25
|
+
* @dynamic ignore 'strictMetadataEmit' errors due to the usage of {@link Document} as ambient type for DI.
|
|
26
|
+
*/
|
|
27
|
+
class SciNativeScrollbarTrackSizeProvider {
|
|
28
|
+
constructor(_document, _zone) {
|
|
29
|
+
this._document = _document;
|
|
30
|
+
this._zone = _zone;
|
|
31
|
+
this._trackSize$ = new BehaviorSubject(null);
|
|
32
|
+
this._destroy$ = new Subject();
|
|
33
|
+
this.installNativeScrollbarTrackSizeListener();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns an {Observable} which emits the native scrollbar track size, if any, or else `null`.
|
|
37
|
+
*
|
|
38
|
+
* Upon subscription, it emits the track size immediately, and then continuously emits when the track size changes.
|
|
39
|
+
*/
|
|
40
|
+
get trackSize$() {
|
|
41
|
+
return this._trackSize$;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the native scrollbar track size, if any, or else `null`.
|
|
45
|
+
*/
|
|
46
|
+
get trackSize() {
|
|
47
|
+
return this._trackSize$.getValue();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Computes the native scrollbar track size.
|
|
51
|
+
*
|
|
52
|
+
* @returns native track size, or `null` if the native scrollbars sit on top of the content.
|
|
53
|
+
*/
|
|
54
|
+
computeTrackSize() {
|
|
55
|
+
// create temporary viewport and viewport client with native scrollbars to compute scrolltrack width
|
|
56
|
+
const viewportDiv = this._document.createElement('div');
|
|
57
|
+
setStyle(viewportDiv, {
|
|
58
|
+
position: 'absolute',
|
|
59
|
+
overflow: 'scroll',
|
|
60
|
+
height: '100px',
|
|
61
|
+
width: '100px',
|
|
62
|
+
border: 0,
|
|
63
|
+
visibility: 'hidden',
|
|
64
|
+
});
|
|
65
|
+
const viewportClientDiv = this._document.createElement('div');
|
|
66
|
+
setStyle(viewportClientDiv, {
|
|
67
|
+
height: '100%',
|
|
68
|
+
width: '100%',
|
|
69
|
+
border: 0,
|
|
70
|
+
});
|
|
71
|
+
viewportDiv.appendChild(viewportClientDiv);
|
|
72
|
+
this._document.body.appendChild(viewportDiv);
|
|
73
|
+
const trackSize = {
|
|
74
|
+
hScrollbarTrackHeight: viewportDiv.offsetHeight - viewportClientDiv.offsetHeight,
|
|
75
|
+
vScrollbarTrackWidth: viewportDiv.offsetWidth - viewportClientDiv.offsetWidth,
|
|
76
|
+
};
|
|
77
|
+
// destroy temporary viewport
|
|
78
|
+
this._document.body.removeChild(viewportDiv);
|
|
79
|
+
if (trackSize.hScrollbarTrackHeight === 0 && trackSize.vScrollbarTrackWidth === 0) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return trackSize;
|
|
83
|
+
}
|
|
84
|
+
installNativeScrollbarTrackSizeListener() {
|
|
85
|
+
// We compute the size of the native scrollbar track when the browser fires the onresize window event.
|
|
86
|
+
// This event is also fired on page zoom or when displaying a hidden document. Hidden documents do not have
|
|
87
|
+
// a scrollbar track size until being displayed, e.g., after showing hidden iframes.
|
|
88
|
+
this._zone.runOutsideAngular(() => {
|
|
89
|
+
fromEvent(window, 'resize')
|
|
90
|
+
.pipe(debounceTime(5), startWith(null), // trigger the initial computation
|
|
91
|
+
map(() => this.computeTrackSize()), distinctUntilChanged((t1, t2) => JSON.stringify(t1) === JSON.stringify(t2)), takeUntil(this._destroy$))
|
|
92
|
+
.subscribe(trackSize => {
|
|
93
|
+
this._zone.run(() => this._trackSize$.next(trackSize));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
ngOnDestroy() {
|
|
98
|
+
this._destroy$.next();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
SciNativeScrollbarTrackSizeProvider.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciNativeScrollbarTrackSizeProvider, deps: [{ token: DOCUMENT }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
102
|
+
SciNativeScrollbarTrackSizeProvider.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciNativeScrollbarTrackSizeProvider, providedIn: 'root' });
|
|
103
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciNativeScrollbarTrackSizeProvider, decorators: [{
|
|
104
|
+
type: Injectable,
|
|
105
|
+
args: [{ providedIn: 'root' }]
|
|
106
|
+
}], ctorParameters: function () {
|
|
107
|
+
return [{ type: Document, decorators: [{
|
|
108
|
+
type: Inject,
|
|
109
|
+
args: [DOCUMENT]
|
|
110
|
+
}] }, { type: i0.NgZone }];
|
|
111
|
+
} });
|
|
112
|
+
/**
|
|
113
|
+
* Applies the given style(s) to the given element.
|
|
114
|
+
*
|
|
115
|
+
* Specify styles to be modified by passing a dictionary containing CSS property names (hyphen case).
|
|
116
|
+
* To remove a style, set its value to `null`.
|
|
117
|
+
*
|
|
118
|
+
* @ignore
|
|
119
|
+
*/
|
|
120
|
+
function setStyle(element, style) {
|
|
121
|
+
Object.keys(style).forEach(key => element.style.setProperty(key, style[key]));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
126
|
+
*
|
|
127
|
+
* This program and the accompanying materials are made
|
|
128
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
129
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
130
|
+
*
|
|
131
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
132
|
+
*/
|
|
133
|
+
/**
|
|
134
|
+
* Renders a vertical or horizontal scrollbar.
|
|
135
|
+
*
|
|
136
|
+
* The scrollbar features the following functionality:
|
|
137
|
+
* - allows to move the thumb by mouse or touch
|
|
138
|
+
* - enlarges the thumb if the mouse pointer is near the thumb
|
|
139
|
+
* - allows paging on mousedown on the scroll track
|
|
140
|
+
*
|
|
141
|
+
* ### CSS styling:
|
|
142
|
+
*
|
|
143
|
+
* You can override the following CSS variables:
|
|
144
|
+
*
|
|
145
|
+
* - sci-scrollbar-color: Sets the color of the scrollbar (by default, uses `rgb(78, 78, 78)`).
|
|
146
|
+
*
|
|
147
|
+
* Example:
|
|
148
|
+
*
|
|
149
|
+
* ```css
|
|
150
|
+
*
|
|
151
|
+
* sci-scrollbar {
|
|
152
|
+
* --sci-scrollbar-color: blue;
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
class SciScrollbarComponent {
|
|
157
|
+
constructor(_host, _document, _zone) {
|
|
158
|
+
this._host = _host;
|
|
159
|
+
this._document = _document;
|
|
160
|
+
this._zone = _zone;
|
|
161
|
+
this._destroy$ = new Subject();
|
|
162
|
+
this._viewportChange$ = new Subject();
|
|
163
|
+
this._lastDragPosition = null;
|
|
164
|
+
this._overflow = false;
|
|
165
|
+
this._thumbSizeFr = 0;
|
|
166
|
+
this._thumbPositionFr = 0;
|
|
167
|
+
/**
|
|
168
|
+
* Specifies the direction of the scrollbar.
|
|
169
|
+
*
|
|
170
|
+
* By default, if not specified, renders a vertical scrollbar.
|
|
171
|
+
*/
|
|
172
|
+
this.direction = 'vscroll';
|
|
173
|
+
this._viewportChange$
|
|
174
|
+
.pipe(switchMap(() => {
|
|
175
|
+
if (!this._viewport) {
|
|
176
|
+
return of(undefined);
|
|
177
|
+
}
|
|
178
|
+
return merge(this.viewportScrollChange$(), this.viewportDimensionChange$({ debounceTime: SciScrollbarComponent.VIEWPORT_RESIZE_DEBOUNCE_TIME }), this.viewportClientDimensionChange$({ debounceTime: SciScrollbarComponent.VIEWPORT_RESIZE_DEBOUNCE_TIME }));
|
|
179
|
+
}), subscribeInside(continueFn => this._zone.runOutsideAngular(continueFn)), takeUntil(this._destroy$))
|
|
180
|
+
.subscribe(() => {
|
|
181
|
+
if (this._viewport) {
|
|
182
|
+
this.renderScrollPosition();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
this.unsetScrollPosition();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
get vertical() {
|
|
190
|
+
return this.direction === 'vscroll';
|
|
191
|
+
}
|
|
192
|
+
get horizontal() {
|
|
193
|
+
return this.direction === 'hscroll';
|
|
194
|
+
}
|
|
195
|
+
get scrolling() {
|
|
196
|
+
return this._lastDragPosition !== null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The viewport to provide scrollbars for.
|
|
200
|
+
*/
|
|
201
|
+
set setViewport(viewport) {
|
|
202
|
+
this._viewport = viewport;
|
|
203
|
+
this._viewportChange$.next();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Computes the scroll position and updates CSS variables to render the scroll position in the UI.
|
|
207
|
+
*/
|
|
208
|
+
renderScrollPosition() {
|
|
209
|
+
NgZone.assertNotInAngularZone();
|
|
210
|
+
const viewportSize = this.viewportSize;
|
|
211
|
+
const viewportClientSize = this.viewportClientSize;
|
|
212
|
+
const thumbPositionFr = this.scrollPosition / viewportClientSize;
|
|
213
|
+
const thumbSizeFr = viewportSize / viewportClientSize;
|
|
214
|
+
const overflow = viewportClientSize > viewportSize;
|
|
215
|
+
if (thumbPositionFr !== this._thumbPositionFr || thumbSizeFr !== this._thumbSizeFr) {
|
|
216
|
+
this._thumbPositionFr = thumbPositionFr;
|
|
217
|
+
this._thumbSizeFr = thumbSizeFr;
|
|
218
|
+
this.setCssVariable('--ɵsci-scrollbar-thumb-position-fr', thumbPositionFr);
|
|
219
|
+
this.setCssVariable('--ɵsci-scrollbar-thumb-size-fr', thumbSizeFr);
|
|
220
|
+
}
|
|
221
|
+
if (overflow !== this._overflow) {
|
|
222
|
+
this._overflow = overflow;
|
|
223
|
+
overflow ? this._host.nativeElement.classList.add('overflow') : this._host.nativeElement.classList.remove('overflow');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Clears CSS variables used for rendering the scroll position in the UI.
|
|
228
|
+
*/
|
|
229
|
+
unsetScrollPosition() {
|
|
230
|
+
NgZone.assertNotInAngularZone();
|
|
231
|
+
this._thumbPositionFr = 0;
|
|
232
|
+
this._thumbSizeFr = 0;
|
|
233
|
+
this._overflow = false;
|
|
234
|
+
this.setCssVariable('--ɵsci-scrollbar-thumb-position-fr', 0);
|
|
235
|
+
this.setCssVariable('--ɵsci-scrollbar-thumb-size-fr', 0);
|
|
236
|
+
this._host.nativeElement.classList.remove('overflow');
|
|
237
|
+
}
|
|
238
|
+
/* @docs-private */
|
|
239
|
+
onTouchStart(event) {
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
this._lastDragPosition = this.vertical ? event.touches[0].screenY : event.touches[0].screenX;
|
|
242
|
+
}
|
|
243
|
+
/* @docs-private */
|
|
244
|
+
onTouchMove(event) {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
const newDragPositionPx = this.vertical ? event.touches[0].screenY : event.touches[0].screenX;
|
|
247
|
+
const scrollbarPanPx = newDragPositionPx - this._lastDragPosition;
|
|
248
|
+
const viewportPanPx = this.toViewportPanPx(scrollbarPanPx);
|
|
249
|
+
this._lastDragPosition = newDragPositionPx;
|
|
250
|
+
this.moveViewportClient(viewportPanPx);
|
|
251
|
+
}
|
|
252
|
+
/* @docs-private */
|
|
253
|
+
onTouchEnd(event) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
this._lastDragPosition = null;
|
|
256
|
+
}
|
|
257
|
+
/* @docs-private */
|
|
258
|
+
onMouseDown(mousedownEvent) {
|
|
259
|
+
if (mousedownEvent.button !== 0) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
mousedownEvent.preventDefault();
|
|
263
|
+
this._lastDragPosition = this.vertical ? mousedownEvent.screenY : mousedownEvent.screenX;
|
|
264
|
+
// Listen for 'mousemove' events
|
|
265
|
+
this._zone.runOutsideAngular(() => {
|
|
266
|
+
const mousemoveListener = merge(fromEvent(this._document, 'mousemove'), fromEvent(this._document, 'sci-mousemove'))
|
|
267
|
+
.pipe(takeUntil(this._destroy$))
|
|
268
|
+
.subscribe(mousemoveEvent => {
|
|
269
|
+
mousemoveEvent.preventDefault();
|
|
270
|
+
const newDragPositionPx = this.vertical ? mousemoveEvent.screenY : mousemoveEvent.screenX;
|
|
271
|
+
const scrollbarPanPx = newDragPositionPx - this._lastDragPosition;
|
|
272
|
+
const viewportPanPx = this.toViewportPanPx(scrollbarPanPx);
|
|
273
|
+
this._lastDragPosition = newDragPositionPx;
|
|
274
|
+
this.moveViewportClient(viewportPanPx);
|
|
275
|
+
});
|
|
276
|
+
// Listen for 'mouseup' events; use 'capture phase' and 'stop propagation' to not close overlays
|
|
277
|
+
merge(fromEvent(this._document, 'mouseup', { capture: true }), fromEvent(this._document, 'sci-mouseup'))
|
|
278
|
+
.pipe(first(), takeUntil(this._destroy$))
|
|
279
|
+
.subscribe(mouseupEvent => {
|
|
280
|
+
mouseupEvent.stopPropagation();
|
|
281
|
+
mousemoveListener.unsubscribe();
|
|
282
|
+
this._lastDragPosition = null;
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/* @docs-private */
|
|
287
|
+
onScrollTrackMouseDown(event, direction) {
|
|
288
|
+
const signum = (direction === 'up' ? -1 : +1);
|
|
289
|
+
this.scrollWhileMouseDown(this.toViewportPanPx(signum * this.thumbSize), event);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Projects the given scrollbar scroll pixels into viewport scroll pixels.
|
|
293
|
+
*/
|
|
294
|
+
toViewportPanPx(scrollbarPanPx) {
|
|
295
|
+
const scrollRangePx = this.trackSize - this.thumbSize;
|
|
296
|
+
const scrollRatio = scrollbarPanPx / scrollRangePx;
|
|
297
|
+
return scrollRatio * (this.viewportClientSize - this.viewportSize);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Moves the viewport client by the specified numbers of pixels.
|
|
301
|
+
*/
|
|
302
|
+
moveViewportClient(viewportPanPx) {
|
|
303
|
+
if (this.vertical) {
|
|
304
|
+
this._viewport.scrollTop += viewportPanPx;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this._viewport.scrollLeft += viewportPanPx;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Indicates if the content overflows.
|
|
312
|
+
*/
|
|
313
|
+
get overflow() {
|
|
314
|
+
return this._overflow;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Scrolls continuously while holding the mouse pressed, or until the mouse leaves the scrolltrack.
|
|
318
|
+
*/
|
|
319
|
+
scrollWhileMouseDown(viewportScrollPx, mousedownEvent) {
|
|
320
|
+
// The `EventTarget` type of `Event.target` is not yet compatible with `FromEventTarget` used in `fromEvent`.
|
|
321
|
+
// This will be fixed in rxjs version 7.0.0. Refer to https://github.com/ReactiveX/rxjs/commit/5f022d784570684632e6fd5ae247fc259ee34c4b
|
|
322
|
+
// for more details.
|
|
323
|
+
const scrollTrackElement = mousedownEvent.target;
|
|
324
|
+
// scroll continuously every 50ms after an initial delay of 250ms
|
|
325
|
+
timer(250, 50)
|
|
326
|
+
.pipe(
|
|
327
|
+
// continue chain with latest mouse event
|
|
328
|
+
withLatestFrom(merge(of(mousedownEvent), fromEvent(scrollTrackElement, 'mousemove')), (tick, event) => event),
|
|
329
|
+
// start immediately
|
|
330
|
+
startWith(mousedownEvent),
|
|
331
|
+
// stop scrolling if the thumb hits the mouse pointer position
|
|
332
|
+
takeWhile((event) => scrollTrackElement === this._document.elementFromPoint(event.clientX, event.clientY)), debounceTime(10),
|
|
333
|
+
// stop scrolling on mouseout or mouseup
|
|
334
|
+
takeUntil(merge(fromEvent(scrollTrackElement, 'mouseout'), fromEvent(scrollTrackElement, 'mouseup'))))
|
|
335
|
+
.subscribe(() => {
|
|
336
|
+
this.moveViewportClient(viewportScrollPx);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Emits whenever the viewport scrolls.
|
|
341
|
+
*/
|
|
342
|
+
viewportScrollChange$() {
|
|
343
|
+
return fromEvent(this._viewport, 'scroll', { passive: true }).pipe(map(() => undefined));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Emits on subscription, and then each time the size of the viewport changes.
|
|
347
|
+
*/
|
|
348
|
+
viewportDimensionChange$(options) {
|
|
349
|
+
return fromDimension$(this._viewport)
|
|
350
|
+
.pipe(
|
|
351
|
+
// Debouncing is particularly important in the context of Angular animations, since they continuously
|
|
352
|
+
// trigger resize events. Debouncing prevents the scrollbar from flickering, for example, when the user
|
|
353
|
+
// expands a panel that contains a viewport.
|
|
354
|
+
debounceTime(options.debounceTime), map(() => undefined));
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Emits on subscription, and then each time the size or style property of the viewport client changes.
|
|
358
|
+
*/
|
|
359
|
+
viewportClientDimensionChange$(options) {
|
|
360
|
+
return this.children$(this._viewport)
|
|
361
|
+
.pipe(switchMap(children => merge(...children.map(child => merge(fromDimension$(child),
|
|
362
|
+
// Observe style mutations since some transformations change the scroll position without necessarily triggering a dimension change,
|
|
363
|
+
// e.g., `scale` or `translate` used by some virtual scroll implementations
|
|
364
|
+
fromMutation$(child, { subtree: false, childList: false, attributeFilter: ['style'] }))))),
|
|
365
|
+
// Debouncing is particularly important in the context of Angular animations, since they continuously
|
|
366
|
+
// trigger resize events. Debouncing prevents the scrollbar from flickering, for example, when the user
|
|
367
|
+
// expands a panel that contains a viewport.
|
|
368
|
+
debounceTime(options.debounceTime), map(() => undefined));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Emits the children of the passed element, and then each time child elements are added or removed.
|
|
372
|
+
*/
|
|
373
|
+
children$(element) {
|
|
374
|
+
return fromMutation$(element, { subtree: false, childList: true })
|
|
375
|
+
.pipe(startWith(undefined), map(() => Array.from(element.children)), filterArray((child) => child instanceof HTMLElement));
|
|
376
|
+
}
|
|
377
|
+
setCssVariable(key, value) {
|
|
378
|
+
this._host.nativeElement.style.setProperty(key, value);
|
|
379
|
+
}
|
|
380
|
+
get viewportSize() {
|
|
381
|
+
return this._viewport ? (this.vertical ? this._viewport.clientHeight : this._viewport.clientWidth) : 0;
|
|
382
|
+
}
|
|
383
|
+
get viewportClientSize() {
|
|
384
|
+
return this._viewport ? (this.vertical ? this._viewport.scrollHeight : this._viewport.scrollWidth) : 0;
|
|
385
|
+
}
|
|
386
|
+
get scrollPosition() {
|
|
387
|
+
return this._viewport ? (this.vertical ? this._viewport.scrollTop : this._viewport.scrollLeft) : 0;
|
|
388
|
+
}
|
|
389
|
+
get thumbSize() {
|
|
390
|
+
const thumbElement = this.thumbElement.nativeElement;
|
|
391
|
+
return this.vertical ? thumbElement.clientHeight : thumbElement.clientWidth;
|
|
392
|
+
}
|
|
393
|
+
get trackSize() {
|
|
394
|
+
const trackElement = this._host.nativeElement;
|
|
395
|
+
return this.vertical ? trackElement.clientHeight : trackElement.clientWidth;
|
|
396
|
+
}
|
|
397
|
+
/* @docs-private */
|
|
398
|
+
ngOnDestroy() {
|
|
399
|
+
this._destroy$.next();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Timeout for debouncing viewport resize events that trigger the scroll position computation.
|
|
404
|
+
*
|
|
405
|
+
* Debouncing is particularly important in the context of Angular animations, since they continuously
|
|
406
|
+
* trigger resize events. Debouncing prevents the scrollbar from flickering, for example, when the user
|
|
407
|
+
* expands a panel that contains a viewport.
|
|
408
|
+
*
|
|
409
|
+
* @internal
|
|
410
|
+
*/
|
|
411
|
+
SciScrollbarComponent.VIEWPORT_RESIZE_DEBOUNCE_TIME = 50;
|
|
412
|
+
SciScrollbarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciScrollbarComponent, deps: [{ token: i0.ElementRef }, { token: DOCUMENT }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
|
|
413
|
+
SciScrollbarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.3", type: SciScrollbarComponent, selector: "sci-scrollbar", inputs: { direction: "direction", setViewport: ["viewport", "setViewport"] }, host: { properties: { "class.vertical": "this.vertical", "class.horizontal": "this.horizontal", "class.scrolling": "this.scrolling" } }, viewQueries: [{ propertyName: "thumbElement", first: true, predicate: ["thumb_handle"], descendants: true, static: true }], ngImport: i0, template: "<!-- scrolltrack to move the viewport client upwards (paging) -->\n<div class=\"scrolltrack-start\" (mousedown)=\"onScrollTrackMouseDown($event, 'up')\"></div>\n\n<!-- scrollthumb -->\n<div #thumb_handle\n class=\"thumb-handle\"\n [class.vertical]=\"vertical\"\n [class.horizontal]=\"horizontal\"\n (mousedown)=\"onMouseDown($event)\"\n (touchstart)=\"onTouchStart($event)\"\n (touchmove)=\"onTouchMove($event)\"\n (touchend)=\"onTouchEnd($event)\"\n (touchcancel)=\"onTouchEnd($event)\">\n <div class=\"thumb\"\n [class.vertical]=\"vertical\"\n [class.horizontal]=\"horizontal\">\n </div>\n</div>\n\n<!-- scrolltrack to move the viewport client downwards (paging) -->\n<div class=\"scrolltrack-end\" (mousedown)=\"onScrollTrackMouseDown($event, 'down')\"></div>\n", styles: ["@charset \"UTF-8\";:host{display:flex;border:2px solid transparent;box-sizing:border-box;--sci-scrollbar-color: rgb(78, 78, 78);--\\275sci-scrollbar-thumb-position-fr: 0;--\\275sci-scrollbar-thumb-size-fr: 0}:host.vertical{flex-direction:column}:host.horizontal{flex-direction:row}:host>div.scrolltrack-start{flex-grow:var(--\\275sci-scrollbar-thumb-position-fr)}:host>div.thumb-handle{flex-basis:20px;display:flex;flex-grow:var(--\\275sci-scrollbar-thumb-size-fr);align-items:center}:host>div.thumb-handle.vertical{flex-direction:column}:host>div.thumb-handle.horizontal{flex-direction:row}:host>div.thumb-handle>div.thumb{flex:auto;border-radius:4px;background-color:var(--sci-scrollbar-color);opacity:.4;transition-duration:125ms;transition-property:width,height;transition-timing-function:ease-out}:host>div.thumb-handle>div.thumb.vertical{width:60%}:host>div.thumb-handle>div.thumb.horizontal{height:60%}:host>div.scrolltrack-end{flex-grow:calc(1 - (var(--\\275sci-scrollbar-thumb-position-fr) + var(--\\275sci-scrollbar-thumb-size-fr)))}:host-context:not(.overflow){display:none}:host-context:hover>div.thumb-handle>div.thumb,:host-context(.scrolling)>div.thumb-handle>div.thumb{background-color:var(--sci-scrollbar-color);opacity:.75}:host-context:hover>div.thumb-handle>div.thumb.vertical,:host-context(.scrolling)>div.thumb-handle>div.thumb.vertical{width:100%}:host-context:hover>div.thumb-handle>div.thumb.horizontal,:host-context(.scrolling)>div.thumb-handle>div.thumb.horizontal{height:100%}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
414
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciScrollbarComponent, decorators: [{
|
|
415
|
+
type: Component,
|
|
416
|
+
args: [{ selector: 'sci-scrollbar', changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- scrolltrack to move the viewport client upwards (paging) -->\n<div class=\"scrolltrack-start\" (mousedown)=\"onScrollTrackMouseDown($event, 'up')\"></div>\n\n<!-- scrollthumb -->\n<div #thumb_handle\n class=\"thumb-handle\"\n [class.vertical]=\"vertical\"\n [class.horizontal]=\"horizontal\"\n (mousedown)=\"onMouseDown($event)\"\n (touchstart)=\"onTouchStart($event)\"\n (touchmove)=\"onTouchMove($event)\"\n (touchend)=\"onTouchEnd($event)\"\n (touchcancel)=\"onTouchEnd($event)\">\n <div class=\"thumb\"\n [class.vertical]=\"vertical\"\n [class.horizontal]=\"horizontal\">\n </div>\n</div>\n\n<!-- scrolltrack to move the viewport client downwards (paging) -->\n<div class=\"scrolltrack-end\" (mousedown)=\"onScrollTrackMouseDown($event, 'down')\"></div>\n", styles: ["@charset \"UTF-8\";:host{display:flex;border:2px solid transparent;box-sizing:border-box;--sci-scrollbar-color: rgb(78, 78, 78);--\\275sci-scrollbar-thumb-position-fr: 0;--\\275sci-scrollbar-thumb-size-fr: 0}:host.vertical{flex-direction:column}:host.horizontal{flex-direction:row}:host>div.scrolltrack-start{flex-grow:var(--\\275sci-scrollbar-thumb-position-fr)}:host>div.thumb-handle{flex-basis:20px;display:flex;flex-grow:var(--\\275sci-scrollbar-thumb-size-fr);align-items:center}:host>div.thumb-handle.vertical{flex-direction:column}:host>div.thumb-handle.horizontal{flex-direction:row}:host>div.thumb-handle>div.thumb{flex:auto;border-radius:4px;background-color:var(--sci-scrollbar-color);opacity:.4;transition-duration:125ms;transition-property:width,height;transition-timing-function:ease-out}:host>div.thumb-handle>div.thumb.vertical{width:60%}:host>div.thumb-handle>div.thumb.horizontal{height:60%}:host>div.scrolltrack-end{flex-grow:calc(1 - (var(--\\275sci-scrollbar-thumb-position-fr) + var(--\\275sci-scrollbar-thumb-size-fr)))}:host-context:not(.overflow){display:none}:host-context:hover>div.thumb-handle>div.thumb,:host-context(.scrolling)>div.thumb-handle>div.thumb{background-color:var(--sci-scrollbar-color);opacity:.75}:host-context:hover>div.thumb-handle>div.thumb.vertical,:host-context(.scrolling)>div.thumb-handle>div.thumb.vertical{width:100%}:host-context:hover>div.thumb-handle>div.thumb.horizontal,:host-context(.scrolling)>div.thumb-handle>div.thumb.horizontal{height:100%}\n"] }]
|
|
417
|
+
}], ctorParameters: function () {
|
|
418
|
+
return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
|
|
419
|
+
type: Inject,
|
|
420
|
+
args: [DOCUMENT]
|
|
421
|
+
}] }, { type: i0.NgZone }];
|
|
422
|
+
}, propDecorators: { thumbElement: [{
|
|
423
|
+
type: ViewChild,
|
|
424
|
+
args: ['thumb_handle', { static: true }]
|
|
425
|
+
}], vertical: [{
|
|
426
|
+
type: HostBinding,
|
|
427
|
+
args: ['class.vertical']
|
|
428
|
+
}], horizontal: [{
|
|
429
|
+
type: HostBinding,
|
|
430
|
+
args: ['class.horizontal']
|
|
431
|
+
}], scrolling: [{
|
|
432
|
+
type: HostBinding,
|
|
433
|
+
args: ['class.scrolling']
|
|
434
|
+
}], direction: [{
|
|
435
|
+
type: Input
|
|
436
|
+
}], setViewport: [{
|
|
437
|
+
type: Input,
|
|
438
|
+
args: ['viewport']
|
|
439
|
+
}] } });
|
|
440
|
+
|
|
441
|
+
/*
|
|
442
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
443
|
+
*
|
|
444
|
+
* This program and the accompanying materials are made
|
|
445
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
446
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
447
|
+
*
|
|
448
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
449
|
+
*/
|
|
450
|
+
/**
|
|
451
|
+
* Makes the host element natively scrollable and hides native scrollbars by default, unless native scrollbars
|
|
452
|
+
* already sit on top of the viewport (e.g. in OS X).
|
|
453
|
+
*
|
|
454
|
+
* Because there is no cross-browser API to hide scrollbars without losing native scroll support, we set 'overflow'
|
|
455
|
+
* to 'scroll' but shift the native scrollbars out of the visible viewport area. The shift offset is computed upfront.
|
|
456
|
+
*
|
|
457
|
+
* This directive expects its host element to be the only child in document flow in its parent DOM element. It makes the host element
|
|
458
|
+
* fill up the entire space (width and height set to 100%). The parent element must have its CSS `overflow` property set to `hidden`
|
|
459
|
+
* to hide the pushed out native scrollbars.
|
|
460
|
+
*/
|
|
461
|
+
class SciScrollableDirective {
|
|
462
|
+
constructor(_host, _renderer, nativeScrollbarTrackSizeProvider) {
|
|
463
|
+
this._host = _host;
|
|
464
|
+
this._renderer = _renderer;
|
|
465
|
+
this._destroy$ = new Subject();
|
|
466
|
+
this._inputChange$ = new Subject();
|
|
467
|
+
/**
|
|
468
|
+
* Controls whether to display native scrollbars.
|
|
469
|
+
* Has no effect if the native scrollbar sits on top of the content, e.g. in OS X.
|
|
470
|
+
*/
|
|
471
|
+
this.isDisplayNativeScrollbar = false;
|
|
472
|
+
merge(nativeScrollbarTrackSizeProvider.trackSize$, this._inputChange$.pipe(map(() => nativeScrollbarTrackSizeProvider.trackSize)))
|
|
473
|
+
.pipe(takeUntil(this._destroy$))
|
|
474
|
+
.subscribe(nativeScrollbarTrackSize => {
|
|
475
|
+
if (nativeScrollbarTrackSize === null) { // the native scrollbar sits on top of the content
|
|
476
|
+
this.useNativeScrollbars();
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
this.isDisplayNativeScrollbar ? this.useNativeScrollbars() : this.shiftNativeScrollbars(nativeScrollbarTrackSize);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Uses the native scrollbars when content overflows.
|
|
485
|
+
*/
|
|
486
|
+
useNativeScrollbars() {
|
|
487
|
+
this.setStyle(this._host.nativeElement, {
|
|
488
|
+
overflow: 'auto',
|
|
489
|
+
width: '100%',
|
|
490
|
+
height: '100%',
|
|
491
|
+
marginRight: 0,
|
|
492
|
+
marginBottom: 0,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Shifts the native scrollbars out of the visible viewport area.
|
|
497
|
+
*/
|
|
498
|
+
shiftNativeScrollbars(nativeScrollbarTrackSize) {
|
|
499
|
+
this.setStyle(this._host.nativeElement, {
|
|
500
|
+
overflow: 'scroll',
|
|
501
|
+
width: `calc(100% + ${nativeScrollbarTrackSize.vScrollbarTrackWidth}px`,
|
|
502
|
+
height: `calc(100% + ${nativeScrollbarTrackSize.hScrollbarTrackHeight}px`,
|
|
503
|
+
marginRight: `-${nativeScrollbarTrackSize.vScrollbarTrackWidth}px`,
|
|
504
|
+
marginBottom: `-${nativeScrollbarTrackSize.hScrollbarTrackHeight}px`,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
setStyle(element, style) {
|
|
508
|
+
Object.keys(style).forEach(key => this._renderer.setStyle(element, key, style[key]));
|
|
509
|
+
}
|
|
510
|
+
ngOnChanges(changes) {
|
|
511
|
+
this._inputChange$.next();
|
|
512
|
+
}
|
|
513
|
+
ngOnDestroy() {
|
|
514
|
+
this._destroy$.next();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
SciScrollableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciScrollableDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: SciNativeScrollbarTrackSizeProvider }], target: i0.ɵɵFactoryTarget.Directive });
|
|
518
|
+
SciScrollableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: SciScrollableDirective, selector: "[sciScrollable]", inputs: { isDisplayNativeScrollbar: ["sciScrollableDisplayNativeScrollbar", "isDisplayNativeScrollbar"] }, usesOnChanges: true, ngImport: i0 });
|
|
519
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciScrollableDirective, decorators: [{
|
|
520
|
+
type: Directive,
|
|
521
|
+
args: [{
|
|
522
|
+
selector: '[sciScrollable]',
|
|
523
|
+
}]
|
|
524
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: SciNativeScrollbarTrackSizeProvider }]; }, propDecorators: { isDisplayNativeScrollbar: [{
|
|
525
|
+
type: Input,
|
|
526
|
+
args: ['sciScrollableDisplayNativeScrollbar']
|
|
527
|
+
}] } });
|
|
528
|
+
|
|
529
|
+
/*
|
|
530
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
531
|
+
*
|
|
532
|
+
* This program and the accompanying materials are made
|
|
533
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
534
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
535
|
+
*
|
|
536
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
537
|
+
*/
|
|
538
|
+
/**
|
|
539
|
+
* Represents a viewport with the `<ng-content>` used as scrollable content. Content is added to a CSS grid layout.
|
|
540
|
+
*
|
|
541
|
+
* The viewport component displays scrollbars when its content overflows. Scrollbars are displayed on top of the content, not next to it.
|
|
542
|
+
* The component uses the native scrollbars of the operating system if they are already sitting on top, or falls back and renders scrollbars on top otherwise.
|
|
543
|
+
* The viewport remains natively scrollable with the native scrollbars shifted out of the viewport's visible area. Consequently, the viewport keeps supporting
|
|
544
|
+
* native scrolling features such as touch gestures, scroll speed acceleration, or scrolling near the viewport edges during drag-and-drop operations.
|
|
545
|
+
*
|
|
546
|
+
* ```html
|
|
547
|
+
* <sci-viewport>
|
|
548
|
+
* your content
|
|
549
|
+
* </sci-viewport>
|
|
550
|
+
* ```
|
|
551
|
+
*
|
|
552
|
+
* ## Adding the viewport to a layout
|
|
553
|
+
*
|
|
554
|
+
* Typically you would add the viewport component to a flexible layout, filling the remaining space vertically and horizontally, such as a flexbox container
|
|
555
|
+
* with the viewport's `flex` CSS property set to either `flex: auto` or `flex: 1 1 0`.
|
|
556
|
+
*
|
|
557
|
+
* The viewport is sized according to its content width and height. It grows to absorb any free space, thus overflowing its content only when encountering
|
|
558
|
+
* a layout constraint. Depending on the layout, different steps may be necessary to prevent the viewport from growing to infinity.
|
|
559
|
+
*
|
|
560
|
+
* - If practical, give the viewport a fixed size or a maximum size.
|
|
561
|
+
* - If you add the viewport to a flexbox layout, make sure that it cannot exceed the available space. Instead, the viewport should fill the remaining space,
|
|
562
|
+
* vertically and horizontally. Be aware that, by default, a flex item does not shrink below its minimum content size. To change this, set the viewport's
|
|
563
|
+
* `flex-basis` to `0` (instead of `auto`), or use the CSS shorthand property `flex: 1 1 0`. The `flex-basis` defines the default size of a flex item before
|
|
564
|
+
* the remaining extra space is distributed. If the viewport does not appear after setting this property, check its parent elements' content sizes.
|
|
565
|
+
* As an alternative to setting `flex: 1 1 0`, change the setting to `flex: auto` and hide the overflow in the parent element, as follows: `overflow: hidden`.
|
|
566
|
+
* Another approach would be to set the minimum height of all parents to `0`, as follows: `min-height: 0`.
|
|
567
|
+
*
|
|
568
|
+
* For the complete documentation on the flex layout and its features, refer to https://developer.mozilla.org/en-US/docs/Web/CSS/flex.
|
|
569
|
+
*
|
|
570
|
+
*
|
|
571
|
+
* ## Layouting the viewport content
|
|
572
|
+
*
|
|
573
|
+
* `NgContent` is added to a CSS grid container with, by default, a single column, filling remaining space vertically and horizontally.
|
|
574
|
+
*
|
|
575
|
+
* You can override the following CSS variables to control the grid:
|
|
576
|
+
*
|
|
577
|
+
* - sci-viewport-content-grid-template-columns: Defines the columns and their track sizes (by default, single column with track size auto)
|
|
578
|
+
* - sci-viewport-content-grid-template-rows: Defines the rows and their track sizes (by default, single row with track size auto)
|
|
579
|
+
* - sci-viewport-content-grid-auto-columns: Defines the track size of not explicitly declared columns.
|
|
580
|
+
* - sci-viewport-content-grid-auto-rows: Defines the track size of not explicitly declared rows.
|
|
581
|
+
* - sci-viewport-content-grid-gap: Sets the gaps (gutters) between rows and columns.
|
|
582
|
+
*
|
|
583
|
+
* Example of how to control the CSS grid:
|
|
584
|
+
*
|
|
585
|
+
* ```css
|
|
586
|
+
* sci-viewport {
|
|
587
|
+
* --sci-viewport-content-grid-auto-rows: min-content;
|
|
588
|
+
* --sci-viewport-content-grid-gap: .5em; // specifies the row and column gap
|
|
589
|
+
* }
|
|
590
|
+
* ```
|
|
591
|
+
*
|
|
592
|
+
* ## Styling of scrollbars
|
|
593
|
+
*
|
|
594
|
+
* You can override the following CSS variables to control the appearance of the scrollbar:
|
|
595
|
+
*
|
|
596
|
+
* - sci-viewport-scrollbar-color: Sets the color of the scrollbar (by default, uses `rgb(78, 78, 78)`).
|
|
597
|
+
*
|
|
598
|
+
* ```css
|
|
599
|
+
* sci-viewport {
|
|
600
|
+
* --sci-viewport-scrollbar-color: blue;
|
|
601
|
+
* }
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
class SciViewportComponent {
|
|
605
|
+
constructor(host, nativeScrollbarTrackSizeProvider) {
|
|
606
|
+
this.host = host;
|
|
607
|
+
this.nativeScrollbarTrackSizeProvider = nativeScrollbarTrackSizeProvider;
|
|
608
|
+
this._scrollbarStyle = 'on-top';
|
|
609
|
+
this.tabindex = -1; // make the viewport programmatically focusable but do not include it in the tab order
|
|
610
|
+
/**
|
|
611
|
+
* Emits upon a scroll event.
|
|
612
|
+
*
|
|
613
|
+
* You can add [sciDimension] directive to the viewport or viewport client to be notified about layout changes.
|
|
614
|
+
*/
|
|
615
|
+
this.scroll = new EventEmitter(); // eslint-disable-line @angular-eslint/no-output-native
|
|
616
|
+
}
|
|
617
|
+
/** @internal */
|
|
618
|
+
set setViewport(viewport) {
|
|
619
|
+
this._viewport = coerceElement(viewport);
|
|
620
|
+
}
|
|
621
|
+
/** @internal */
|
|
622
|
+
set setViewportClient(viewportClient) {
|
|
623
|
+
this._viewportClient = coerceElement(viewportClient);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Controls whether to use native scrollbars or, which is by default, emulated scrollbars that sit on top of the viewport client.
|
|
627
|
+
* In the latter, the viewport client remains natively scrollable.
|
|
628
|
+
*/
|
|
629
|
+
set scrollbarStyle(scrollbarStyle) {
|
|
630
|
+
this._scrollbarStyle = scrollbarStyle || 'on-top';
|
|
631
|
+
}
|
|
632
|
+
get scrollbarStyle() {
|
|
633
|
+
return this._scrollbarStyle;
|
|
634
|
+
}
|
|
635
|
+
focus() {
|
|
636
|
+
this._viewport && this._viewport.focus();
|
|
637
|
+
}
|
|
638
|
+
onScroll(event) {
|
|
639
|
+
this.scroll.emit(event);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Returns the number of pixels that the viewport client is scrolled vertically.
|
|
643
|
+
*
|
|
644
|
+
* @see Element.scrollTop
|
|
645
|
+
*/
|
|
646
|
+
get scrollTop() {
|
|
647
|
+
return this._viewport.scrollTop;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Sets the number of pixels that the viewport client is scrolled vertically.
|
|
651
|
+
*
|
|
652
|
+
* @see Element.scrollTop
|
|
653
|
+
*/
|
|
654
|
+
set scrollTop(scrollTop) {
|
|
655
|
+
this._viewport.scrollTop = scrollTop;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Returns the number of pixels that the viewport client is scrolled horizontally.
|
|
659
|
+
*
|
|
660
|
+
* @see Element.scrollLeft
|
|
661
|
+
*/
|
|
662
|
+
get scrollLeft() {
|
|
663
|
+
return this._viewport.scrollLeft;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Sets the number of pixels that the viewport client is scrolled horizontally.
|
|
667
|
+
*
|
|
668
|
+
* @see Element.scrollLeft
|
|
669
|
+
*/
|
|
670
|
+
set scrollLeft(scrollLeft) {
|
|
671
|
+
this._viewport.scrollLeft = scrollLeft;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Returns the height of the viewport client.
|
|
675
|
+
*
|
|
676
|
+
* @see Element.scrollHeight
|
|
677
|
+
*/
|
|
678
|
+
get scrollHeight() {
|
|
679
|
+
return this._viewport.scrollHeight;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Returns the width of the viewport client.
|
|
683
|
+
*
|
|
684
|
+
* @see Element.scrollWidth
|
|
685
|
+
*/
|
|
686
|
+
get scrollWidth() {
|
|
687
|
+
return this._viewport.scrollWidth;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Returns the viewport {HTMLElement}.
|
|
691
|
+
*/
|
|
692
|
+
get viewportElement() {
|
|
693
|
+
return this._viewport;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Returns the viewport client {HTMLElement}.
|
|
697
|
+
*/
|
|
698
|
+
get viewportClientElement() {
|
|
699
|
+
return this._viewportClient;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Checks if the specified element is scrolled into the viewport.
|
|
703
|
+
*
|
|
704
|
+
* @param element - the element to be checked
|
|
705
|
+
* @param fit - control if the element must fully or partially fit into the viewport
|
|
706
|
+
*/
|
|
707
|
+
isElementInView(element, fit) {
|
|
708
|
+
const elLeft = this.computeOffset(element, 'left');
|
|
709
|
+
const elRight = elLeft + element.offsetWidth;
|
|
710
|
+
const elTop = this.computeOffset(element, 'top');
|
|
711
|
+
const elBottom = elTop + element.offsetHeight;
|
|
712
|
+
const vpLeft = this._viewport.scrollLeft;
|
|
713
|
+
const vpRight = vpLeft + this._viewport.clientWidth;
|
|
714
|
+
const vpTop = this._viewport.scrollTop;
|
|
715
|
+
const vpBottom = vpTop + this._viewport.clientHeight;
|
|
716
|
+
switch (fit) {
|
|
717
|
+
case 'full':
|
|
718
|
+
return (elLeft >= vpLeft && elRight <= vpRight) && (elTop >= vpTop && elBottom <= vpBottom);
|
|
719
|
+
case 'partial':
|
|
720
|
+
return (elRight >= vpLeft && elLeft <= vpRight) && (elBottom >= vpTop && elTop <= vpBottom);
|
|
721
|
+
default:
|
|
722
|
+
throw Error('Unsupported fit strategy');
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Scrolls the specified element into the viewport.
|
|
727
|
+
*
|
|
728
|
+
* @param element - the element to scroll into the viewport
|
|
729
|
+
* @param offset - the gap between the element and the viewport
|
|
730
|
+
*/
|
|
731
|
+
scrollIntoView(element, offset = 50) {
|
|
732
|
+
this._viewport.scrollTop = this.computeOffset(element, 'top') - offset;
|
|
733
|
+
this._viewport.scrollLeft = this.computeOffset(element, 'left') - offset;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Computes the distance of the element to the viewport's left or top border.
|
|
737
|
+
*/
|
|
738
|
+
computeOffset(element, border) {
|
|
739
|
+
if (!isChildOf(element, this._viewport)) {
|
|
740
|
+
throw Error('element not a child of the viewport');
|
|
741
|
+
}
|
|
742
|
+
let offset = 0;
|
|
743
|
+
let el = element;
|
|
744
|
+
do {
|
|
745
|
+
offset += (border === 'left' ? el.offsetLeft : el.offsetTop);
|
|
746
|
+
el = el.offsetParent;
|
|
747
|
+
} while (el !== null && el !== this._viewport);
|
|
748
|
+
return offset;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
SciViewportComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportComponent, deps: [{ token: i0.ElementRef }, { token: SciNativeScrollbarTrackSizeProvider }], target: i0.ɵɵFactoryTarget.Component });
|
|
752
|
+
SciViewportComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.3", type: SciViewportComponent, selector: "sci-viewport", inputs: { scrollbarStyle: "scrollbarStyle" }, outputs: { scroll: "scroll" }, host: { listeners: { "focus": "focus()" }, properties: { "attr.tabindex": "this.tabindex" } }, viewQueries: [{ propertyName: "setViewport", first: true, predicate: ["viewport"], descendants: true, static: true }, { propertyName: "setViewportClient", first: true, predicate: ["viewport_client"], descendants: true, static: true }], ngImport: i0, template: "<!-- viewport and viewport client -->\n<div #viewport\n class=\"viewport\"\n tabindex=\"-1\"\n sciScrollable [sciScrollableDisplayNativeScrollbar]=\"scrollbarStyle === 'native'\"\n cdkScrollable\n (scroll)=\"onScroll($event)\">\n <div #viewport_client class=\"viewport-client\">\n <ng-content></ng-content>\n </div>\n</div>\n\n<!-- render emulated scrollbars which sit on-top -->\n<ng-container *ngIf=\"scrollbarStyle === 'on-top' && (nativeScrollbarTrackSizeProvider.trackSize$ | async) !== null\">\n <sci-scrollbar [direction]=\"'vscroll'\" [viewport]=\"viewport\"></sci-scrollbar>\n <sci-scrollbar [direction]=\"'hscroll'\" [viewport]=\"viewport\"></sci-scrollbar>\n</ng-container>\n", styles: [":host{--sci-viewport-content-grid-template-columns: auto;--sci-viewport-content-grid-template-rows: unset;--sci-viewport-content-grid-auto-columns: unset;--sci-viewport-content-grid-auto-rows: auto;--sci-viewport-content-grid-gap: 0 0;--sci-viewport-scrollbar-color: rgb(78, 78, 78);display:grid;grid-template-columns:100%;grid-template-rows:100%;position:relative;overflow:hidden;outline:none}:host:not(:hover):not(:active) sci-scrollbar:not(.scrolling){opacity:0}:host>div.viewport{display:grid;position:relative;outline:none;-webkit-overflow-scrolling:touch}:host>div.viewport>div.viewport-client{display:grid;grid-template-columns:var(--sci-viewport-content-grid-template-columns);grid-template-rows:var(--sci-viewport-content-grid-template-rows);grid-auto-rows:var(--sci-viewport-content-grid-auto-rows);grid-auto-columns:var(--sci-viewport-content-grid-auto-columns);grid-gap:var(--sci-viewport-content-grid-gap);gap:var(--sci-viewport-content-grid-gap)}:host>sci-scrollbar{--sci-scrollbar-color: var(--sci-viewport-scrollbar-color);position:absolute;transition-duration:1s;transition-property:opacity;transition-timing-function:ease-out}:host>sci-scrollbar.vertical{top:0;right:0;bottom:0;left:unset;width:12px}:host>sci-scrollbar.horizontal{top:unset;right:0;bottom:0;left:0;height:12px}\n"], components: [{ type: SciScrollbarComponent, selector: "sci-scrollbar", inputs: ["direction", "viewport"] }], directives: [{ type: SciScrollableDirective, selector: "[sciScrollable]", inputs: ["sciScrollableDisplayNativeScrollbar"] }, { type: i4.CdkScrollable, selector: "[cdk-scrollable], [cdkScrollable]" }, { type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i5.AsyncPipe } });
|
|
753
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportComponent, decorators: [{
|
|
754
|
+
type: Component,
|
|
755
|
+
args: [{ selector: 'sci-viewport', template: "<!-- viewport and viewport client -->\n<div #viewport\n class=\"viewport\"\n tabindex=\"-1\"\n sciScrollable [sciScrollableDisplayNativeScrollbar]=\"scrollbarStyle === 'native'\"\n cdkScrollable\n (scroll)=\"onScroll($event)\">\n <div #viewport_client class=\"viewport-client\">\n <ng-content></ng-content>\n </div>\n</div>\n\n<!-- render emulated scrollbars which sit on-top -->\n<ng-container *ngIf=\"scrollbarStyle === 'on-top' && (nativeScrollbarTrackSizeProvider.trackSize$ | async) !== null\">\n <sci-scrollbar [direction]=\"'vscroll'\" [viewport]=\"viewport\"></sci-scrollbar>\n <sci-scrollbar [direction]=\"'hscroll'\" [viewport]=\"viewport\"></sci-scrollbar>\n</ng-container>\n", styles: [":host{--sci-viewport-content-grid-template-columns: auto;--sci-viewport-content-grid-template-rows: unset;--sci-viewport-content-grid-auto-columns: unset;--sci-viewport-content-grid-auto-rows: auto;--sci-viewport-content-grid-gap: 0 0;--sci-viewport-scrollbar-color: rgb(78, 78, 78);display:grid;grid-template-columns:100%;grid-template-rows:100%;position:relative;overflow:hidden;outline:none}:host:not(:hover):not(:active) sci-scrollbar:not(.scrolling){opacity:0}:host>div.viewport{display:grid;position:relative;outline:none;-webkit-overflow-scrolling:touch}:host>div.viewport>div.viewport-client{display:grid;grid-template-columns:var(--sci-viewport-content-grid-template-columns);grid-template-rows:var(--sci-viewport-content-grid-template-rows);grid-auto-rows:var(--sci-viewport-content-grid-auto-rows);grid-auto-columns:var(--sci-viewport-content-grid-auto-columns);grid-gap:var(--sci-viewport-content-grid-gap);gap:var(--sci-viewport-content-grid-gap)}:host>sci-scrollbar{--sci-scrollbar-color: var(--sci-viewport-scrollbar-color);position:absolute;transition-duration:1s;transition-property:opacity;transition-timing-function:ease-out}:host>sci-scrollbar.vertical{top:0;right:0;bottom:0;left:unset;width:12px}:host>sci-scrollbar.horizontal{top:unset;right:0;bottom:0;left:0;height:12px}\n"] }]
|
|
756
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: SciNativeScrollbarTrackSizeProvider }]; }, propDecorators: { tabindex: [{
|
|
757
|
+
type: HostBinding,
|
|
758
|
+
args: ['attr.tabindex']
|
|
759
|
+
}], setViewport: [{
|
|
760
|
+
type: ViewChild,
|
|
761
|
+
args: ['viewport', { static: true }]
|
|
762
|
+
}], setViewportClient: [{
|
|
763
|
+
type: ViewChild,
|
|
764
|
+
args: ['viewport_client', { static: true }]
|
|
765
|
+
}], scrollbarStyle: [{
|
|
766
|
+
type: Input
|
|
767
|
+
}], scroll: [{
|
|
768
|
+
type: Output
|
|
769
|
+
}], focus: [{
|
|
770
|
+
type: HostListener,
|
|
771
|
+
args: ['focus']
|
|
772
|
+
}] } });
|
|
773
|
+
/**
|
|
774
|
+
* Returns 'true' if the given element is a child element of the parent element.
|
|
775
|
+
*/
|
|
776
|
+
function isChildOf(element, parent) {
|
|
777
|
+
while (element.parentElement !== null) {
|
|
778
|
+
element = element.parentElement;
|
|
779
|
+
if (element === parent) {
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/*
|
|
787
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
788
|
+
*
|
|
789
|
+
* This program and the accompanying materials are made
|
|
790
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
791
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
792
|
+
*
|
|
793
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
794
|
+
*/
|
|
795
|
+
/**
|
|
796
|
+
* Provides a viewport component with scrollbars that sit on top of the viewport client.
|
|
797
|
+
*/
|
|
798
|
+
class SciViewportModule {
|
|
799
|
+
}
|
|
800
|
+
SciViewportModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
801
|
+
SciViewportModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportModule, declarations: [SciViewportComponent,
|
|
802
|
+
SciScrollbarComponent,
|
|
803
|
+
SciScrollableDirective], imports: [CommonModule,
|
|
804
|
+
ScrollingModule], exports: [SciViewportComponent,
|
|
805
|
+
SciScrollbarComponent,
|
|
806
|
+
SciScrollableDirective] });
|
|
807
|
+
SciViewportModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportModule, imports: [[
|
|
808
|
+
CommonModule,
|
|
809
|
+
ScrollingModule,
|
|
810
|
+
]] });
|
|
811
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: SciViewportModule, decorators: [{
|
|
812
|
+
type: NgModule,
|
|
813
|
+
args: [{
|
|
814
|
+
imports: [
|
|
815
|
+
CommonModule,
|
|
816
|
+
ScrollingModule,
|
|
817
|
+
],
|
|
818
|
+
declarations: [
|
|
819
|
+
SciViewportComponent,
|
|
820
|
+
SciScrollbarComponent,
|
|
821
|
+
SciScrollableDirective,
|
|
822
|
+
],
|
|
823
|
+
exports: [
|
|
824
|
+
SciViewportComponent,
|
|
825
|
+
SciScrollbarComponent,
|
|
826
|
+
SciScrollableDirective,
|
|
827
|
+
],
|
|
828
|
+
}]
|
|
829
|
+
}] });
|
|
830
|
+
|
|
831
|
+
/*
|
|
832
|
+
* Copyright (c) 2018-2019 Swiss Federal Railways
|
|
833
|
+
*
|
|
834
|
+
* This program and the accompanying materials are made
|
|
835
|
+
* available under the terms of the Eclipse Public License 2.0
|
|
836
|
+
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
837
|
+
*
|
|
838
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
839
|
+
*/
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Generated bundle index. Do not edit.
|
|
843
|
+
*/
|
|
844
|
+
|
|
845
|
+
export { SciNativeScrollbarTrackSizeProvider, SciScrollableDirective, SciScrollbarComponent, SciViewportComponent, SciViewportModule };
|
|
846
|
+
//# sourceMappingURL=scion-components-viewport.mjs.map
|