@skyux/core 8.6.0 → 9.0.0-alpha.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/{esm2020 → esm2022}/lib/modules/adapter-service/adapter.module.mjs +5 -5
- package/esm2022/lib/modules/adapter-service/adapter.service.mjs +225 -0
- package/esm2022/lib/modules/affix/affix.directive.mjs +116 -0
- package/{esm2020 → esm2022}/lib/modules/affix/affix.module.mjs +5 -5
- package/esm2022/lib/modules/affix/affix.service.mjs +25 -0
- package/esm2022/lib/modules/affix/affixer.mjs +398 -0
- package/esm2022/lib/modules/default-input-provider/default-input-provider.mjs +26 -0
- package/esm2022/lib/modules/dock/dock-dom-adapter.service.mjs +81 -0
- package/esm2022/lib/modules/dock/dock-item.mjs +31 -0
- package/esm2022/lib/modules/dock/dock.component.mjs +108 -0
- package/{esm2020 → esm2022}/lib/modules/dock/dock.module.mjs +5 -5
- package/esm2022/lib/modules/dock/dock.service.mjs +96 -0
- package/{esm2020 → esm2022}/lib/modules/dynamic-component/dynamic-component.module.mjs +5 -5
- package/esm2022/lib/modules/dynamic-component/dynamic-component.service.mjs +106 -0
- package/{esm2020 → esm2022}/lib/modules/format/app-format.mjs +4 -4
- package/esm2022/lib/modules/id/id.directive.mjs +31 -0
- package/{esm2020 → esm2022}/lib/modules/id/id.module.mjs +5 -5
- package/{esm2020 → esm2022}/lib/modules/id/id.service.mjs +4 -4
- package/esm2022/lib/modules/layout-host/layout-host.service.mjs +22 -0
- package/esm2022/lib/modules/live-announcer/live-announcer.service.mjs +79 -0
- package/{esm2020 → esm2022}/lib/modules/log/log.module.mjs +5 -5
- package/esm2022/lib/modules/log/log.service.mjs +148 -0
- package/{esm2020 → esm2022}/lib/modules/media-query/media-query.module.mjs +5 -5
- package/esm2022/lib/modules/media-query/media-query.service.mjs +123 -0
- package/{esm2020 → esm2022}/lib/modules/mutation/mutation-observer-service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/modules/numeric/numeric.module.mjs +5 -5
- package/esm2022/lib/modules/numeric/numeric.pipe.mjs +81 -0
- package/esm2022/lib/modules/numeric/numeric.service.mjs +205 -0
- package/esm2022/lib/modules/overlay/overlay-adapter.service.mjs +44 -0
- package/esm2022/lib/modules/overlay/overlay-instance.mjs +62 -0
- package/esm2022/lib/modules/overlay/overlay.component.mjs +193 -0
- package/{esm2020 → esm2022}/lib/modules/overlay/overlay.module.mjs +5 -5
- package/esm2022/lib/modules/overlay/overlay.service.mjs +124 -0
- package/{esm2020 → esm2022}/lib/modules/percent-pipe/percent-pipe.module.mjs +5 -5
- package/esm2022/lib/modules/percent-pipe/percent.pipe.mjs +56 -0
- package/esm2022/lib/modules/resize-observer/resize-observer-media-query.service.mjs +120 -0
- package/esm2022/lib/modules/resize-observer/resize-observer.service.mjs +77 -0
- package/esm2022/lib/modules/scrollable-host/scrollable-host.service.mjs +223 -0
- package/esm2022/lib/modules/shared/number-format/number-format-utility.mjs +72 -0
- package/esm2022/lib/modules/shared/sky-core-resources.module.mjs +50 -0
- package/esm2022/lib/modules/title/title.service.mjs +31 -0
- package/esm2022/lib/modules/trim/trim.directive.mjs +64 -0
- package/{esm2020 → esm2022}/lib/modules/trim/trim.module.mjs +5 -5
- package/{esm2020 → esm2022}/lib/modules/ui-config/ui-config.service.mjs +4 -4
- package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper-host-options.mjs +4 -4
- package/esm2022/lib/modules/viewkeeper/viewkeeper.directive.mjs +131 -0
- package/esm2022/lib/modules/viewkeeper/viewkeeper.mjs +283 -0
- package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper.module.mjs +5 -5
- package/esm2022/lib/modules/viewkeeper/viewkeeper.service.mjs +39 -0
- package/{esm2020 → esm2022}/lib/modules/window/window-ref.mjs +4 -4
- package/esm2022/testing/core-testing.module.mjs +32 -0
- package/esm2022/testing/mock-media-query.service.mjs +46 -0
- package/{esm2020 → esm2022}/testing/mock-ui-config.service.mjs +4 -4
- package/esm2022/testing/overlay/overlay-harness.mjs +43 -0
- package/esm2022/testing/shared/component-harness.mjs +13 -0
- package/{fesm2020 → fesm2022}/skyux-core-testing.mjs +28 -34
- package/{fesm2020 → fesm2022}/skyux-core-testing.mjs.map +1 -1
- package/fesm2022/skyux-core.mjs +3858 -0
- package/fesm2022/skyux-core.mjs.map +1 -0
- package/lib/modules/affix/affix.directive.d.ts +1 -1
- package/lib/modules/viewkeeper/viewkeeper.directive.d.ts +1 -1
- package/package.json +14 -22
- package/esm2020/lib/modules/adapter-service/adapter.service.mjs +0 -227
- package/esm2020/lib/modules/affix/affix.directive.mjs +0 -118
- package/esm2020/lib/modules/affix/affix.service.mjs +0 -28
- package/esm2020/lib/modules/affix/affixer.mjs +0 -377
- package/esm2020/lib/modules/default-input-provider/default-input-provider.mjs +0 -31
- package/esm2020/lib/modules/dock/dock-dom-adapter.service.mjs +0 -83
- package/esm2020/lib/modules/dock/dock-item.mjs +0 -34
- package/esm2020/lib/modules/dock/dock.component.mjs +0 -110
- package/esm2020/lib/modules/dock/dock.service.mjs +0 -98
- package/esm2020/lib/modules/dynamic-component/dynamic-component.service.mjs +0 -109
- package/esm2020/lib/modules/id/id.directive.mjs +0 -34
- package/esm2020/lib/modules/layout-host/layout-host.service.mjs +0 -27
- package/esm2020/lib/modules/live-announcer/live-announcer.service.mjs +0 -80
- package/esm2020/lib/modules/log/log.service.mjs +0 -147
- package/esm2020/lib/modules/media-query/media-query.service.mjs +0 -124
- package/esm2020/lib/modules/numeric/numeric.pipe.mjs +0 -84
- package/esm2020/lib/modules/numeric/numeric.service.mjs +0 -179
- package/esm2020/lib/modules/overlay/overlay-adapter.service.mjs +0 -47
- package/esm2020/lib/modules/overlay/overlay-instance.mjs +0 -65
- package/esm2020/lib/modules/overlay/overlay.component.mjs +0 -192
- package/esm2020/lib/modules/overlay/overlay.service.mjs +0 -125
- package/esm2020/lib/modules/percent-pipe/percent.pipe.mjs +0 -59
- package/esm2020/lib/modules/resize-observer/resize-observer-media-query.service.mjs +0 -121
- package/esm2020/lib/modules/resize-observer/resize-observer.service.mjs +0 -79
- package/esm2020/lib/modules/scrollable-host/scrollable-host.service.mjs +0 -218
- package/esm2020/lib/modules/shared/number-format/number-format-utility.mjs +0 -72
- package/esm2020/lib/modules/shared/sky-core-resources.module.mjs +0 -50
- package/esm2020/lib/modules/title/title.service.mjs +0 -34
- package/esm2020/lib/modules/trim/trim.directive.mjs +0 -65
- package/esm2020/lib/modules/viewkeeper/viewkeeper.directive.mjs +0 -131
- package/esm2020/lib/modules/viewkeeper/viewkeeper.mjs +0 -276
- package/esm2020/lib/modules/viewkeeper/viewkeeper.service.mjs +0 -42
- package/esm2020/testing/core-testing.module.mjs +0 -32
- package/esm2020/testing/mock-media-query.service.mjs +0 -46
- package/esm2020/testing/overlay/overlay-harness.mjs +0 -43
- package/esm2020/testing/shared/component-harness.mjs +0 -19
- package/fesm2015/skyux-core-testing.mjs +0 -209
- package/fesm2015/skyux-core-testing.mjs.map +0 -1
- package/fesm2015/skyux-core.mjs +0 -3835
- package/fesm2015/skyux-core.mjs.map +0 -1
- package/fesm2020/skyux-core.mjs +0 -3825
- package/fesm2020/skyux-core.mjs.map +0 -1
- /package/{esm2020 → esm2022}/index.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/adapter-service/focusable-children-options.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-auto-fit-context.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-horizontal-alignment.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-offset-change.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-offset.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-placement-change.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-placement.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-position.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-rect.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/affix-vertical-alignment.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/affix/dom-utils.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/dock-insert-component-config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/dock-item-config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/dock-item-reference.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/dock-location.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/dock-options.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dock/sort-by-stack-order.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dynamic-component/dynamic-component-location.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/dynamic-component/dynamic-component-options.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/layout-host/layout-host-for-child-args.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/live-announcer/types/live-announcer-args.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/live-announcer/types/live-announcer-politeness.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/log/types/log-deprecation-args.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/log/types/log-level-token.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/log/types/log-level.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/media-query/media-breakpoints.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/media-query/media-query-listener.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/numeric/numeric-symbol.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/numeric/numeric.options.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/overlay/overlay-config.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/overlay/overlay-context.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/overlay/overlay-position.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/stacking-context/stacking-context-token.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/stacking-context/stacking-context.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/title/set-title-args.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper-boundary-info.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper-fixed-styles.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper-offset.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/modules/viewkeeper/viewkeeper-options.mjs +0 -0
- /package/{esm2020 → esm2022}/skyux-core.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/overlay/overlay-harness-filters.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/public-api.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/shared/harness-filters.mjs +0 -0
- /package/{esm2020 → esm2022}/testing/skyux-core-testing.mjs +0 -0
@@ -0,0 +1,3858 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { NgModule, Injectable, EventEmitter, Directive, Input, Output, Injector, ViewContainerRef, Component, ChangeDetectionStrategy, ViewChild, createComponent, inject, InjectionToken, Optional, Inject, Pipe, ElementRef, HostBinding } from '@angular/core';
|
3
|
+
import * as i5 from '@angular/common';
|
4
|
+
import { CommonModule, DOCUMENT } from '@angular/common';
|
5
|
+
import { Subject, fromEvent, ReplaySubject, BehaviorSubject, Observable, of, concat, animationFrameScheduler } from 'rxjs';
|
6
|
+
import { takeUntil, debounceTime, finalize, switchMap, map } from 'rxjs/operators';
|
7
|
+
import * as i1 from '@skyux/i18n';
|
8
|
+
import { getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS, SkyIntlNumberFormatStyle, SkyIntlNumberFormatter } from '@skyux/i18n';
|
9
|
+
import * as i4 from '@angular/router';
|
10
|
+
import { NavigationStart } from '@angular/router';
|
11
|
+
import * as i1$1 from '@angular/platform-browser';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @deprecated The `SkyCoreAdapterService` no longer needs the `SkyCoreAdapterModule`.
|
15
|
+
* The `SkyCoreAdapterModule` can be removed from your project.
|
16
|
+
*/
|
17
|
+
class SkyCoreAdapterModule {
|
18
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
19
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterModule }); }
|
20
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterModule }); }
|
21
|
+
}
|
22
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterModule, decorators: [{
|
23
|
+
type: NgModule,
|
24
|
+
args: [{}]
|
25
|
+
}] });
|
26
|
+
|
27
|
+
var SkyMediaBreakpoints;
|
28
|
+
(function (SkyMediaBreakpoints) {
|
29
|
+
/**
|
30
|
+
* Screen widths of 767px or less.
|
31
|
+
*/
|
32
|
+
SkyMediaBreakpoints[SkyMediaBreakpoints["xs"] = 1] = "xs";
|
33
|
+
/**
|
34
|
+
* Screen widths of 768px to 991px.
|
35
|
+
*/
|
36
|
+
SkyMediaBreakpoints[SkyMediaBreakpoints["sm"] = 2] = "sm";
|
37
|
+
/**
|
38
|
+
* Screen widths of 992px to 1199px.
|
39
|
+
*/
|
40
|
+
SkyMediaBreakpoints[SkyMediaBreakpoints["md"] = 3] = "md";
|
41
|
+
/**
|
42
|
+
* Screen widths of 1200px or greater.
|
43
|
+
*/
|
44
|
+
SkyMediaBreakpoints[SkyMediaBreakpoints["lg"] = 4] = "lg";
|
45
|
+
})(SkyMediaBreakpoints || (SkyMediaBreakpoints = {}));
|
46
|
+
|
47
|
+
const SKY_TABBABLE_SELECTOR = [
|
48
|
+
'a[href]',
|
49
|
+
'area[href]',
|
50
|
+
'input:not([disabled])',
|
51
|
+
'button:not([disabled])',
|
52
|
+
'select:not([disabled])',
|
53
|
+
'textarea:not([disabled])',
|
54
|
+
'iframe',
|
55
|
+
'object',
|
56
|
+
'embed',
|
57
|
+
'*[contenteditable=true]:not([disabled])',
|
58
|
+
'*[tabindex]:not([disabled])',
|
59
|
+
].join(', ');
|
60
|
+
class SkyCoreAdapterService {
|
61
|
+
#renderer;
|
62
|
+
constructor(rendererFactory) {
|
63
|
+
this.#renderer = rendererFactory.createRenderer(undefined, null);
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* Set the responsive container CSS class for a given element.
|
67
|
+
*
|
68
|
+
* @param elementRef - The element that will receive the new CSS class.
|
69
|
+
* @param breakpoint - The SkyMediaBreakpoint will determine which class
|
70
|
+
* gets set. For example a SkyMediaBreakpoint of `xs` will set a CSS class of `sky-responsive-container-xs`.
|
71
|
+
*/
|
72
|
+
setResponsiveContainerClass(elementRef, breakpoint) {
|
73
|
+
const nativeEl = elementRef.nativeElement;
|
74
|
+
this.#renderer.removeClass(nativeEl, 'sky-responsive-container-xs');
|
75
|
+
this.#renderer.removeClass(nativeEl, 'sky-responsive-container-sm');
|
76
|
+
this.#renderer.removeClass(nativeEl, 'sky-responsive-container-md');
|
77
|
+
this.#renderer.removeClass(nativeEl, 'sky-responsive-container-lg');
|
78
|
+
let newClass;
|
79
|
+
switch (breakpoint) {
|
80
|
+
case SkyMediaBreakpoints.xs: {
|
81
|
+
newClass = 'sky-responsive-container-xs';
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
case SkyMediaBreakpoints.sm: {
|
85
|
+
newClass = 'sky-responsive-container-sm';
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
case SkyMediaBreakpoints.md: {
|
89
|
+
newClass = 'sky-responsive-container-md';
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
default: {
|
93
|
+
newClass = 'sky-responsive-container-lg';
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
this.#renderer.addClass(nativeEl, newClass);
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* This method temporarily enables/disables pointer events.
|
101
|
+
* This is helpful to prevent iFrames from interfering with drag events.
|
102
|
+
*
|
103
|
+
* @param enable - Set to `true` to enable pointer events. Set to `false` to disable.
|
104
|
+
*/
|
105
|
+
toggleIframePointerEvents(enable) {
|
106
|
+
const iframes = document.querySelectorAll('iframe');
|
107
|
+
for (let i = 0; i < iframes.length; i++) {
|
108
|
+
// Setting to empty string will allow iframe to fall back to its prior CSS assignment.
|
109
|
+
iframes[i].style.pointerEvents = enable ? '' : 'none';
|
110
|
+
}
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* Focuses on the first element found with an `autofocus` attribute inside the supplied `elementRef`.
|
114
|
+
*
|
115
|
+
* @param elementRef - The element to search within.
|
116
|
+
* @return Returns `true` if a child element with autofocus is found.
|
117
|
+
*/
|
118
|
+
applyAutoFocus(elementRef) {
|
119
|
+
if (!elementRef) {
|
120
|
+
return false;
|
121
|
+
}
|
122
|
+
const elementWithAutoFocus = elementRef.nativeElement.querySelector('[autofocus]');
|
123
|
+
// Child was found with the autofocus property. Set focus and return true.
|
124
|
+
if (elementWithAutoFocus) {
|
125
|
+
elementWithAutoFocus.focus();
|
126
|
+
return true;
|
127
|
+
}
|
128
|
+
// No children were found with autofocus property. Return false.
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Sets focus on the first focusable child of the `elementRef` parameter.
|
133
|
+
* If no focusable children are found, and `focusOnContainerIfNoChildrenFound` is `true`,
|
134
|
+
* focus will be set on the container element.
|
135
|
+
*
|
136
|
+
* @param elementRef - The element to search within.
|
137
|
+
* @param containerSelector - A CSS selector indicating the container that should
|
138
|
+
* receive focus if no focusable children are found.
|
139
|
+
* @param focusOnContainerIfNoChildrenFound - It set to `true`, the container will
|
140
|
+
* receive focus if no focusable children are found.
|
141
|
+
*/
|
142
|
+
getFocusableChildrenAndApplyFocus(elementRef, containerSelector, focusOnContainerIfNoChildrenFound = false) {
|
143
|
+
const containerElement = elementRef.nativeElement.querySelector(containerSelector);
|
144
|
+
if (containerElement) {
|
145
|
+
const focusableChildren = this.getFocusableChildren(containerElement);
|
146
|
+
// Focus first focusable child if available. Otherwise, set focus on container.
|
147
|
+
if (!this.#focusFirstElement(focusableChildren) &&
|
148
|
+
focusOnContainerIfNoChildrenFound) {
|
149
|
+
containerElement.focus();
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
/**
|
154
|
+
* Returns an array of all focusable children of provided `element`.
|
155
|
+
*
|
156
|
+
* @param element - The HTMLElement to search within.
|
157
|
+
* @param options - Options for getting focusable children.
|
158
|
+
*/
|
159
|
+
getFocusableChildren(element, options) {
|
160
|
+
if (!element) {
|
161
|
+
return [];
|
162
|
+
}
|
163
|
+
let elements = Array.prototype.slice.call(element.querySelectorAll(SKY_TABBABLE_SELECTOR));
|
164
|
+
// Unless ignoreTabIndex = true, filter out elements with tabindex = -1.
|
165
|
+
if (!options || !options.ignoreTabIndex) {
|
166
|
+
elements = elements.filter((el) => {
|
167
|
+
return el.tabIndex !== -1;
|
168
|
+
});
|
169
|
+
}
|
170
|
+
// Unless ignoreVisibility = true, filter out elements that are not visible.
|
171
|
+
if (!options || !options.ignoreVisibility) {
|
172
|
+
elements = elements.filter((el) => {
|
173
|
+
return this.#isVisible(el);
|
174
|
+
});
|
175
|
+
}
|
176
|
+
return elements;
|
177
|
+
}
|
178
|
+
/**
|
179
|
+
* Returns the clientWidth of the provided elementRef.
|
180
|
+
* @param elementRef - The element to calculate width from.
|
181
|
+
*/
|
182
|
+
getWidth(elementRef) {
|
183
|
+
return elementRef.nativeElement.clientWidth;
|
184
|
+
}
|
185
|
+
/**
|
186
|
+
* Checks if an event target has a higher z-index than a given element.
|
187
|
+
* @param target The event target element.
|
188
|
+
* @param element The element to test against. A z-index must be explicitly set for this element.
|
189
|
+
*/
|
190
|
+
isTargetAboveElement(target, element) {
|
191
|
+
const zIndex = getComputedStyle(element).zIndex;
|
192
|
+
let el = target;
|
193
|
+
while (el) {
|
194
|
+
// Getting the computed style only works for elements that exist in the DOM.
|
195
|
+
// In certain scenarios, an element is removed after a click event; by the time the event
|
196
|
+
// bubbles up to other elements, however, the element has been removed and the computed style returns empty.
|
197
|
+
// In this case, we'll need to check the z-index directly, via the style property.
|
198
|
+
const targetZIndex = getComputedStyle(el).zIndex || el.style.zIndex;
|
199
|
+
if (targetZIndex !== '' &&
|
200
|
+
targetZIndex !== 'auto' &&
|
201
|
+
+targetZIndex > +zIndex) {
|
202
|
+
return true;
|
203
|
+
}
|
204
|
+
el = el.parentElement;
|
205
|
+
}
|
206
|
+
return false;
|
207
|
+
}
|
208
|
+
/**
|
209
|
+
* Remove inline height styles from the provided elements.
|
210
|
+
* @param elementRef - The element to search within.
|
211
|
+
* @param selector - The CSS selector to use when finding elements for removing height.
|
212
|
+
*/
|
213
|
+
resetHeight(elementRef, selector) {
|
214
|
+
const children = elementRef.nativeElement.querySelectorAll(selector);
|
215
|
+
/* istanbul ignore else */
|
216
|
+
if (children.length > 0) {
|
217
|
+
for (let i = 0; i < children.length; i++) {
|
218
|
+
// Setting style attributes with Web API requires null instead of undefined.
|
219
|
+
children[i].style.height = null;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
223
|
+
/**
|
224
|
+
* Sets all element heights to match the height of the tallest element.
|
225
|
+
* @param elementRef - The element to search within.
|
226
|
+
* @param selector - The CSS selector to use when finding elements for syncing height.
|
227
|
+
*/
|
228
|
+
syncMaxHeight(elementRef, selector) {
|
229
|
+
const children = elementRef.nativeElement.querySelectorAll(selector);
|
230
|
+
/* istanbul ignore else */
|
231
|
+
if (children.length > 0) {
|
232
|
+
let maxHeight = 0;
|
233
|
+
for (let i = 0; i < children.length; i++) {
|
234
|
+
maxHeight = Math.max(maxHeight, children[i].offsetHeight);
|
235
|
+
}
|
236
|
+
for (let i = 0; i < children.length; i++) {
|
237
|
+
children[i].style.height = maxHeight + 'px';
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
#focusFirstElement(list) {
|
242
|
+
if (list.length > 0) {
|
243
|
+
list[0].focus();
|
244
|
+
return true;
|
245
|
+
}
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
#isVisible(element) {
|
249
|
+
const style = window.getComputedStyle(element);
|
250
|
+
const isHidden = style.display === 'none' || style.visibility === 'hidden';
|
251
|
+
if (isHidden) {
|
252
|
+
return false;
|
253
|
+
}
|
254
|
+
const hasBounds = !!(element.offsetWidth ||
|
255
|
+
element.offsetHeight ||
|
256
|
+
element.getClientRects().length);
|
257
|
+
return hasBounds;
|
258
|
+
}
|
259
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterService, deps: [{ token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
260
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterService, providedIn: 'root' }); }
|
261
|
+
}
|
262
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreAdapterService, decorators: [{
|
263
|
+
type: Injectable,
|
264
|
+
args: [{
|
265
|
+
providedIn: 'root',
|
266
|
+
}]
|
267
|
+
}], ctorParameters: function () { return [{ type: i0.RendererFactory2 }]; } });
|
268
|
+
|
269
|
+
var SkyAffixAutoFitContext;
|
270
|
+
(function (SkyAffixAutoFitContext) {
|
271
|
+
/**
|
272
|
+
* Auto-fit functionality will respect the nearest overflow parent element's dimensions.
|
273
|
+
*/
|
274
|
+
SkyAffixAutoFitContext[SkyAffixAutoFitContext["OverflowParent"] = 0] = "OverflowParent";
|
275
|
+
/**
|
276
|
+
* Auto-fit functionality will respect the browser viewport dimensions.
|
277
|
+
*/
|
278
|
+
SkyAffixAutoFitContext[SkyAffixAutoFitContext["Viewport"] = 1] = "Viewport";
|
279
|
+
})(SkyAffixAutoFitContext || (SkyAffixAutoFitContext = {}));
|
280
|
+
|
281
|
+
function getNextPlacement(placement) {
|
282
|
+
const placements = ['above', 'right', 'below', 'left'];
|
283
|
+
let index = placements.indexOf(placement) + 1;
|
284
|
+
if (index >= placements.length) {
|
285
|
+
index = 0;
|
286
|
+
}
|
287
|
+
return placements[index];
|
288
|
+
}
|
289
|
+
function getInversePlacement(placement) {
|
290
|
+
const pairings = {
|
291
|
+
above: 'below',
|
292
|
+
below: 'above',
|
293
|
+
right: 'left',
|
294
|
+
left: 'right',
|
295
|
+
};
|
296
|
+
return pairings[placement];
|
297
|
+
}
|
298
|
+
|
299
|
+
/**
|
300
|
+
* Returns the offset values of a given element.
|
301
|
+
* @param element The HTML element.
|
302
|
+
* @param bufferOffset An optional offset to add/subtract to the element's actual offset.
|
303
|
+
*/
|
304
|
+
function getElementOffset(element, bufferOffset) {
|
305
|
+
const bufferOffsetBottom = bufferOffset?.bottom || 0;
|
306
|
+
const bufferOffsetLeft = bufferOffset?.left || 0;
|
307
|
+
const bufferOffsetRight = bufferOffset?.right || 0;
|
308
|
+
const bufferOffsetTop = bufferOffset?.top || 0;
|
309
|
+
let top;
|
310
|
+
let left;
|
311
|
+
let right;
|
312
|
+
let bottom;
|
313
|
+
if (element === document.body) {
|
314
|
+
left = 0;
|
315
|
+
top = 0;
|
316
|
+
right = document.documentElement.clientWidth;
|
317
|
+
bottom = document.documentElement.clientHeight;
|
318
|
+
}
|
319
|
+
else {
|
320
|
+
const clientRect = element.getBoundingClientRect();
|
321
|
+
left = clientRect.left;
|
322
|
+
top = clientRect.top;
|
323
|
+
right = clientRect.right;
|
324
|
+
bottom = clientRect.bottom;
|
325
|
+
}
|
326
|
+
bottom -= bufferOffsetBottom;
|
327
|
+
left += bufferOffsetLeft;
|
328
|
+
right -= bufferOffsetRight;
|
329
|
+
top += bufferOffsetTop;
|
330
|
+
return {
|
331
|
+
bottom,
|
332
|
+
left,
|
333
|
+
right,
|
334
|
+
top,
|
335
|
+
};
|
336
|
+
}
|
337
|
+
function getOverflowParents(child) {
|
338
|
+
const bodyElement = window.document.body;
|
339
|
+
const results = [bodyElement];
|
340
|
+
let parentElement = child?.parentNode;
|
341
|
+
while (parentElement !== undefined &&
|
342
|
+
parentElement !== bodyElement &&
|
343
|
+
parentElement instanceof HTMLElement) {
|
344
|
+
const overflowY = window
|
345
|
+
.getComputedStyle(parentElement, undefined)
|
346
|
+
.overflowY.toLowerCase();
|
347
|
+
if (overflowY === 'auto' ||
|
348
|
+
overflowY === 'hidden' ||
|
349
|
+
overflowY === 'scroll') {
|
350
|
+
results.push(parentElement);
|
351
|
+
}
|
352
|
+
parentElement = parentElement.parentNode;
|
353
|
+
}
|
354
|
+
return results;
|
355
|
+
}
|
356
|
+
/**
|
357
|
+
* Confirms offset is fully visible within a parent element.
|
358
|
+
* @param parent
|
359
|
+
* @param offset
|
360
|
+
*/
|
361
|
+
function isOffsetFullyVisibleWithinParent(parent, offset, bufferOffset) {
|
362
|
+
const parentOffset = getElementOffset(parent, bufferOffset);
|
363
|
+
return !(parentOffset.top > offset.top ||
|
364
|
+
parentOffset.right < offset.right ||
|
365
|
+
parentOffset.bottom < offset.bottom ||
|
366
|
+
parentOffset.left > offset.left);
|
367
|
+
}
|
368
|
+
function isOffsetPartiallyVisibleWithinParent(parent, offset, bufferOffset) {
|
369
|
+
const parentOffset = getElementOffset(parent, bufferOffset);
|
370
|
+
return !(parentOffset.top >= offset.bottom ||
|
371
|
+
parentOffset.right <= offset.left ||
|
372
|
+
parentOffset.bottom <= offset.top ||
|
373
|
+
parentOffset.left >= offset.right);
|
374
|
+
}
|
375
|
+
|
376
|
+
const DEFAULT_AFFIX_CONFIG = {
|
377
|
+
autoFitContext: SkyAffixAutoFitContext.OverflowParent,
|
378
|
+
enableAutoFit: false,
|
379
|
+
horizontalAlignment: 'center',
|
380
|
+
isSticky: false,
|
381
|
+
placement: 'above',
|
382
|
+
};
|
383
|
+
class SkyAffixer {
|
384
|
+
/**
|
385
|
+
* Fires when the affixed element's offset changes.
|
386
|
+
*/
|
387
|
+
get offsetChange() {
|
388
|
+
return this.#offsetChangeObs;
|
389
|
+
}
|
390
|
+
/**
|
391
|
+
* Fires when the base element's nearest overflow parent is scrolling. This is useful if you need
|
392
|
+
* to perform an additional action during the scroll event but don't want to generate another
|
393
|
+
* event listener.
|
394
|
+
*/
|
395
|
+
get overflowScroll() {
|
396
|
+
return this.#overflowScrollObs;
|
397
|
+
}
|
398
|
+
/**
|
399
|
+
* Fires when the placement value changes. A `null` value indicates that a suitable
|
400
|
+
* placement could not be found.
|
401
|
+
*/
|
402
|
+
get placementChange() {
|
403
|
+
return this.#placementChangeObs;
|
404
|
+
}
|
405
|
+
get #config() {
|
406
|
+
return this.#_config;
|
407
|
+
}
|
408
|
+
set #config(value) {
|
409
|
+
const merged = {
|
410
|
+
...DEFAULT_AFFIX_CONFIG,
|
411
|
+
...value,
|
412
|
+
};
|
413
|
+
// Make sure none of the values are undefined.
|
414
|
+
let key;
|
415
|
+
for (key in merged) {
|
416
|
+
if (merged[key] === undefined) {
|
417
|
+
merged[key] = DEFAULT_AFFIX_CONFIG[key];
|
418
|
+
}
|
419
|
+
}
|
420
|
+
this.#_config = merged;
|
421
|
+
}
|
422
|
+
#affixedElement;
|
423
|
+
#baseElement;
|
424
|
+
#currentOffset;
|
425
|
+
#currentPlacement;
|
426
|
+
#offsetChange;
|
427
|
+
#offsetChangeObs;
|
428
|
+
#overflowParents = [];
|
429
|
+
#overflowScroll;
|
430
|
+
#overflowScrollObs;
|
431
|
+
#placementChange;
|
432
|
+
#placementChangeObs;
|
433
|
+
#renderer;
|
434
|
+
#resizeListener;
|
435
|
+
#scrollListeners;
|
436
|
+
#_config = DEFAULT_AFFIX_CONFIG;
|
437
|
+
constructor(affixedElement, renderer) {
|
438
|
+
this.#affixedElement = affixedElement;
|
439
|
+
this.#renderer = renderer;
|
440
|
+
this.#offsetChange = new Subject();
|
441
|
+
this.#overflowScroll = new Subject();
|
442
|
+
this.#placementChange = new Subject();
|
443
|
+
this.#offsetChangeObs = this.#offsetChange.asObservable();
|
444
|
+
this.#overflowScrollObs = this.#overflowScroll.asObservable();
|
445
|
+
this.#placementChangeObs = this.#placementChange.asObservable();
|
446
|
+
}
|
447
|
+
/**
|
448
|
+
* Affixes an element to a base element.
|
449
|
+
* @param baseElement The base element.
|
450
|
+
* @param config Configuration for the affix action.
|
451
|
+
*/
|
452
|
+
affixTo(baseElement, config) {
|
453
|
+
this.#reset();
|
454
|
+
this.#config = config;
|
455
|
+
this.#baseElement = baseElement;
|
456
|
+
this.#overflowParents = getOverflowParents(baseElement);
|
457
|
+
this.#affix();
|
458
|
+
if (this.#config.isSticky) {
|
459
|
+
this.#addScrollListeners();
|
460
|
+
this.#addResizeListener();
|
461
|
+
}
|
462
|
+
}
|
463
|
+
getConfig() {
|
464
|
+
return this.#config;
|
465
|
+
}
|
466
|
+
/**
|
467
|
+
* Re-runs the affix calculation.
|
468
|
+
*/
|
469
|
+
reaffix() {
|
470
|
+
// Reset current placement to preferred placement.
|
471
|
+
this.#currentPlacement = this.#config.placement;
|
472
|
+
this.#affix();
|
473
|
+
}
|
474
|
+
/**
|
475
|
+
* Destroys the affixer.
|
476
|
+
*/
|
477
|
+
destroy() {
|
478
|
+
this.#reset();
|
479
|
+
this.#placementChange.complete();
|
480
|
+
this.#offsetChange.complete();
|
481
|
+
this.#overflowScroll.complete();
|
482
|
+
}
|
483
|
+
#affix() {
|
484
|
+
const offset = this.#getOffset();
|
485
|
+
if (this.#isNewOffset(offset)) {
|
486
|
+
this.#renderer.setStyle(this.#affixedElement, 'top', `${offset.top}px`);
|
487
|
+
this.#renderer.setStyle(this.#affixedElement, 'left', `${offset.left}px`);
|
488
|
+
this.#offsetChange.next({ offset });
|
489
|
+
}
|
490
|
+
}
|
491
|
+
#getOffset() {
|
492
|
+
const parent = this.#getAutoFitContextParent();
|
493
|
+
const maxAttempts = 4;
|
494
|
+
let attempts = 0;
|
495
|
+
let isAffixedElementFullyVisible = false;
|
496
|
+
let offset;
|
497
|
+
let placement = this.#config.placement;
|
498
|
+
const autoFitOverflowOffset = this.#config.autoFitOverflowOffset || {
|
499
|
+
bottom: 0,
|
500
|
+
left: 0,
|
501
|
+
right: 0,
|
502
|
+
top: 0,
|
503
|
+
};
|
504
|
+
if (this.#config.position === 'absolute') {
|
505
|
+
autoFitOverflowOffset.top =
|
506
|
+
(autoFitOverflowOffset.top || 0) + window.scrollY;
|
507
|
+
}
|
508
|
+
do {
|
509
|
+
offset = this.#getPreferredOffset(placement);
|
510
|
+
isAffixedElementFullyVisible = isOffsetFullyVisibleWithinParent(parent, offset, autoFitOverflowOffset);
|
511
|
+
if (!this.#config.enableAutoFit) {
|
512
|
+
break;
|
513
|
+
}
|
514
|
+
if (!isAffixedElementFullyVisible) {
|
515
|
+
placement =
|
516
|
+
attempts % 2 === 0
|
517
|
+
? getInversePlacement(placement)
|
518
|
+
: getNextPlacement(placement);
|
519
|
+
}
|
520
|
+
attempts++;
|
521
|
+
} while (!isAffixedElementFullyVisible && attempts < maxAttempts);
|
522
|
+
if (isAffixedElementFullyVisible) {
|
523
|
+
if (this.#isBaseElementVisible()) {
|
524
|
+
this.#notifyPlacementChange(placement);
|
525
|
+
}
|
526
|
+
else {
|
527
|
+
this.#notifyPlacementChange(null);
|
528
|
+
}
|
529
|
+
return offset;
|
530
|
+
}
|
531
|
+
if (this.#config.enableAutoFit) {
|
532
|
+
this.#notifyPlacementChange(null);
|
533
|
+
}
|
534
|
+
// No suitable placement was found, so revert to preferred placement.
|
535
|
+
return this.#getPreferredOffset(this.#config.placement);
|
536
|
+
}
|
537
|
+
#getRect(baseElement) {
|
538
|
+
const baseDomRect = baseElement.getBoundingClientRect();
|
539
|
+
const baseRect = {
|
540
|
+
top: baseDomRect.top,
|
541
|
+
bottom: baseDomRect.bottom,
|
542
|
+
left: baseDomRect.left,
|
543
|
+
right: baseDomRect.right,
|
544
|
+
width: baseDomRect.width,
|
545
|
+
height: baseDomRect.height,
|
546
|
+
};
|
547
|
+
if (this.#config.position === 'absolute') {
|
548
|
+
baseRect.top += window.scrollY;
|
549
|
+
baseRect.bottom = baseRect.top + baseDomRect.height;
|
550
|
+
}
|
551
|
+
return baseRect;
|
552
|
+
}
|
553
|
+
#getPreferredOffset(placement) {
|
554
|
+
if (!this.#baseElement) {
|
555
|
+
return { top: 0, left: 0, bottom: 0, right: 0 };
|
556
|
+
}
|
557
|
+
const affixedRect = this.#getRect(this.#affixedElement);
|
558
|
+
const baseRect = this.#getRect(this.#baseElement);
|
559
|
+
const horizontalAlignment = this.#config.horizontalAlignment;
|
560
|
+
const verticalAlignment = this.#config.verticalAlignment;
|
561
|
+
const enableAutoFit = this.#config.enableAutoFit;
|
562
|
+
let top;
|
563
|
+
let left;
|
564
|
+
if (placement === 'above' || placement === 'below') {
|
565
|
+
if (placement === 'above') {
|
566
|
+
top = baseRect.top - affixedRect.height;
|
567
|
+
switch (verticalAlignment) {
|
568
|
+
case 'top':
|
569
|
+
top = top + affixedRect.height;
|
570
|
+
break;
|
571
|
+
case 'middle':
|
572
|
+
top = top + affixedRect.height / 2;
|
573
|
+
break;
|
574
|
+
case 'bottom':
|
575
|
+
default:
|
576
|
+
break;
|
577
|
+
}
|
578
|
+
}
|
579
|
+
else {
|
580
|
+
top = baseRect.bottom;
|
581
|
+
switch (verticalAlignment) {
|
582
|
+
case 'top':
|
583
|
+
default:
|
584
|
+
break;
|
585
|
+
case 'middle':
|
586
|
+
top = top - affixedRect.height / 2;
|
587
|
+
break;
|
588
|
+
case 'bottom':
|
589
|
+
top = top - affixedRect.height;
|
590
|
+
break;
|
591
|
+
}
|
592
|
+
}
|
593
|
+
switch (horizontalAlignment) {
|
594
|
+
case 'left':
|
595
|
+
left = baseRect.left;
|
596
|
+
break;
|
597
|
+
case 'center':
|
598
|
+
default:
|
599
|
+
left = baseRect.left + baseRect.width / 2 - affixedRect.width / 2;
|
600
|
+
break;
|
601
|
+
case 'right':
|
602
|
+
left = baseRect.right - affixedRect.width;
|
603
|
+
break;
|
604
|
+
}
|
605
|
+
}
|
606
|
+
else {
|
607
|
+
if (placement === 'left') {
|
608
|
+
left = baseRect.left - affixedRect.width;
|
609
|
+
}
|
610
|
+
else {
|
611
|
+
left = baseRect.right;
|
612
|
+
}
|
613
|
+
switch (verticalAlignment) {
|
614
|
+
case 'top':
|
615
|
+
top = baseRect.top;
|
616
|
+
break;
|
617
|
+
case 'middle':
|
618
|
+
default:
|
619
|
+
top = baseRect.top + baseRect.height / 2 - affixedRect.height / 2;
|
620
|
+
break;
|
621
|
+
case 'bottom':
|
622
|
+
top = baseRect.bottom - affixedRect.height;
|
623
|
+
break;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
const offset = { top, left, bottom: 0, right: 0 };
|
627
|
+
if (enableAutoFit) {
|
628
|
+
const adjustments = this.#adjustOffsetToOverflowParent({ top, left }, placement, this.#baseElement);
|
629
|
+
offset.top = adjustments.top;
|
630
|
+
offset.left = adjustments.left;
|
631
|
+
}
|
632
|
+
offset.bottom = offset.top + affixedRect.height;
|
633
|
+
offset.right = offset.left + affixedRect.width;
|
634
|
+
return offset;
|
635
|
+
}
|
636
|
+
/**
|
637
|
+
* Slightly adjust the offset to fit within the scroll parent's boundaries if
|
638
|
+
* the affixed element would otherwise be clipped.
|
639
|
+
*/
|
640
|
+
#adjustOffsetToOverflowParent(offset, placement, baseElement) {
|
641
|
+
const parent = this.#getAutoFitContextParent();
|
642
|
+
const parentOffset = getElementOffset(parent, this.#config.autoFitOverflowOffset);
|
643
|
+
const affixedRect = this.#getRect(this.#affixedElement);
|
644
|
+
const baseRect = this.#getRect(baseElement);
|
645
|
+
// A pixel value representing the leeway between the edge of the overflow parent and the edge
|
646
|
+
// of the base element before it disappears from view.
|
647
|
+
// If the visible portion of the base element is less than this pixel value, the auto-fit
|
648
|
+
// functionality attempts to find another placement.
|
649
|
+
const defaultPixelTolerance = 40;
|
650
|
+
let pixelTolerance;
|
651
|
+
const originalOffsetTop = offset.top;
|
652
|
+
const originalOffsetLeft = offset.left;
|
653
|
+
switch (placement) {
|
654
|
+
case 'above':
|
655
|
+
case 'below':
|
656
|
+
// Keep the affixed element within the overflow parent.
|
657
|
+
if (offset.left < parentOffset.left) {
|
658
|
+
offset.left = parentOffset.left;
|
659
|
+
}
|
660
|
+
else if (offset.left + affixedRect.width > parentOffset.right) {
|
661
|
+
offset.left = parentOffset.right - affixedRect.width;
|
662
|
+
}
|
663
|
+
// Use a smaller pixel tolerance if the base element width is less than the default.
|
664
|
+
pixelTolerance = Math.min(defaultPixelTolerance, baseRect.width);
|
665
|
+
// Make sure the affixed element never detaches from the base element.
|
666
|
+
if (offset.left + pixelTolerance > baseRect.right ||
|
667
|
+
offset.left + affixedRect.width - pixelTolerance < baseRect.left) {
|
668
|
+
offset.left = originalOffsetLeft;
|
669
|
+
}
|
670
|
+
break;
|
671
|
+
case 'left':
|
672
|
+
case 'right':
|
673
|
+
// Keep the affixed element within the overflow parent.
|
674
|
+
if (offset.top < parentOffset.top) {
|
675
|
+
offset.top = parentOffset.top;
|
676
|
+
}
|
677
|
+
else if (offset.top + affixedRect.height > parentOffset.bottom) {
|
678
|
+
offset.top = parentOffset.bottom - affixedRect.height;
|
679
|
+
}
|
680
|
+
// Use a smaller pixel tolerance if the base element height is less than the default.
|
681
|
+
pixelTolerance = Math.min(defaultPixelTolerance, baseRect.height);
|
682
|
+
// Make sure the affixed element never detaches from the base element.
|
683
|
+
if (offset.top + pixelTolerance > baseRect.bottom ||
|
684
|
+
offset.top + affixedRect.height - pixelTolerance < baseRect.top) {
|
685
|
+
offset.top = originalOffsetTop;
|
686
|
+
}
|
687
|
+
break;
|
688
|
+
}
|
689
|
+
return offset;
|
690
|
+
}
|
691
|
+
#getImmediateOverflowParent() {
|
692
|
+
return this.#overflowParents[this.#overflowParents.length - 1];
|
693
|
+
}
|
694
|
+
#getAutoFitContextParent() {
|
695
|
+
const bodyElement = this.#overflowParents[0];
|
696
|
+
return this.#config.autoFitContext === SkyAffixAutoFitContext.OverflowParent
|
697
|
+
? this.#getImmediateOverflowParent()
|
698
|
+
: bodyElement;
|
699
|
+
}
|
700
|
+
#notifyPlacementChange(placement) {
|
701
|
+
if (this.#currentPlacement !== placement) {
|
702
|
+
this.#currentPlacement = placement ?? undefined;
|
703
|
+
this.#placementChange.next({
|
704
|
+
placement,
|
705
|
+
});
|
706
|
+
}
|
707
|
+
}
|
708
|
+
#reset() {
|
709
|
+
this.#removeScrollListeners();
|
710
|
+
this.#removeResizeListener();
|
711
|
+
this.#overflowParents = [];
|
712
|
+
this.#config =
|
713
|
+
this.#baseElement =
|
714
|
+
this.#currentPlacement =
|
715
|
+
this.#currentOffset =
|
716
|
+
undefined;
|
717
|
+
}
|
718
|
+
#isNewOffset(offset) {
|
719
|
+
if (this.#currentOffset === undefined) {
|
720
|
+
this.#currentOffset = offset;
|
721
|
+
return true;
|
722
|
+
}
|
723
|
+
if (this.#currentOffset.top === offset.top &&
|
724
|
+
this.#currentOffset.left === offset.left) {
|
725
|
+
return false;
|
726
|
+
}
|
727
|
+
this.#currentOffset = offset;
|
728
|
+
return true;
|
729
|
+
}
|
730
|
+
#isBaseElementVisible() {
|
731
|
+
if (!this.#baseElement) {
|
732
|
+
return false;
|
733
|
+
}
|
734
|
+
const baseRect = this.#baseElement.getBoundingClientRect();
|
735
|
+
return isOffsetPartiallyVisibleWithinParent(this.#getImmediateOverflowParent(), {
|
736
|
+
top: baseRect.top,
|
737
|
+
left: baseRect.left,
|
738
|
+
right: baseRect.right,
|
739
|
+
bottom: baseRect.bottom,
|
740
|
+
}, this.#config.autoFitOverflowOffset);
|
741
|
+
}
|
742
|
+
#addScrollListeners() {
|
743
|
+
this.#scrollListeners = this.#overflowParents.map((parentElement) => {
|
744
|
+
const overflow = parentElement === document.body ? 'window' : parentElement;
|
745
|
+
return this.#renderer.listen(overflow, 'scroll', () => {
|
746
|
+
this.#affix();
|
747
|
+
this.#overflowScroll.next();
|
748
|
+
});
|
749
|
+
});
|
750
|
+
}
|
751
|
+
#addResizeListener() {
|
752
|
+
this.#resizeListener = fromEvent(window, 'resize').subscribe(() => this.#affix());
|
753
|
+
}
|
754
|
+
#removeResizeListener() {
|
755
|
+
if (this.#resizeListener) {
|
756
|
+
this.#resizeListener.unsubscribe();
|
757
|
+
this.#resizeListener = undefined;
|
758
|
+
}
|
759
|
+
}
|
760
|
+
#removeScrollListeners() {
|
761
|
+
if (this.#scrollListeners) {
|
762
|
+
// Remove renderer-generated listeners by calling the listener itself.
|
763
|
+
// https://github.com/angular/angular/issues/9368#issuecomment-227199778
|
764
|
+
this.#scrollListeners.forEach((listener) => listener());
|
765
|
+
this.#scrollListeners = undefined;
|
766
|
+
}
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
class SkyAffixService {
|
771
|
+
#renderer;
|
772
|
+
constructor(rendererFactory) {
|
773
|
+
this.#renderer = rendererFactory.createRenderer(undefined, null);
|
774
|
+
}
|
775
|
+
/**
|
776
|
+
* Creates an instance of [[SkyAffixer]].
|
777
|
+
* @param affixed The element to be affixed.
|
778
|
+
*/
|
779
|
+
createAffixer(affixed) {
|
780
|
+
return new SkyAffixer(affixed.nativeElement, this.#renderer);
|
781
|
+
}
|
782
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixService, deps: [{ token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
783
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixService, providedIn: 'root' }); }
|
784
|
+
}
|
785
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixService, decorators: [{
|
786
|
+
type: Injectable,
|
787
|
+
args: [{
|
788
|
+
providedIn: 'root',
|
789
|
+
}]
|
790
|
+
}], ctorParameters: function () { return [{ type: i0.RendererFactory2 }]; } });
|
791
|
+
|
792
|
+
/**
|
793
|
+
* Affixes the host element to a base element.
|
794
|
+
*/
|
795
|
+
class SkyAffixDirective {
|
796
|
+
#affixer;
|
797
|
+
#affixService;
|
798
|
+
#elementRef;
|
799
|
+
#ngUnsubscribe;
|
800
|
+
constructor(elementRef, affixService) {
|
801
|
+
/**
|
802
|
+
* Fires when the affixed element's offset changes.
|
803
|
+
*/
|
804
|
+
this.affixOffsetChange = new EventEmitter();
|
805
|
+
/**
|
806
|
+
* Fires when the affixed element's overflow container is scrolled.
|
807
|
+
*/
|
808
|
+
this.affixOverflowScroll = new EventEmitter();
|
809
|
+
/**
|
810
|
+
* Fires when the placement value changes.
|
811
|
+
*/
|
812
|
+
this.affixPlacementChange = new EventEmitter();
|
813
|
+
this.#ngUnsubscribe = new Subject();
|
814
|
+
this.#elementRef = elementRef;
|
815
|
+
this.#affixService = affixService;
|
816
|
+
}
|
817
|
+
ngOnInit() {
|
818
|
+
this.#affixer = this.#affixService.createAffixer(this.#elementRef);
|
819
|
+
this.#affixer.offsetChange
|
820
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
821
|
+
.subscribe((change) => this.affixOffsetChange.emit(change));
|
822
|
+
this.#affixer.overflowScroll
|
823
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
824
|
+
.subscribe((change) => this.affixOverflowScroll.emit(change));
|
825
|
+
this.#affixer.placementChange
|
826
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
827
|
+
.subscribe((change) => this.affixPlacementChange.emit(change));
|
828
|
+
this.#updateAlignment();
|
829
|
+
}
|
830
|
+
ngOnChanges(changes) {
|
831
|
+
/* istanbul ignore else */
|
832
|
+
if (changes['affixAutoFitContext'] ||
|
833
|
+
changes['affixAutoFitOverflowOffset'] ||
|
834
|
+
changes['affixEnableAutoFit'] ||
|
835
|
+
changes['affixHorizontalAlignment'] ||
|
836
|
+
changes['affixIsSticky'] ||
|
837
|
+
changes['affixPlacement'] ||
|
838
|
+
changes['affixPosition'] ||
|
839
|
+
changes['affixVerticalAlignment']) {
|
840
|
+
this.#updateAlignment();
|
841
|
+
}
|
842
|
+
}
|
843
|
+
ngOnDestroy() {
|
844
|
+
this.affixOffsetChange.complete();
|
845
|
+
this.affixOverflowScroll.complete();
|
846
|
+
this.affixPlacementChange.complete();
|
847
|
+
this.#ngUnsubscribe.next();
|
848
|
+
this.#ngUnsubscribe.complete();
|
849
|
+
/*istanbul ignore else*/
|
850
|
+
if (this.#affixer) {
|
851
|
+
this.#affixer.destroy();
|
852
|
+
this.#affixer = undefined;
|
853
|
+
}
|
854
|
+
}
|
855
|
+
#updateAlignment() {
|
856
|
+
if (this.skyAffixTo && this.#affixer) {
|
857
|
+
this.#affixer.affixTo(this.skyAffixTo, {
|
858
|
+
autoFitContext: this.affixAutoFitContext,
|
859
|
+
autoFitOverflowOffset: this.affixAutoFitOverflowOffset,
|
860
|
+
enableAutoFit: this.affixEnableAutoFit,
|
861
|
+
horizontalAlignment: this.affixHorizontalAlignment,
|
862
|
+
isSticky: this.affixIsSticky,
|
863
|
+
placement: this.affixPlacement,
|
864
|
+
position: this.affixPosition,
|
865
|
+
verticalAlignment: this.affixVerticalAlignment,
|
866
|
+
});
|
867
|
+
}
|
868
|
+
}
|
869
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixDirective, deps: [{ token: i0.ElementRef }, { token: SkyAffixService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
870
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: SkyAffixDirective, selector: "[skyAffixTo]", inputs: { skyAffixTo: "skyAffixTo", affixAutoFitContext: "affixAutoFitContext", affixAutoFitOverflowOffset: "affixAutoFitOverflowOffset", affixEnableAutoFit: "affixEnableAutoFit", affixHorizontalAlignment: "affixHorizontalAlignment", affixIsSticky: "affixIsSticky", affixPlacement: "affixPlacement", affixPosition: "affixPosition", affixVerticalAlignment: "affixVerticalAlignment" }, outputs: { affixOffsetChange: "affixOffsetChange", affixOverflowScroll: "affixOverflowScroll", affixPlacementChange: "affixPlacementChange" }, usesOnChanges: true, ngImport: i0 }); }
|
871
|
+
}
|
872
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixDirective, decorators: [{
|
873
|
+
type: Directive,
|
874
|
+
args: [{
|
875
|
+
selector: '[skyAffixTo]',
|
876
|
+
}]
|
877
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: SkyAffixService }]; }, propDecorators: { skyAffixTo: [{
|
878
|
+
type: Input
|
879
|
+
}], affixAutoFitContext: [{
|
880
|
+
type: Input
|
881
|
+
}], affixAutoFitOverflowOffset: [{
|
882
|
+
type: Input
|
883
|
+
}], affixEnableAutoFit: [{
|
884
|
+
type: Input
|
885
|
+
}], affixHorizontalAlignment: [{
|
886
|
+
type: Input
|
887
|
+
}], affixIsSticky: [{
|
888
|
+
type: Input
|
889
|
+
}], affixPlacement: [{
|
890
|
+
type: Input
|
891
|
+
}], affixPosition: [{
|
892
|
+
type: Input
|
893
|
+
}], affixVerticalAlignment: [{
|
894
|
+
type: Input
|
895
|
+
}], affixOffsetChange: [{
|
896
|
+
type: Output
|
897
|
+
}], affixOverflowScroll: [{
|
898
|
+
type: Output
|
899
|
+
}], affixPlacementChange: [{
|
900
|
+
type: Output
|
901
|
+
}] } });
|
902
|
+
|
903
|
+
class SkyAffixModule {
|
904
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
905
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixModule, declarations: [SkyAffixDirective], imports: [CommonModule], exports: [SkyAffixDirective] }); }
|
906
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixModule, imports: [CommonModule] }); }
|
907
|
+
}
|
908
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAffixModule, decorators: [{
|
909
|
+
type: NgModule,
|
910
|
+
args: [{
|
911
|
+
imports: [CommonModule],
|
912
|
+
exports: [SkyAffixDirective],
|
913
|
+
declarations: [SkyAffixDirective],
|
914
|
+
}]
|
915
|
+
}] });
|
916
|
+
|
917
|
+
/**
|
918
|
+
* @internal
|
919
|
+
* An API to provide default Angular component input values to child components.
|
920
|
+
*/
|
921
|
+
class SkyDefaultInputProvider {
|
922
|
+
#props = {};
|
923
|
+
setValue(componentName, inputName, value) {
|
924
|
+
const subject = this.#getSubject(componentName, inputName);
|
925
|
+
subject.next(value);
|
926
|
+
}
|
927
|
+
getValue(componentName, inputName) {
|
928
|
+
const test = this.#getSubject(componentName, inputName);
|
929
|
+
return test.asObservable();
|
930
|
+
}
|
931
|
+
#getSubject(componentName, inputName) {
|
932
|
+
const componentSubjects = this.#props[componentName] || {};
|
933
|
+
const inputSubject = componentSubjects[inputName];
|
934
|
+
if (!inputSubject) {
|
935
|
+
componentSubjects[inputName] = new ReplaySubject(1);
|
936
|
+
this.#props[componentName] = componentSubjects;
|
937
|
+
}
|
938
|
+
return componentSubjects[inputName];
|
939
|
+
}
|
940
|
+
}
|
941
|
+
|
942
|
+
/**
|
943
|
+
* Represents a single item added to the dock.
|
944
|
+
*/
|
945
|
+
class SkyDockItem {
|
946
|
+
/**
|
947
|
+
* An event that emits when the item is removed from the dock.
|
948
|
+
*/
|
949
|
+
get destroyed() {
|
950
|
+
return this.#destroyedObs;
|
951
|
+
}
|
952
|
+
#destroyed = new Subject();
|
953
|
+
#destroyedObs;
|
954
|
+
/**
|
955
|
+
* @param componentInstance The item's component instance.
|
956
|
+
* @param stackOrder The assigned stack order of the docked item.
|
957
|
+
*/
|
958
|
+
constructor(componentInstance, stackOrder) {
|
959
|
+
this.componentInstance = componentInstance;
|
960
|
+
this.stackOrder = stackOrder;
|
961
|
+
this.#destroyedObs = this.#destroyed.asObservable();
|
962
|
+
}
|
963
|
+
/**
|
964
|
+
* Removes the item from the dock.
|
965
|
+
*/
|
966
|
+
destroy() {
|
967
|
+
this.#destroyed.next();
|
968
|
+
this.#destroyed.complete();
|
969
|
+
}
|
970
|
+
}
|
971
|
+
|
972
|
+
/**
|
973
|
+
* The location on the page where the dock component should be rendered.
|
974
|
+
*/
|
975
|
+
var SkyDockLocation;
|
976
|
+
(function (SkyDockLocation) {
|
977
|
+
/**
|
978
|
+
* Renders the dock component before a given element.
|
979
|
+
*/
|
980
|
+
SkyDockLocation[SkyDockLocation["BeforeElement"] = 0] = "BeforeElement";
|
981
|
+
/**
|
982
|
+
* Renders the dock component as the last element inside the BODY element.
|
983
|
+
*/
|
984
|
+
SkyDockLocation[SkyDockLocation["BodyBottom"] = 1] = "BodyBottom";
|
985
|
+
/**
|
986
|
+
* Renders the dock component as the last element inside a given element.
|
987
|
+
*/
|
988
|
+
SkyDockLocation[SkyDockLocation["ElementBottom"] = 2] = "ElementBottom";
|
989
|
+
})(SkyDockLocation || (SkyDockLocation = {}));
|
990
|
+
|
991
|
+
/**
|
992
|
+
* @internal
|
993
|
+
*/
|
994
|
+
class SkyMutationObserverService {
|
995
|
+
create(callback) {
|
996
|
+
return new MutationObserver(callback);
|
997
|
+
}
|
998
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMutationObserverService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
999
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMutationObserverService, providedIn: 'root' }); }
|
1000
|
+
}
|
1001
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMutationObserverService, decorators: [{
|
1002
|
+
type: Injectable,
|
1003
|
+
args: [{
|
1004
|
+
providedIn: 'root',
|
1005
|
+
}]
|
1006
|
+
}] });
|
1007
|
+
|
1008
|
+
/**
|
1009
|
+
* @internal
|
1010
|
+
*/
|
1011
|
+
class SkyDockDomAdapterService {
|
1012
|
+
#currentDockHeight;
|
1013
|
+
#mutationSvc;
|
1014
|
+
#ngUnsubscribe = new Subject();
|
1015
|
+
#observer;
|
1016
|
+
#renderer;
|
1017
|
+
#styleElement;
|
1018
|
+
constructor(mutationSvc, rendererFactory) {
|
1019
|
+
this.#mutationSvc = mutationSvc;
|
1020
|
+
this.#renderer = rendererFactory.createRenderer(undefined, null);
|
1021
|
+
}
|
1022
|
+
ngOnDestroy() {
|
1023
|
+
if (this.#observer) {
|
1024
|
+
this.#observer.disconnect();
|
1025
|
+
}
|
1026
|
+
this.#ngUnsubscribe.next();
|
1027
|
+
this.#ngUnsubscribe.complete();
|
1028
|
+
if (this.#styleElement) {
|
1029
|
+
this.#destroyStyleElement();
|
1030
|
+
}
|
1031
|
+
this.#currentDockHeight = this.#observer = this.#styleElement = undefined;
|
1032
|
+
}
|
1033
|
+
setSticky(elementRef) {
|
1034
|
+
this.#renderer.addClass(elementRef.nativeElement, 'sky-dock-sticky');
|
1035
|
+
}
|
1036
|
+
setZIndex(zIndex, elementRef) {
|
1037
|
+
this.#renderer.setStyle(elementRef.nativeElement, 'z-index', zIndex);
|
1038
|
+
}
|
1039
|
+
unbindDock(elementRef) {
|
1040
|
+
this.#renderer.addClass(elementRef.nativeElement, 'sky-dock-unbound');
|
1041
|
+
}
|
1042
|
+
watchDomChanges(elementRef) {
|
1043
|
+
this.#observer = this.#mutationSvc.create(() => {
|
1044
|
+
this.#adjustBodyStyles(elementRef);
|
1045
|
+
});
|
1046
|
+
this.#observer.observe(elementRef.nativeElement, {
|
1047
|
+
attributes: true,
|
1048
|
+
childList: true,
|
1049
|
+
characterData: true,
|
1050
|
+
subtree: true,
|
1051
|
+
});
|
1052
|
+
fromEvent(window, 'resize')
|
1053
|
+
.pipe(debounceTime(250), takeUntil(this.#ngUnsubscribe))
|
1054
|
+
.subscribe(() => this.#adjustBodyStyles(elementRef));
|
1055
|
+
}
|
1056
|
+
#adjustBodyStyles(elementRef) {
|
1057
|
+
const dockHeight = elementRef.nativeElement.getBoundingClientRect().height;
|
1058
|
+
if (dockHeight === this.#currentDockHeight) {
|
1059
|
+
return;
|
1060
|
+
}
|
1061
|
+
// Create a style element to avoid overwriting any existing inline body styles.
|
1062
|
+
const styleElement = this.#renderer.createElement('style');
|
1063
|
+
const textNode = this.#renderer.createText(`body { margin-bottom: ${dockHeight}px; }`);
|
1064
|
+
// Apply a `data-` attribute to make unit testing easier.
|
1065
|
+
this.#renderer.setAttribute(styleElement, 'data-test-selector', 'sky-layout-dock-bottom-styles');
|
1066
|
+
this.#renderer.appendChild(styleElement, textNode);
|
1067
|
+
this.#renderer.appendChild(document.head, styleElement);
|
1068
|
+
if (this.#styleElement) {
|
1069
|
+
this.#destroyStyleElement();
|
1070
|
+
}
|
1071
|
+
this.#currentDockHeight = dockHeight;
|
1072
|
+
this.#styleElement = styleElement;
|
1073
|
+
}
|
1074
|
+
#destroyStyleElement() {
|
1075
|
+
this.#renderer.removeChild(document.head, this.#styleElement);
|
1076
|
+
}
|
1077
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockDomAdapterService, deps: [{ token: SkyMutationObserverService }, { token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1078
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockDomAdapterService }); }
|
1079
|
+
}
|
1080
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockDomAdapterService, decorators: [{
|
1081
|
+
type: Injectable
|
1082
|
+
}], ctorParameters: function () { return [{ type: SkyMutationObserverService }, { type: i0.RendererFactory2 }]; } });
|
1083
|
+
|
1084
|
+
/**
|
1085
|
+
* @internal
|
1086
|
+
*/
|
1087
|
+
function sortByStackOrder(a, b) {
|
1088
|
+
if (a.stackOrder > b.stackOrder) {
|
1089
|
+
return -1;
|
1090
|
+
}
|
1091
|
+
if (a.stackOrder < b.stackOrder) {
|
1092
|
+
return 1;
|
1093
|
+
}
|
1094
|
+
return 0;
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
/**
|
1098
|
+
* @internal
|
1099
|
+
*/
|
1100
|
+
class SkyDockComponent {
|
1101
|
+
#changeDetector;
|
1102
|
+
#domAdapter;
|
1103
|
+
#elementRef;
|
1104
|
+
#injector;
|
1105
|
+
#itemRefs = [];
|
1106
|
+
#options;
|
1107
|
+
constructor(changeDetector, elementRef, injector, domAdapter) {
|
1108
|
+
this.#changeDetector = changeDetector;
|
1109
|
+
this.#elementRef = elementRef;
|
1110
|
+
this.#injector = injector;
|
1111
|
+
this.#domAdapter = domAdapter;
|
1112
|
+
}
|
1113
|
+
insertComponent(component, config = {}) {
|
1114
|
+
/*istanbul ignore if: untestable*/
|
1115
|
+
if (!this.target) {
|
1116
|
+
throw Error('[SkyDockComponent] Could not insert the component because the target element could not be found.');
|
1117
|
+
}
|
1118
|
+
const injector = Injector.create({
|
1119
|
+
providers: config.providers || [],
|
1120
|
+
parent: this.#injector,
|
1121
|
+
});
|
1122
|
+
const componentRef = this.target.createComponent(component, {
|
1123
|
+
injector,
|
1124
|
+
});
|
1125
|
+
const stackOrder = config.stackOrder !== null && config.stackOrder !== undefined
|
1126
|
+
? config.stackOrder
|
1127
|
+
: this.#getHighestStackOrder();
|
1128
|
+
this.#itemRefs.push({
|
1129
|
+
componentRef,
|
1130
|
+
stackOrder,
|
1131
|
+
});
|
1132
|
+
this.#sortItemsByStackOrder();
|
1133
|
+
this.#changeDetector.markForCheck();
|
1134
|
+
return {
|
1135
|
+
componentRef,
|
1136
|
+
stackOrder,
|
1137
|
+
};
|
1138
|
+
}
|
1139
|
+
removeItem(item) {
|
1140
|
+
/*istanbul ignore if: untestable*/
|
1141
|
+
if (!this.target) {
|
1142
|
+
throw Error('[SkyDockComponent] Could not remove the item because the target element could not be found.');
|
1143
|
+
}
|
1144
|
+
const viewRef = item.componentRef.hostView;
|
1145
|
+
this.target.remove(this.target.indexOf(viewRef));
|
1146
|
+
const found = this.#itemRefs.find((i) => i.componentRef.hostView === viewRef);
|
1147
|
+
if (found) {
|
1148
|
+
this.#itemRefs.splice(this.#itemRefs.indexOf(found), 1);
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
setOptions(options) {
|
1152
|
+
this.#options = options;
|
1153
|
+
switch (this.#options?.location) {
|
1154
|
+
case SkyDockLocation.BeforeElement:
|
1155
|
+
this.#domAdapter.unbindDock(this.#elementRef);
|
1156
|
+
break;
|
1157
|
+
case SkyDockLocation.ElementBottom:
|
1158
|
+
this.#domAdapter.setSticky(this.#elementRef);
|
1159
|
+
break;
|
1160
|
+
case SkyDockLocation.BodyBottom:
|
1161
|
+
default:
|
1162
|
+
this.#domAdapter.watchDomChanges(this.#elementRef);
|
1163
|
+
break;
|
1164
|
+
}
|
1165
|
+
if (this.#options?.zIndex) {
|
1166
|
+
this.#domAdapter.setZIndex(this.#options.zIndex, this.#elementRef);
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
#sortItemsByStackOrder() {
|
1170
|
+
if (this.target) {
|
1171
|
+
this.#itemRefs.sort(sortByStackOrder);
|
1172
|
+
// Reassign the correct index for each view.
|
1173
|
+
for (let i = 0, len = this.#itemRefs.length; i < len; i++) {
|
1174
|
+
const item = this.#itemRefs[i];
|
1175
|
+
this.target.move(item.componentRef.hostView, i);
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
#getHighestStackOrder() {
|
1180
|
+
if (this.#itemRefs.length === 0) {
|
1181
|
+
return 0;
|
1182
|
+
}
|
1183
|
+
return this.#itemRefs[0].stackOrder + 1;
|
1184
|
+
}
|
1185
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Injector }, { token: SkyDockDomAdapterService }], target: i0.ɵɵFactoryTarget.Component }); }
|
1186
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: SkyDockComponent, selector: "sky-dock", providers: [SkyDockDomAdapterService], viewQueries: [{ propertyName: "target", first: true, predicate: ["target"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<ng-container #target></ng-container>\n", styles: [":host{display:flex;flex-direction:column;width:100%}:host:not(.sky-dock-unbound){position:fixed;left:var(--sky-viewport-left, 0);bottom:var(--sky-viewport-bottom, 0);right:var(--sky-viewport-right, 0);width:auto}:host.sky-dock-sticky{position:sticky}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
1187
|
+
}
|
1188
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockComponent, decorators: [{
|
1189
|
+
type: Component,
|
1190
|
+
args: [{ selector: 'sky-dock', providers: [SkyDockDomAdapterService], changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container #target></ng-container>\n", styles: [":host{display:flex;flex-direction:column;width:100%}:host:not(.sky-dock-unbound){position:fixed;left:var(--sky-viewport-left, 0);bottom:var(--sky-viewport-bottom, 0);right:var(--sky-viewport-right, 0);width:auto}:host.sky-dock-sticky{position:sticky}\n"] }]
|
1191
|
+
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.Injector }, { type: SkyDockDomAdapterService }]; }, propDecorators: { target: [{
|
1192
|
+
type: ViewChild,
|
1193
|
+
args: ['target', {
|
1194
|
+
read: ViewContainerRef,
|
1195
|
+
static: true,
|
1196
|
+
}]
|
1197
|
+
}] } });
|
1198
|
+
|
1199
|
+
class SkyDockModule {
|
1200
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1201
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyDockModule, declarations: [SkyDockComponent], imports: [CommonModule] }); }
|
1202
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockModule, providers: [SkyMutationObserverService], imports: [CommonModule] }); }
|
1203
|
+
}
|
1204
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockModule, decorators: [{
|
1205
|
+
type: NgModule,
|
1206
|
+
args: [{
|
1207
|
+
imports: [CommonModule],
|
1208
|
+
declarations: [SkyDockComponent],
|
1209
|
+
providers: [SkyMutationObserverService],
|
1210
|
+
}]
|
1211
|
+
}] });
|
1212
|
+
|
1213
|
+
/**
|
1214
|
+
* The location on the page where the dynamic component should be rendered.
|
1215
|
+
*/
|
1216
|
+
var SkyDynamicComponentLocation;
|
1217
|
+
(function (SkyDynamicComponentLocation) {
|
1218
|
+
/**
|
1219
|
+
* Renders the dynamic component before a given element.
|
1220
|
+
*/
|
1221
|
+
SkyDynamicComponentLocation[SkyDynamicComponentLocation["BeforeElement"] = 0] = "BeforeElement";
|
1222
|
+
/**
|
1223
|
+
* Renders the dynamic component as the last element inside the BODY element.
|
1224
|
+
*/
|
1225
|
+
SkyDynamicComponentLocation[SkyDynamicComponentLocation["BodyBottom"] = 1] = "BodyBottom";
|
1226
|
+
/**
|
1227
|
+
* Renders the dynamic component as the first element inside the BODY element.
|
1228
|
+
*/
|
1229
|
+
SkyDynamicComponentLocation[SkyDynamicComponentLocation["BodyTop"] = 2] = "BodyTop";
|
1230
|
+
/**
|
1231
|
+
* Renders the dynamic component as the last element inside a given element.
|
1232
|
+
*/
|
1233
|
+
SkyDynamicComponentLocation[SkyDynamicComponentLocation["ElementBottom"] = 3] = "ElementBottom";
|
1234
|
+
/**
|
1235
|
+
* Renders the dynamic component as the first element inside a given element.
|
1236
|
+
*/
|
1237
|
+
SkyDynamicComponentLocation[SkyDynamicComponentLocation["ElementTop"] = 4] = "ElementTop";
|
1238
|
+
})(SkyDynamicComponentLocation || (SkyDynamicComponentLocation = {}));
|
1239
|
+
|
1240
|
+
/**
|
1241
|
+
* @internal
|
1242
|
+
*/
|
1243
|
+
function getWindow() {
|
1244
|
+
return window;
|
1245
|
+
}
|
1246
|
+
/**
|
1247
|
+
* The application window reference service references the global window variable.
|
1248
|
+
* After users inject SkyAppWindowRef into a component, they can use the service to interact with
|
1249
|
+
* window properties and event handlers by referencing its nativeWindow property.
|
1250
|
+
*/
|
1251
|
+
class SkyAppWindowRef {
|
1252
|
+
/**
|
1253
|
+
* The global `window` variable.
|
1254
|
+
*/
|
1255
|
+
get nativeWindow() {
|
1256
|
+
return getWindow();
|
1257
|
+
}
|
1258
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppWindowRef, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1259
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppWindowRef, providedIn: 'root' }); }
|
1260
|
+
}
|
1261
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppWindowRef, decorators: [{
|
1262
|
+
type: Injectable,
|
1263
|
+
args: [{
|
1264
|
+
providedIn: 'root',
|
1265
|
+
}]
|
1266
|
+
}] });
|
1267
|
+
|
1268
|
+
/**
|
1269
|
+
* Angular service for creating and rendering a dynamic component.
|
1270
|
+
* @internal
|
1271
|
+
*/
|
1272
|
+
class SkyDynamicComponentService {
|
1273
|
+
#applicationRef;
|
1274
|
+
#environmentInjector;
|
1275
|
+
#injector;
|
1276
|
+
#renderer;
|
1277
|
+
#windowRef;
|
1278
|
+
constructor(applicationRef, injector, windowRef, rendererFactory, environmentInjector) {
|
1279
|
+
this.#applicationRef = applicationRef;
|
1280
|
+
this.#injector = injector;
|
1281
|
+
this.#windowRef = windowRef;
|
1282
|
+
this.#environmentInjector = environmentInjector;
|
1283
|
+
// Based on suggestions from https://github.com/angular/angular/issues/17824
|
1284
|
+
// for accessing an instance of Renderer2 in a service since Renderer2 can't
|
1285
|
+
// be injected into a service. Passing undefined for both parameters results
|
1286
|
+
// in the default renderer which is what we want here.
|
1287
|
+
this.#renderer = rendererFactory.createRenderer(undefined, null);
|
1288
|
+
}
|
1289
|
+
/**
|
1290
|
+
* Creates an instance of the specified component and adds it to the specified location
|
1291
|
+
* on the page.
|
1292
|
+
*/
|
1293
|
+
createComponent(componentType, options) {
|
1294
|
+
options = options || {
|
1295
|
+
location: SkyDynamicComponentLocation.BodyBottom,
|
1296
|
+
};
|
1297
|
+
const injector = Injector.create({
|
1298
|
+
providers: options.providers || [],
|
1299
|
+
parent: options.parentInjector || this.#injector,
|
1300
|
+
});
|
1301
|
+
let componentRef;
|
1302
|
+
if (options.viewContainerRef) {
|
1303
|
+
componentRef = options.viewContainerRef.createComponent(componentType, {
|
1304
|
+
injector,
|
1305
|
+
});
|
1306
|
+
}
|
1307
|
+
else {
|
1308
|
+
componentRef = createComponent(componentType, {
|
1309
|
+
environmentInjector: this.#environmentInjector,
|
1310
|
+
elementInjector: injector,
|
1311
|
+
});
|
1312
|
+
this.#applicationRef.attachView(componentRef.hostView);
|
1313
|
+
const el = this.#getRootNode(componentRef);
|
1314
|
+
const bodyEl = this.#windowRef.nativeWindow.document.body;
|
1315
|
+
switch (options.location) {
|
1316
|
+
case SkyDynamicComponentLocation.BeforeElement:
|
1317
|
+
if (!options.referenceEl) {
|
1318
|
+
throw new Error('[SkyDynamicComponentService] Could not create a component at location `SkyDynamicComponentLocation.BeforeElement` because a reference element was not provided.');
|
1319
|
+
}
|
1320
|
+
this.#renderer.insertBefore(options.referenceEl.parentElement, el, options.referenceEl);
|
1321
|
+
break;
|
1322
|
+
case SkyDynamicComponentLocation.ElementTop:
|
1323
|
+
if (!options.referenceEl) {
|
1324
|
+
throw new Error('[SkyDynamicComponentService] Could not create a component at location `SkyDynamicComponentLocation.ElementTop` because a reference element was not provided.');
|
1325
|
+
}
|
1326
|
+
this.#renderer.insertBefore(options.referenceEl, el, options.referenceEl.firstChild);
|
1327
|
+
break;
|
1328
|
+
case SkyDynamicComponentLocation.ElementBottom:
|
1329
|
+
this.#renderer.appendChild(options.referenceEl, el);
|
1330
|
+
break;
|
1331
|
+
case SkyDynamicComponentLocation.BodyTop:
|
1332
|
+
this.#renderer.insertBefore(bodyEl, el, bodyEl.firstChild);
|
1333
|
+
break;
|
1334
|
+
default:
|
1335
|
+
this.#renderer.appendChild(bodyEl, el);
|
1336
|
+
break;
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
return componentRef;
|
1340
|
+
}
|
1341
|
+
/**
|
1342
|
+
* Removes a component ref from the page
|
1343
|
+
* @param componentRef Component ref for the component being removed
|
1344
|
+
*/
|
1345
|
+
removeComponent(componentRef) {
|
1346
|
+
if (!componentRef) {
|
1347
|
+
return;
|
1348
|
+
}
|
1349
|
+
this.#applicationRef.detachView(componentRef.hostView);
|
1350
|
+
componentRef.destroy();
|
1351
|
+
}
|
1352
|
+
#getRootNode(componentRef) {
|
1353
|
+
// Technique for retrieving the component's root node taken from here:
|
1354
|
+
// https://malcoded.com/posts/angular-dynamic-components
|
1355
|
+
return componentRef.hostView.rootNodes[0];
|
1356
|
+
}
|
1357
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: SkyAppWindowRef }, { token: i0.RendererFactory2 }, { token: i0.EnvironmentInjector }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1358
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentService, providedIn: 'any' }); }
|
1359
|
+
}
|
1360
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentService, decorators: [{
|
1361
|
+
type: Injectable,
|
1362
|
+
args: [{
|
1363
|
+
// Must be 'any' so that the component is created in the context of its module's injector.
|
1364
|
+
// If set to 'root', the component's dependency injections would only be derived from the root
|
1365
|
+
// injector and may lose context if the component is created within a lazy-loaded module.
|
1366
|
+
providedIn: 'any',
|
1367
|
+
}]
|
1368
|
+
}], ctorParameters: function () { return [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: SkyAppWindowRef }, { type: i0.RendererFactory2 }, { type: i0.EnvironmentInjector }]; } });
|
1369
|
+
|
1370
|
+
/**
|
1371
|
+
* This service docks components to specific areas on the page.
|
1372
|
+
*/
|
1373
|
+
class SkyDockService {
|
1374
|
+
static { this._items = []; }
|
1375
|
+
/**
|
1376
|
+
* Returns all docked items.
|
1377
|
+
*/
|
1378
|
+
get items() {
|
1379
|
+
return SkyDockService._items;
|
1380
|
+
}
|
1381
|
+
#dynamicComponentSvc;
|
1382
|
+
#options;
|
1383
|
+
constructor(dynamicComponentSvc) {
|
1384
|
+
this.#dynamicComponentSvc = dynamicComponentSvc;
|
1385
|
+
}
|
1386
|
+
/**
|
1387
|
+
* Docks a component to the bottom of the page.
|
1388
|
+
* @param component The component to dock.
|
1389
|
+
* @param config Options that affect the docking action.
|
1390
|
+
*/
|
1391
|
+
insertComponent(component, config) {
|
1392
|
+
const dockRef = (SkyDockService.dockRef =
|
1393
|
+
SkyDockService.dockRef || this.#createDock());
|
1394
|
+
const itemRef = dockRef.instance.insertComponent(component, config);
|
1395
|
+
const item = new SkyDockItem(itemRef.componentRef.instance, itemRef.stackOrder);
|
1396
|
+
item.destroyed.subscribe(() => {
|
1397
|
+
dockRef.instance.removeItem(itemRef);
|
1398
|
+
SkyDockService._items.splice(SkyDockService._items.indexOf(item), 1);
|
1399
|
+
if (SkyDockService._items.length === 0) {
|
1400
|
+
this.#destroyDock();
|
1401
|
+
}
|
1402
|
+
});
|
1403
|
+
SkyDockService._items.push(item);
|
1404
|
+
SkyDockService._items.sort(sortByStackOrder);
|
1405
|
+
return item;
|
1406
|
+
}
|
1407
|
+
/**
|
1408
|
+
* Sets options for the positioning and styling of the dock component. Since the dock service is a
|
1409
|
+
* singleton instance, these options will be applied to all components inserted into the dock. In
|
1410
|
+
* order to create a separate dock with different options, consumers should provide a different
|
1411
|
+
* instance of the dock service.
|
1412
|
+
* @param options The options for positioning and styling
|
1413
|
+
*/
|
1414
|
+
setDockOptions(options) {
|
1415
|
+
this.#options = options;
|
1416
|
+
}
|
1417
|
+
#createDock() {
|
1418
|
+
let dockOptions;
|
1419
|
+
if (this.#options) {
|
1420
|
+
let dynamicLocation;
|
1421
|
+
switch (this.#options.location) {
|
1422
|
+
case SkyDockLocation.BeforeElement:
|
1423
|
+
dynamicLocation = SkyDynamicComponentLocation.BeforeElement;
|
1424
|
+
break;
|
1425
|
+
case SkyDockLocation.ElementBottom:
|
1426
|
+
dynamicLocation = SkyDynamicComponentLocation.ElementBottom;
|
1427
|
+
break;
|
1428
|
+
default:
|
1429
|
+
dynamicLocation = SkyDynamicComponentLocation.BodyTop;
|
1430
|
+
break;
|
1431
|
+
}
|
1432
|
+
dockOptions = {
|
1433
|
+
location: dynamicLocation,
|
1434
|
+
referenceEl: this.#options.referenceEl,
|
1435
|
+
};
|
1436
|
+
}
|
1437
|
+
const dockRef = this.#dynamicComponentSvc.createComponent(SkyDockComponent, dockOptions);
|
1438
|
+
dockRef.instance.setOptions(this.#options);
|
1439
|
+
return dockRef;
|
1440
|
+
}
|
1441
|
+
#destroyDock() {
|
1442
|
+
this.#dynamicComponentSvc.removeComponent(SkyDockService.dockRef);
|
1443
|
+
SkyDockService.dockRef = undefined;
|
1444
|
+
}
|
1445
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockService, deps: [{ token: SkyDynamicComponentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1446
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockService, providedIn: 'any' }); }
|
1447
|
+
}
|
1448
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDockService, decorators: [{
|
1449
|
+
type: Injectable,
|
1450
|
+
args: [{
|
1451
|
+
// Must be 'any' so that the dock component is created in the context of its module's injector.
|
1452
|
+
// If set to 'root', the component's dependency injections would only be derived from the root
|
1453
|
+
// injector and may loose context if the dock was opened from within a lazy-loaded module.
|
1454
|
+
providedIn: 'any',
|
1455
|
+
}]
|
1456
|
+
}], ctorParameters: function () { return [{ type: SkyDynamicComponentService }]; } });
|
1457
|
+
|
1458
|
+
/**
|
1459
|
+
* Provides services required to create dynamic components on the page.
|
1460
|
+
* @deprecated The `SkyDynamicComponentService` no longer needs the `SkyDynamicComponentModule`.
|
1461
|
+
* The `SkyDynamicComponentModule` can be removed from your project.
|
1462
|
+
*/
|
1463
|
+
class SkyDynamicComponentModule {
|
1464
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1465
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentModule }); }
|
1466
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentModule }); }
|
1467
|
+
}
|
1468
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyDynamicComponentModule, decorators: [{
|
1469
|
+
type: NgModule,
|
1470
|
+
args: [{}]
|
1471
|
+
}] });
|
1472
|
+
|
1473
|
+
class SkyAppFormat {
|
1474
|
+
formatText(format, ...args) {
|
1475
|
+
return String(format).replace(/\{(\d+)\}/g, function (match, capture) {
|
1476
|
+
return args[parseInt(capture, 10)];
|
1477
|
+
});
|
1478
|
+
}
|
1479
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppFormat, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1480
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppFormat, providedIn: 'root' }); }
|
1481
|
+
}
|
1482
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppFormat, decorators: [{
|
1483
|
+
type: Injectable,
|
1484
|
+
args: [{
|
1485
|
+
providedIn: 'root',
|
1486
|
+
}]
|
1487
|
+
}] });
|
1488
|
+
|
1489
|
+
let idIndex = 0;
|
1490
|
+
/**
|
1491
|
+
* Generates unique IDs to be used with HTML elements.
|
1492
|
+
*/
|
1493
|
+
class SkyIdService {
|
1494
|
+
generateId() {
|
1495
|
+
idIndex++;
|
1496
|
+
// Include timestamp and an incrementing index to guarantee unique IDs both during the application
|
1497
|
+
// lifecycle as well as across sessions, since browsers will try to apply autocomplete options to
|
1498
|
+
// elements with the same ID across sessions.
|
1499
|
+
return `sky-id-gen__${new Date().getTime()}__${idIndex}`;
|
1500
|
+
}
|
1501
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1502
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdService, providedIn: 'root' }); }
|
1503
|
+
}
|
1504
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdService, decorators: [{
|
1505
|
+
type: Injectable,
|
1506
|
+
args: [{
|
1507
|
+
providedIn: 'root',
|
1508
|
+
}]
|
1509
|
+
}] });
|
1510
|
+
|
1511
|
+
/**
|
1512
|
+
* Sets the element's `id` attribute to a unique ID. To reference this unique ID on other elements,
|
1513
|
+
* such as in a `label` element's `for` attribute, assign this directive to a template reference
|
1514
|
+
* variable, then use its `id` property.
|
1515
|
+
*/
|
1516
|
+
class SkyIdDirective {
|
1517
|
+
get id() {
|
1518
|
+
return this.#_id;
|
1519
|
+
}
|
1520
|
+
#_id;
|
1521
|
+
constructor(elRef, renderer, idSvc) {
|
1522
|
+
// Generate and apply the ID before the template is rendered
|
1523
|
+
// to avoid a changed-after-checked error.
|
1524
|
+
const id = idSvc.generateId();
|
1525
|
+
renderer.setAttribute(elRef.nativeElement, 'id', id);
|
1526
|
+
this.#_id = id;
|
1527
|
+
}
|
1528
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: SkyIdService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
1529
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: SkyIdDirective, selector: "[skyId]", exportAs: ["skyId"], ngImport: i0 }); }
|
1530
|
+
}
|
1531
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdDirective, decorators: [{
|
1532
|
+
type: Directive,
|
1533
|
+
args: [{
|
1534
|
+
selector: '[skyId]',
|
1535
|
+
exportAs: 'skyId',
|
1536
|
+
}]
|
1537
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: SkyIdService }]; } });
|
1538
|
+
|
1539
|
+
class SkyIdModule {
|
1540
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1541
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyIdModule, declarations: [SkyIdDirective], exports: [SkyIdDirective] }); }
|
1542
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdModule }); }
|
1543
|
+
}
|
1544
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyIdModule, decorators: [{
|
1545
|
+
type: NgModule,
|
1546
|
+
args: [{
|
1547
|
+
declarations: [SkyIdDirective],
|
1548
|
+
exports: [SkyIdDirective],
|
1549
|
+
}]
|
1550
|
+
}] });
|
1551
|
+
|
1552
|
+
/**
|
1553
|
+
* @internal
|
1554
|
+
*/
|
1555
|
+
class SkyLayoutHostService {
|
1556
|
+
get hostLayoutForChild() {
|
1557
|
+
return this.#hostLayoutForChildObs;
|
1558
|
+
}
|
1559
|
+
#hostLayoutForChild = new Subject();
|
1560
|
+
#hostLayoutForChildObs = this.#hostLayoutForChild.asObservable();
|
1561
|
+
setHostLayoutForChild(layout) {
|
1562
|
+
this.#hostLayoutForChild.next(layout);
|
1563
|
+
}
|
1564
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLayoutHostService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1565
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLayoutHostService }); }
|
1566
|
+
}
|
1567
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLayoutHostService, decorators: [{
|
1568
|
+
type: Injectable
|
1569
|
+
}] });
|
1570
|
+
|
1571
|
+
/**
|
1572
|
+
* Allows for announcing messages to screen reader users through the use of a common `aria-live` element.
|
1573
|
+
* @internal
|
1574
|
+
*/
|
1575
|
+
class SkyLiveAnnouncerService {
|
1576
|
+
#announcerElement;
|
1577
|
+
#document;
|
1578
|
+
#idService;
|
1579
|
+
constructor() {
|
1580
|
+
this.announcerElementChanged = new ReplaySubject(1);
|
1581
|
+
this.#document = inject(DOCUMENT);
|
1582
|
+
this.#idService = inject(SkyIdService);
|
1583
|
+
this.#announcerElement = this.#createLiveElement();
|
1584
|
+
this.announcerElementChanged.next(this.#announcerElement);
|
1585
|
+
}
|
1586
|
+
/**
|
1587
|
+
* Announces a message to screen readers.
|
1588
|
+
* @param message Message to be announced to the screen reader.
|
1589
|
+
* @param args Options for the announcement of the message.
|
1590
|
+
*/
|
1591
|
+
announce(message, args) {
|
1592
|
+
/* safety-check */
|
1593
|
+
/* istanbul ignore if */
|
1594
|
+
if (!this.#announcerElement) {
|
1595
|
+
this.#announcerElement = this.#createLiveElement();
|
1596
|
+
this.announcerElementChanged.next(this.#announcerElement);
|
1597
|
+
}
|
1598
|
+
const politeness = args?.politeness ?? 'polite';
|
1599
|
+
this.clear();
|
1600
|
+
this.#announcerElement.setAttribute('aria-live', politeness);
|
1601
|
+
this.#announcerElement.textContent = message;
|
1602
|
+
}
|
1603
|
+
/**
|
1604
|
+
* Clears the current text from the announcer element. Can be used to prevent
|
1605
|
+
* screen readers from reading the text out again while the user is going
|
1606
|
+
* through the page landmarks.
|
1607
|
+
*/
|
1608
|
+
clear() {
|
1609
|
+
if (this.#announcerElement) {
|
1610
|
+
this.#announcerElement.textContent = '';
|
1611
|
+
}
|
1612
|
+
}
|
1613
|
+
/**
|
1614
|
+
* @internal
|
1615
|
+
*/
|
1616
|
+
ngOnDestroy() {
|
1617
|
+
this.#announcerElement?.remove();
|
1618
|
+
this.#announcerElement = undefined;
|
1619
|
+
this.announcerElementChanged.next(undefined);
|
1620
|
+
}
|
1621
|
+
#createLiveElement() {
|
1622
|
+
const elementClass = 'sky-live-announcer-element';
|
1623
|
+
const previousElements = this.#document.getElementsByClassName(elementClass);
|
1624
|
+
const liveEl = this.#document.createElement('div');
|
1625
|
+
// Remove any old containers. This can happen when coming in from a server-side-rendered page.
|
1626
|
+
for (let i = 0; i < previousElements.length; i++) {
|
1627
|
+
previousElements[i].remove();
|
1628
|
+
}
|
1629
|
+
liveEl.classList.add(elementClass);
|
1630
|
+
liveEl.classList.add('sky-screen-reader-only');
|
1631
|
+
liveEl.setAttribute('aria-atomic', 'true');
|
1632
|
+
liveEl.setAttribute('aria-live', 'polite');
|
1633
|
+
liveEl.id = this.#idService.generateId();
|
1634
|
+
this.#document.body.appendChild(liveEl);
|
1635
|
+
return liveEl;
|
1636
|
+
}
|
1637
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLiveAnnouncerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1638
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLiveAnnouncerService, providedIn: 'root' }); }
|
1639
|
+
}
|
1640
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLiveAnnouncerService, decorators: [{
|
1641
|
+
type: Injectable,
|
1642
|
+
args: [{ providedIn: 'root' }]
|
1643
|
+
}], ctorParameters: function () { return []; } });
|
1644
|
+
|
1645
|
+
/**
|
1646
|
+
* @deprecated The `SkyLogService` no longer needs the `SkyLogModule`.
|
1647
|
+
* The `SkyLogModule` can be removed from your project.
|
1648
|
+
*/
|
1649
|
+
class SkyLogModule {
|
1650
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1651
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyLogModule }); }
|
1652
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogModule }); }
|
1653
|
+
}
|
1654
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogModule, decorators: [{
|
1655
|
+
type: NgModule,
|
1656
|
+
args: [{}]
|
1657
|
+
}] });
|
1658
|
+
|
1659
|
+
/**
|
1660
|
+
* @internal
|
1661
|
+
*/
|
1662
|
+
const SKY_LOG_LEVEL = new InjectionToken('SkyLogLevel');
|
1663
|
+
|
1664
|
+
const previousWarnings = new Set();
|
1665
|
+
/**
|
1666
|
+
* Logs information to the console based on the application's log level as
|
1667
|
+
* provided by the `SKY_LOG_LEVEL` injection token. If no token is provided,
|
1668
|
+
* only `error` logs will be shown.
|
1669
|
+
* @internal
|
1670
|
+
*/
|
1671
|
+
class SkyLogService {
|
1672
|
+
#applicationLogLevel;
|
1673
|
+
#formatter;
|
1674
|
+
constructor(formatter, applicationLogLevel) {
|
1675
|
+
this.#formatter = formatter;
|
1676
|
+
this.#applicationLogLevel = applicationLogLevel ?? 3 /* SkyLogLevel.Error */;
|
1677
|
+
}
|
1678
|
+
/**
|
1679
|
+
* Clears previously-logged messages. Primarily used for unit
|
1680
|
+
* testing this service.
|
1681
|
+
*/
|
1682
|
+
static clearPreviousLogs() {
|
1683
|
+
previousWarnings.clear();
|
1684
|
+
}
|
1685
|
+
/**
|
1686
|
+
* Logs a deprecation warning for a class, property, function, etc. This will
|
1687
|
+
* be logged as a console warning unless a different log level is given in the
|
1688
|
+
* `args` parameter.
|
1689
|
+
* @param name The name of the deprecated class, property, function, etc.
|
1690
|
+
* @param args Information about the deprecation and replacement recommendations.
|
1691
|
+
* @returns
|
1692
|
+
*/
|
1693
|
+
async deprecated(name, args) {
|
1694
|
+
const logLevel = args?.logLevel ?? 2 /* SkyLogLevel.Warn */;
|
1695
|
+
name = this.#convertStringToCode(name);
|
1696
|
+
if (this.#canLog(logLevel)) {
|
1697
|
+
const messageParts = [];
|
1698
|
+
if (args?.deprecationMajorVersion) {
|
1699
|
+
messageParts.push(this.#formatter.formatText('{0} is deprecated starting in SKY UX {1}.', name, args.deprecationMajorVersion.toLocaleString()));
|
1700
|
+
}
|
1701
|
+
else {
|
1702
|
+
messageParts.push(this.#formatter.formatText('{0} is deprecated.', name));
|
1703
|
+
}
|
1704
|
+
if (args?.removalMajorVersion) {
|
1705
|
+
messageParts.push(this.#formatter.formatText('We will remove it in version {0}.', args.removalMajorVersion.toLocaleString()));
|
1706
|
+
}
|
1707
|
+
else {
|
1708
|
+
messageParts.push('We will remove it in a future major version.');
|
1709
|
+
}
|
1710
|
+
if (args?.replacementRecommendation) {
|
1711
|
+
messageParts.push(args.replacementRecommendation);
|
1712
|
+
}
|
1713
|
+
if (args?.moreInfoUrl) {
|
1714
|
+
messageParts.push(this.#formatter.formatText('For more information, see {0}.', args.moreInfoUrl));
|
1715
|
+
}
|
1716
|
+
this.#logBasedOnLevel(logLevel, messageParts.join(' '));
|
1717
|
+
}
|
1718
|
+
return Promise.resolve();
|
1719
|
+
}
|
1720
|
+
/**
|
1721
|
+
* Logs a console error if the application's log level is `SkyLogLevel.Error`.
|
1722
|
+
* @param message The error message
|
1723
|
+
* @param params Optional parameters for the error message.
|
1724
|
+
*/
|
1725
|
+
error(message, params) {
|
1726
|
+
if (this.#canLog(3 /* SkyLogLevel.Error */)) {
|
1727
|
+
this.#logWithParams('error', message, params);
|
1728
|
+
}
|
1729
|
+
}
|
1730
|
+
/**
|
1731
|
+
* Logs console information if the application's log level is `SkyLogLevel.Info` or above.
|
1732
|
+
* @param message The informational message
|
1733
|
+
* @param params Optional parameters for the informational message.
|
1734
|
+
*/
|
1735
|
+
info(message, params) {
|
1736
|
+
if (this.#canLog(1 /* SkyLogLevel.Info */)) {
|
1737
|
+
this.#logWithParams('log', message, params);
|
1738
|
+
}
|
1739
|
+
}
|
1740
|
+
/**
|
1741
|
+
* Logs a console warning if the application's log level is `SkyLogLevel.Warn` or above.
|
1742
|
+
* @param message The warning message
|
1743
|
+
* @param params Optional parameters for the warning message.
|
1744
|
+
*/
|
1745
|
+
warn(message, params) {
|
1746
|
+
if (this.#canLog(2 /* SkyLogLevel.Warn */)) {
|
1747
|
+
const messageKey = this.#buildMessageKey(message, params);
|
1748
|
+
// Only log each warning once per application instance to avoid drowning out other
|
1749
|
+
// important messages in the console.
|
1750
|
+
if (!previousWarnings.has(message)) {
|
1751
|
+
this.#logWithParams('warn', message, params);
|
1752
|
+
previousWarnings.add(messageKey);
|
1753
|
+
}
|
1754
|
+
}
|
1755
|
+
}
|
1756
|
+
#convertStringToCode(typeString) {
|
1757
|
+
if (typeString.charAt(0) !== '`' && typeString.charAt(-1) !== '`') {
|
1758
|
+
typeString = '`' + typeString + '`';
|
1759
|
+
}
|
1760
|
+
return typeString;
|
1761
|
+
}
|
1762
|
+
#canLog(intendedLogLevel) {
|
1763
|
+
return intendedLogLevel >= this.#applicationLogLevel;
|
1764
|
+
}
|
1765
|
+
#logBasedOnLevel(logLevel, message, params) {
|
1766
|
+
switch (logLevel) {
|
1767
|
+
case 1 /* SkyLogLevel.Info */:
|
1768
|
+
this.info(message, params);
|
1769
|
+
break;
|
1770
|
+
case 2 /* SkyLogLevel.Warn */:
|
1771
|
+
this.warn(message, params);
|
1772
|
+
break;
|
1773
|
+
case 3 /* SkyLogLevel.Error */:
|
1774
|
+
this.error(message, params);
|
1775
|
+
break;
|
1776
|
+
}
|
1777
|
+
}
|
1778
|
+
#logWithParams(logMethod, message, params) {
|
1779
|
+
if (params) {
|
1780
|
+
console[logMethod](message, ...params);
|
1781
|
+
}
|
1782
|
+
else {
|
1783
|
+
console[logMethod](message);
|
1784
|
+
}
|
1785
|
+
}
|
1786
|
+
#buildMessageKey(message, params) {
|
1787
|
+
let key = message;
|
1788
|
+
if (params?.length) {
|
1789
|
+
key = `${key} ${params.join(' ')}`;
|
1790
|
+
}
|
1791
|
+
return key;
|
1792
|
+
}
|
1793
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogService, deps: [{ token: SkyAppFormat }, { token: SKY_LOG_LEVEL, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1794
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogService, providedIn: 'root' }); }
|
1795
|
+
}
|
1796
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyLogService, decorators: [{
|
1797
|
+
type: Injectable,
|
1798
|
+
args: [{
|
1799
|
+
providedIn: 'root',
|
1800
|
+
}]
|
1801
|
+
}], ctorParameters: function () { return [{ type: SkyAppFormat }, { type: undefined, decorators: [{
|
1802
|
+
type: Optional
|
1803
|
+
}, {
|
1804
|
+
type: Inject,
|
1805
|
+
args: [SKY_LOG_LEVEL]
|
1806
|
+
}] }]; } });
|
1807
|
+
|
1808
|
+
/**
|
1809
|
+
* @deprecated The `SkyMediaQueryService` no longer needs the `SkyMediaQueryModule`.
|
1810
|
+
* The `SkyMediaQueryModule` can be removed from your project.
|
1811
|
+
*/
|
1812
|
+
class SkyMediaQueryModule {
|
1813
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1814
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryModule }); }
|
1815
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryModule }); }
|
1816
|
+
}
|
1817
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryModule, decorators: [{
|
1818
|
+
type: NgModule,
|
1819
|
+
args: [{}]
|
1820
|
+
}] });
|
1821
|
+
|
1822
|
+
const DEFAULT_BREAKPOINT$1 = SkyMediaBreakpoints.md;
|
1823
|
+
class SkyMediaQueryService {
|
1824
|
+
/**
|
1825
|
+
* The size for the `xs` breakpoint.
|
1826
|
+
* @default "(max-width: 767px)"
|
1827
|
+
*/
|
1828
|
+
static { this.xs = '(max-width: 767px)'; }
|
1829
|
+
/**
|
1830
|
+
* The size for the `sm` breakpoint.
|
1831
|
+
* @default "(min-width: 768px) and (max-width: 991px)"
|
1832
|
+
*/
|
1833
|
+
static { this.sm = '(min-width: 768px) and (max-width: 991px)'; }
|
1834
|
+
/**
|
1835
|
+
* The size for the `md` breakpoint.
|
1836
|
+
* @default "(min-width: 992px) and (max-width: 1199px)"
|
1837
|
+
*/
|
1838
|
+
static { this.md = '(min-width: 992px) and (max-width: 1199px)'; }
|
1839
|
+
/**
|
1840
|
+
* The size for the `lg` breakpoint.
|
1841
|
+
* @default "(min-width: 1200px)"
|
1842
|
+
*/
|
1843
|
+
static { this.lg = '(min-width: 1200px)'; }
|
1844
|
+
/**
|
1845
|
+
* Returns the current breakpoint.
|
1846
|
+
*/
|
1847
|
+
get current() {
|
1848
|
+
return this.#currentBreakpoint;
|
1849
|
+
}
|
1850
|
+
#currentSubject = new BehaviorSubject(DEFAULT_BREAKPOINT$1);
|
1851
|
+
#currentBreakpoint = DEFAULT_BREAKPOINT$1;
|
1852
|
+
#breakpoints = [
|
1853
|
+
{
|
1854
|
+
mediaQueryString: SkyMediaQueryService.xs,
|
1855
|
+
name: SkyMediaBreakpoints.xs,
|
1856
|
+
},
|
1857
|
+
{
|
1858
|
+
mediaQueryString: SkyMediaQueryService.sm,
|
1859
|
+
name: SkyMediaBreakpoints.sm,
|
1860
|
+
},
|
1861
|
+
{
|
1862
|
+
mediaQueryString: SkyMediaQueryService.md,
|
1863
|
+
name: SkyMediaBreakpoints.md,
|
1864
|
+
},
|
1865
|
+
{
|
1866
|
+
mediaQueryString: SkyMediaQueryService.lg,
|
1867
|
+
name: SkyMediaBreakpoints.lg,
|
1868
|
+
},
|
1869
|
+
];
|
1870
|
+
#mediaQueries = [];
|
1871
|
+
#zone;
|
1872
|
+
constructor(zone) {
|
1873
|
+
this.#zone = zone;
|
1874
|
+
this.#addListeners();
|
1875
|
+
}
|
1876
|
+
ngOnDestroy() {
|
1877
|
+
this.#removeListeners();
|
1878
|
+
this.#currentSubject.complete();
|
1879
|
+
}
|
1880
|
+
/**
|
1881
|
+
* Subscribes to screen size changes.
|
1882
|
+
* @param listener Specifies a function that is called when breakpoints change.
|
1883
|
+
*/
|
1884
|
+
subscribe(listener) {
|
1885
|
+
return this.#currentSubject.subscribe({
|
1886
|
+
next: (breakpoints) => {
|
1887
|
+
listener(breakpoints);
|
1888
|
+
},
|
1889
|
+
});
|
1890
|
+
}
|
1891
|
+
/**
|
1892
|
+
* @internal
|
1893
|
+
*/
|
1894
|
+
destroy() {
|
1895
|
+
this.#removeListeners();
|
1896
|
+
this.#currentSubject.complete();
|
1897
|
+
}
|
1898
|
+
#addListeners() {
|
1899
|
+
this.#mediaQueries = this.#breakpoints.map((breakpoint) => {
|
1900
|
+
const mq = matchMedia(breakpoint.mediaQueryString);
|
1901
|
+
const listener = (event) => {
|
1902
|
+
// Run the check outside of Angular's change detection since Angular
|
1903
|
+
// does not wrap matchMedia listeners in NgZone.
|
1904
|
+
// See: https://blog.assaf.co/angular-2-change-detection-zones-and-an-example/
|
1905
|
+
this.#zone.run(() => {
|
1906
|
+
if (event.matches) {
|
1907
|
+
this.#notifyBreakpointChange(breakpoint.name);
|
1908
|
+
}
|
1909
|
+
});
|
1910
|
+
};
|
1911
|
+
mq.addListener(listener);
|
1912
|
+
if (mq.matches) {
|
1913
|
+
this.#notifyBreakpointChange(breakpoint.name);
|
1914
|
+
}
|
1915
|
+
return {
|
1916
|
+
mediaQueryList: mq,
|
1917
|
+
listener,
|
1918
|
+
};
|
1919
|
+
});
|
1920
|
+
}
|
1921
|
+
#removeListeners() {
|
1922
|
+
this.#mediaQueries.forEach((mediaQuery) => {
|
1923
|
+
mediaQuery.mediaQueryList.removeListener(mediaQuery.listener);
|
1924
|
+
});
|
1925
|
+
this.#mediaQueries = [];
|
1926
|
+
}
|
1927
|
+
#notifyBreakpointChange(breakpoint) {
|
1928
|
+
this.#currentBreakpoint = breakpoint;
|
1929
|
+
this.#currentSubject.next(breakpoint);
|
1930
|
+
}
|
1931
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
1932
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryService, providedIn: 'root' }); }
|
1933
|
+
}
|
1934
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyMediaQueryService, decorators: [{
|
1935
|
+
type: Injectable,
|
1936
|
+
args: [{
|
1937
|
+
providedIn: 'root',
|
1938
|
+
}]
|
1939
|
+
}], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
|
1940
|
+
|
1941
|
+
/**
|
1942
|
+
* NOTICE: DO NOT MODIFY THIS FILE!
|
1943
|
+
* The contents of this file were automatically generated by
|
1944
|
+
* the 'ng generate @skyux/i18n:lib-resources-module lib/modules/shared/sky-core' schematic.
|
1945
|
+
* To update this file, simply rerun the command.
|
1946
|
+
*/
|
1947
|
+
const RESOURCES = {
|
1948
|
+
'EN-US': {
|
1949
|
+
skyux_numeric_billions_symbol: { message: 'B' },
|
1950
|
+
skyux_numeric_millions_symbol: { message: 'M' },
|
1951
|
+
skyux_numeric_thousands_symbol: { message: 'K' },
|
1952
|
+
skyux_numeric_trillions_symbol: { message: 'T' },
|
1953
|
+
},
|
1954
|
+
};
|
1955
|
+
class SkyCoreResourcesProvider {
|
1956
|
+
getString(localeInfo, name) {
|
1957
|
+
return getLibStringForLocale(RESOURCES, localeInfo.locale, name);
|
1958
|
+
}
|
1959
|
+
}
|
1960
|
+
/**
|
1961
|
+
* Import into any component library module that needs to use resource strings.
|
1962
|
+
*/
|
1963
|
+
class SkyCoreResourcesModule {
|
1964
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreResourcesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
1965
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreResourcesModule, exports: [SkyI18nModule] }); }
|
1966
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreResourcesModule, providers: [
|
1967
|
+
{
|
1968
|
+
provide: SKY_LIB_RESOURCES_PROVIDERS,
|
1969
|
+
useClass: SkyCoreResourcesProvider,
|
1970
|
+
multi: true,
|
1971
|
+
},
|
1972
|
+
], imports: [SkyI18nModule] }); }
|
1973
|
+
}
|
1974
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyCoreResourcesModule, decorators: [{
|
1975
|
+
type: NgModule,
|
1976
|
+
args: [{
|
1977
|
+
exports: [SkyI18nModule],
|
1978
|
+
providers: [
|
1979
|
+
{
|
1980
|
+
provide: SKY_LIB_RESOURCES_PROVIDERS,
|
1981
|
+
useClass: SkyCoreResourcesProvider,
|
1982
|
+
multi: true,
|
1983
|
+
},
|
1984
|
+
],
|
1985
|
+
}]
|
1986
|
+
}] });
|
1987
|
+
|
1988
|
+
/**
|
1989
|
+
* Provides arguments for the number to format.
|
1990
|
+
* @deprecated Use the `SkyNumericOptions` interface instead.
|
1991
|
+
* @internal
|
1992
|
+
*/
|
1993
|
+
class NumericOptions {
|
1994
|
+
constructor() {
|
1995
|
+
this.digits = 1;
|
1996
|
+
this.format = 'number';
|
1997
|
+
this.currencySign = 'standard';
|
1998
|
+
this.iso = 'USD';
|
1999
|
+
this.truncate = true;
|
2000
|
+
this.truncateAfter = 1000;
|
2001
|
+
const logService = new SkyLogService(new SkyAppFormat());
|
2002
|
+
logService
|
2003
|
+
.deprecated('NumericOptions', {
|
2004
|
+
deprecationMajorVersion: 7,
|
2005
|
+
moreInfoUrl: 'https://developer.blackbaud.com/skyux/components/numeric',
|
2006
|
+
replacementRecommendation: 'Use the `SkyNumericOptions` interface instead.',
|
2007
|
+
})
|
2008
|
+
.then();
|
2009
|
+
}
|
2010
|
+
}
|
2011
|
+
|
2012
|
+
/* eslint-disable eqeqeq */
|
2013
|
+
// This file is mostly ported from the Angular 4.x NumberPipe in order to maintain the old
|
2014
|
+
// behavior of using the `Intl` API for formatting numbers rather than having to register every
|
2015
|
+
// supported locale.
|
2016
|
+
// https://github.com/angular/angular/blob/4.4.x/packages/common/src/pipes/number_pipe.ts
|
2017
|
+
function isNumeric(value) {
|
2018
|
+
return !isNaN(value - parseFloat(value));
|
2019
|
+
}
|
2020
|
+
function parseIntAutoRadix(text) {
|
2021
|
+
const result = parseInt(text, 10);
|
2022
|
+
/* istanbul ignore next */
|
2023
|
+
if (isNaN(result)) {
|
2024
|
+
throw new Error('Invalid integer literal when parsing ' + text);
|
2025
|
+
}
|
2026
|
+
return result;
|
2027
|
+
}
|
2028
|
+
// Need to add the following to classes which contain static methods.
|
2029
|
+
// See: https://github.com/ng-packagr/ng-packagr/issues/641
|
2030
|
+
// @dynamic
|
2031
|
+
class SkyNumberFormatUtility {
|
2032
|
+
static { this._NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/; }
|
2033
|
+
static formatNumber(locale, value, style, digits, currency = null, currencyAsSymbol = false, currencySign) {
|
2034
|
+
if (value == null) {
|
2035
|
+
return null;
|
2036
|
+
}
|
2037
|
+
// Convert strings to numbers
|
2038
|
+
value = typeof value === 'string' && isNumeric(value) ? +value : value;
|
2039
|
+
if (typeof value !== 'number') {
|
2040
|
+
throw Error(`SkyInvalidPipeArgument: '${value}'`);
|
2041
|
+
}
|
2042
|
+
let minInt = undefined;
|
2043
|
+
let minFraction = undefined;
|
2044
|
+
let maxFraction = undefined;
|
2045
|
+
if (style !== SkyIntlNumberFormatStyle.Currency) {
|
2046
|
+
// rely on Intl default for currency
|
2047
|
+
minInt = 1;
|
2048
|
+
minFraction = 0;
|
2049
|
+
maxFraction = 3;
|
2050
|
+
}
|
2051
|
+
if (digits) {
|
2052
|
+
const parts = digits.match(this._NUMBER_FORMAT_REGEXP);
|
2053
|
+
if (parts === null) {
|
2054
|
+
throw new Error(`${digits} is not a valid digit info for number pipes`);
|
2055
|
+
}
|
2056
|
+
/* istanbul ignore else */
|
2057
|
+
if (parts[1] != null) {
|
2058
|
+
// min integer digits
|
2059
|
+
minInt = parseIntAutoRadix(parts[1]);
|
2060
|
+
}
|
2061
|
+
/* istanbul ignore else */
|
2062
|
+
if (parts[3] != null) {
|
2063
|
+
// min fraction digits
|
2064
|
+
minFraction = parseIntAutoRadix(parts[3]);
|
2065
|
+
}
|
2066
|
+
/* istanbul ignore else */
|
2067
|
+
if (parts[5] != null) {
|
2068
|
+
// max fraction digits
|
2069
|
+
maxFraction = parseIntAutoRadix(parts[5]);
|
2070
|
+
}
|
2071
|
+
}
|
2072
|
+
return SkyIntlNumberFormatter.format(value, locale, style, {
|
2073
|
+
minimumIntegerDigits: minInt,
|
2074
|
+
minimumFractionDigits: minFraction,
|
2075
|
+
maximumFractionDigits: maxFraction,
|
2076
|
+
currency: currency,
|
2077
|
+
currencyAsSymbol: currencyAsSymbol,
|
2078
|
+
currencySign: currencySign,
|
2079
|
+
});
|
2080
|
+
}
|
2081
|
+
}
|
2082
|
+
|
2083
|
+
class SkyNumericService {
|
2084
|
+
#resourcesSvc;
|
2085
|
+
#symbolIndex;
|
2086
|
+
constructor(resourcesSvc) {
|
2087
|
+
/**
|
2088
|
+
* The browser's current locale.
|
2089
|
+
* @internal
|
2090
|
+
*/
|
2091
|
+
this.currentLocale = 'en-US';
|
2092
|
+
/**
|
2093
|
+
* @internal
|
2094
|
+
*/
|
2095
|
+
this.shortSymbol = '';
|
2096
|
+
this.#resourcesSvc = resourcesSvc;
|
2097
|
+
this.#symbolIndex = [
|
2098
|
+
{ value: 1e12, label: this.#getSymbol('skyux_numeric_trillions_symbol') },
|
2099
|
+
{ value: 1e9, label: this.#getSymbol('skyux_numeric_billions_symbol') },
|
2100
|
+
{ value: 1e6, label: this.#getSymbol('skyux_numeric_millions_symbol') },
|
2101
|
+
{ value: 1e3, label: this.#getSymbol('skyux_numeric_thousands_symbol') },
|
2102
|
+
];
|
2103
|
+
}
|
2104
|
+
/**
|
2105
|
+
* Formats a number based on the provided options.
|
2106
|
+
* @param value The number to format.
|
2107
|
+
* @param options Format options.
|
2108
|
+
*/
|
2109
|
+
formatNumber(value, options) {
|
2110
|
+
if (isNaN(value) || value === null) {
|
2111
|
+
return '';
|
2112
|
+
}
|
2113
|
+
const numericOptions = {
|
2114
|
+
digits: 0,
|
2115
|
+
format: 'number',
|
2116
|
+
currencySign: 'standard',
|
2117
|
+
iso: 'USD',
|
2118
|
+
truncateAfter: 1000,
|
2119
|
+
...options,
|
2120
|
+
};
|
2121
|
+
const decimalPlaceRegExp = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
2122
|
+
const locale = numericOptions.locale || this.currentLocale;
|
2123
|
+
const digits = numericOptions.digits || 0;
|
2124
|
+
// Get the symbol for the number after rounding, since rounding could push the number
|
2125
|
+
// into a different symbol range.
|
2126
|
+
let roundedNumber = this.#roundNumber(value, digits);
|
2127
|
+
const roundedNumberAbs = Math.abs(roundedNumber);
|
2128
|
+
let suffix = '';
|
2129
|
+
for (let i = 0; i < this.#symbolIndex.length; i++) {
|
2130
|
+
let symbol = this.#symbolIndex[i];
|
2131
|
+
if (numericOptions.truncate &&
|
2132
|
+
numericOptions.truncateAfter !== undefined &&
|
2133
|
+
roundedNumberAbs >= numericOptions.truncateAfter &&
|
2134
|
+
roundedNumberAbs >= symbol.value) {
|
2135
|
+
roundedNumber = this.#roundNumber(value / symbol.value, digits);
|
2136
|
+
if (Math.abs(roundedNumber) === 1000 && i > 0) {
|
2137
|
+
// Rounding caused the number to cross into the range of the next symbol.
|
2138
|
+
symbol = this.#symbolIndex[i - 1];
|
2139
|
+
roundedNumber /= 1000;
|
2140
|
+
}
|
2141
|
+
suffix = symbol.label;
|
2142
|
+
break;
|
2143
|
+
}
|
2144
|
+
}
|
2145
|
+
let output = roundedNumber.toString().replace(decimalPlaceRegExp, '$1') + suffix;
|
2146
|
+
this.#storeShortenSymbol(output);
|
2147
|
+
let digitsFormatted;
|
2148
|
+
let isDecimal = false;
|
2149
|
+
// Checks the string entered for format. Using toLowerCase to ignore case.
|
2150
|
+
switch (numericOptions.format?.toLowerCase()) {
|
2151
|
+
// In a case where a decimal value was not shortened and
|
2152
|
+
// the digit input is 2 or higher, it forces 2 digits.
|
2153
|
+
// For example, this prevents a value like $15.50 from displaying as $15.5.
|
2154
|
+
// Note: This will need to be reviewed if we support currencies with
|
2155
|
+
// three decimal digits.
|
2156
|
+
case 'currency':
|
2157
|
+
isDecimal = value % 1 !== 0;
|
2158
|
+
if (numericOptions.minDigits) {
|
2159
|
+
digitsFormatted = `1.${numericOptions.minDigits}-${digits}`;
|
2160
|
+
}
|
2161
|
+
else if (isDecimal && digits >= 2) {
|
2162
|
+
digitsFormatted = `1.2-${digits}`;
|
2163
|
+
}
|
2164
|
+
else {
|
2165
|
+
digitsFormatted = `1.0-${digits}`;
|
2166
|
+
}
|
2167
|
+
output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digitsFormatted, numericOptions.iso,
|
2168
|
+
// Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.
|
2169
|
+
// To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4
|
2170
|
+
// and the appropriate string value for Angular 5+.
|
2171
|
+
// See: https://angular.io/api/common/CurrencyPipe#parameters
|
2172
|
+
'symbol', numericOptions.currencySign);
|
2173
|
+
// ^^^^^^ Result can't be null since the sanitized input is always a number.
|
2174
|
+
break;
|
2175
|
+
// The following is a catch-all to ensure that if
|
2176
|
+
// anything but currency (or a future option) are entered,
|
2177
|
+
// it will be treated like a number.
|
2178
|
+
default:
|
2179
|
+
// Ensures localization of the number to ensure comma and
|
2180
|
+
// decimal separator
|
2181
|
+
if (numericOptions.minDigits) {
|
2182
|
+
digitsFormatted = `1.${numericOptions.minDigits}-${digits}`;
|
2183
|
+
}
|
2184
|
+
else if (numericOptions.truncate) {
|
2185
|
+
digitsFormatted = `1.0-${digits}`;
|
2186
|
+
}
|
2187
|
+
else {
|
2188
|
+
digitsFormatted = `1.${digits}-${digits}`;
|
2189
|
+
}
|
2190
|
+
output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Decimal, digitsFormatted);
|
2191
|
+
// ^^^^^^ Result can't be null since the sanitized input is always a number.
|
2192
|
+
break;
|
2193
|
+
}
|
2194
|
+
if (numericOptions.truncate) {
|
2195
|
+
output = this.#replaceShortenSymbol(output);
|
2196
|
+
}
|
2197
|
+
return output;
|
2198
|
+
}
|
2199
|
+
/**
|
2200
|
+
* Rounds a given number
|
2201
|
+
*
|
2202
|
+
* JS's limitation - numbers bigger than Number.MIN_SAFE_INTEGER or Number.MAX_SAFE_INTEGER
|
2203
|
+
* are not guaranteed to be represented or rounded correctly
|
2204
|
+
* @param value - value to round
|
2205
|
+
* @param precision - what precision to round with, defaults to 0 decimal places
|
2206
|
+
*/
|
2207
|
+
#roundNumber(value, precision) {
|
2208
|
+
if (precision < 0) {
|
2209
|
+
throw new Error('SkyInvalidArgument: precision must be >= 0');
|
2210
|
+
}
|
2211
|
+
/* Sanity check - ignoring coverage but should not ignore if we make this method public */
|
2212
|
+
/* istanbul ignore next */
|
2213
|
+
if (isNaN(value) || value === null) {
|
2214
|
+
return 0;
|
2215
|
+
}
|
2216
|
+
const scaledValue = this.#scaleNumberByPowerOfTen(value, precision, true);
|
2217
|
+
const scaledRoundedValue = Math.round(scaledValue);
|
2218
|
+
const unscaledRoundedValue = this.#scaleNumberByPowerOfTen(scaledRoundedValue, precision, false);
|
2219
|
+
return unscaledRoundedValue;
|
2220
|
+
}
|
2221
|
+
/**
|
2222
|
+
* Scales a given number by a power of 10
|
2223
|
+
* @param value - value to scale
|
2224
|
+
* @param scalar - 10^scalar
|
2225
|
+
* @param scaleUp - whether to increase or decrease the value
|
2226
|
+
*/
|
2227
|
+
#scaleNumberByPowerOfTen(value, scalar, scaleUp) {
|
2228
|
+
const valueStr = value.toString().toLowerCase();
|
2229
|
+
const isExponentFormat = valueStr.includes('e');
|
2230
|
+
if (isExponentFormat) {
|
2231
|
+
const [base, exp] = valueStr.split('e');
|
2232
|
+
const newExp = scaleUp ? Number(exp) + scalar : Number(exp) - scalar;
|
2233
|
+
return Number(`${base}e${newExp}`);
|
2234
|
+
}
|
2235
|
+
else {
|
2236
|
+
const e = scaleUp ? 'e' : 'e-';
|
2237
|
+
return Number(`${value}${e}${scalar}`);
|
2238
|
+
}
|
2239
|
+
}
|
2240
|
+
/**
|
2241
|
+
* Stores the symbol added from shortening to reapply later.
|
2242
|
+
* @param value The string to derive the shorten symbol from.
|
2243
|
+
*/
|
2244
|
+
#storeShortenSymbol(value) {
|
2245
|
+
const symbols = this.#symbolIndex.map((s) => s.label);
|
2246
|
+
const regexp = new RegExp(symbols.join('|'), 'ig');
|
2247
|
+
const match = value.match(regexp);
|
2248
|
+
this.shortSymbol = match ? match.toString() : '';
|
2249
|
+
}
|
2250
|
+
/**
|
2251
|
+
* Must have previously called storeShortenSymbol to have something to replace.
|
2252
|
+
* Finds the last number in the formatted number, gets the index of the position
|
2253
|
+
* after that character and re-inserts the symbol.
|
2254
|
+
* Works regardless of currency symbol position.
|
2255
|
+
* @param value The string to modify.
|
2256
|
+
*/
|
2257
|
+
#replaceShortenSymbol(value) {
|
2258
|
+
const result = /(\d)(?!.*\d)/g.exec(value);
|
2259
|
+
/*istanbul ignore else*/
|
2260
|
+
if (result) {
|
2261
|
+
const pos = result.index + result.length;
|
2262
|
+
const output = value.substring(0, pos) + this.shortSymbol + value.substring(pos);
|
2263
|
+
return output;
|
2264
|
+
}
|
2265
|
+
else {
|
2266
|
+
return value;
|
2267
|
+
}
|
2268
|
+
}
|
2269
|
+
#getSymbol(key) {
|
2270
|
+
// TODO: Need to implement the async `getString` method in a breaking change.
|
2271
|
+
return this.#resourcesSvc.getStringForLocale({ locale: 'en_US' }, key);
|
2272
|
+
}
|
2273
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericService, deps: [{ token: i1.SkyLibResourcesService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
2274
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericService, providedIn: 'any' }); }
|
2275
|
+
}
|
2276
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericService, decorators: [{
|
2277
|
+
type: Injectable,
|
2278
|
+
args: [{
|
2279
|
+
providedIn: 'any',
|
2280
|
+
}]
|
2281
|
+
}], ctorParameters: function () { return [{ type: i1.SkyLibResourcesService }]; } });
|
2282
|
+
|
2283
|
+
/**
|
2284
|
+
* Shortens numbers to rounded numbers and abbreviation characters such as K for thousands,
|
2285
|
+
* M for millions, B for billions, and T for trillions. The pipe also formats for currency.
|
2286
|
+
* Be sure you have a space after the two curly brackets opening the pipe and
|
2287
|
+
* a space before the two curly brackets closing the pipe or it will not work.
|
2288
|
+
*/
|
2289
|
+
class SkyNumericPipe {
|
2290
|
+
#cacheKey;
|
2291
|
+
#changeDetector;
|
2292
|
+
#formattedValue;
|
2293
|
+
#ngUnsubscribe = new Subject();
|
2294
|
+
#numericSvc;
|
2295
|
+
#providerLocale;
|
2296
|
+
constructor(localeProvider, numericSvc, changeDetector) {
|
2297
|
+
this.#numericSvc = numericSvc;
|
2298
|
+
this.#changeDetector = changeDetector;
|
2299
|
+
localeProvider
|
2300
|
+
.getLocaleInfo()
|
2301
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
2302
|
+
.subscribe((localeInfo) => {
|
2303
|
+
this.#providerLocale = localeInfo.locale;
|
2304
|
+
numericSvc.currentLocale = this.#providerLocale;
|
2305
|
+
this.#changeDetector.markForCheck();
|
2306
|
+
});
|
2307
|
+
}
|
2308
|
+
ngOnDestroy() {
|
2309
|
+
this.#ngUnsubscribe.next();
|
2310
|
+
this.#ngUnsubscribe.complete();
|
2311
|
+
}
|
2312
|
+
/**
|
2313
|
+
* Formats a number based on the provided options.
|
2314
|
+
*/
|
2315
|
+
transform(value, config) {
|
2316
|
+
const newCacheKey = (config ? JSON.stringify(config, Object.keys(config).sort()) : '') +
|
2317
|
+
`${value}_${config?.locale || this.#providerLocale}`;
|
2318
|
+
/* If the value and locale are the same as the last transform then return the previous value
|
2319
|
+
instead of reformatting. */
|
2320
|
+
if (this.#formattedValue && this.#cacheKey === newCacheKey) {
|
2321
|
+
return this.#formattedValue;
|
2322
|
+
}
|
2323
|
+
const options = new NumericOptions();
|
2324
|
+
// The default number of digits is `1`. When truncate is disabled, set digits
|
2325
|
+
// to `0` to avoid the unnecessary addition of `.0` at the end of the formatted number.
|
2326
|
+
if (config && config.truncate === false && config.digits === undefined) {
|
2327
|
+
options.digits = 0;
|
2328
|
+
}
|
2329
|
+
// If the minimum digits is less than the set maximum digits then throw an error
|
2330
|
+
if (config &&
|
2331
|
+
config.minDigits &&
|
2332
|
+
config.digits &&
|
2333
|
+
config.minDigits > config.digits) {
|
2334
|
+
throw new Error('The `digits` property must be greater than or equal to the `minDigits` property');
|
2335
|
+
// If there is a minimum digits given but not a maximum then default the maximum to the minimum
|
2336
|
+
}
|
2337
|
+
else if (config && config.minDigits && !config.digits) {
|
2338
|
+
options.digits = config.minDigits;
|
2339
|
+
}
|
2340
|
+
Object.assign(options, config);
|
2341
|
+
// Assign properties for proper result caching.
|
2342
|
+
this.#cacheKey = newCacheKey;
|
2343
|
+
this.#formattedValue = this.#numericSvc.formatNumber(value, options);
|
2344
|
+
return this.#formattedValue;
|
2345
|
+
}
|
2346
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericPipe, deps: [{ token: i1.SkyAppLocaleProvider }, { token: SkyNumericService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
2347
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericPipe, name: "skyNumeric", pure: false }); }
|
2348
|
+
}
|
2349
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericPipe, decorators: [{
|
2350
|
+
type: Pipe,
|
2351
|
+
args: [{
|
2352
|
+
name: 'skyNumeric',
|
2353
|
+
pure: false,
|
2354
|
+
}]
|
2355
|
+
}], ctorParameters: function () { return [{ type: i1.SkyAppLocaleProvider }, { type: SkyNumericService }, { type: i0.ChangeDetectorRef }]; } });
|
2356
|
+
|
2357
|
+
class SkyNumericModule {
|
2358
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
2359
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericModule, declarations: [SkyNumericPipe], imports: [SkyI18nModule, SkyCoreResourcesModule], exports: [SkyNumericPipe] }); }
|
2360
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericModule, providers: [SkyNumericPipe], imports: [SkyI18nModule, SkyCoreResourcesModule] }); }
|
2361
|
+
}
|
2362
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyNumericModule, decorators: [{
|
2363
|
+
type: NgModule,
|
2364
|
+
args: [{
|
2365
|
+
declarations: [SkyNumericPipe],
|
2366
|
+
providers: [SkyNumericPipe],
|
2367
|
+
imports: [SkyI18nModule, SkyCoreResourcesModule],
|
2368
|
+
exports: [SkyNumericPipe],
|
2369
|
+
}]
|
2370
|
+
}] });
|
2371
|
+
|
2372
|
+
/**
|
2373
|
+
* Represents a new overlay instance. It is used to manage the "closed" state of the overlay,
|
2374
|
+
* and access any public members on the appended content component instance.
|
2375
|
+
*/
|
2376
|
+
class SkyOverlayInstance {
|
2377
|
+
/**
|
2378
|
+
* Emits when the overlay is clicked (but not its content).
|
2379
|
+
*/
|
2380
|
+
get backdropClick() {
|
2381
|
+
return this.#backdropClickObs;
|
2382
|
+
}
|
2383
|
+
/**
|
2384
|
+
* Emits after the overlay is closed.
|
2385
|
+
*/
|
2386
|
+
get closed() {
|
2387
|
+
return this.#closedObs;
|
2388
|
+
}
|
2389
|
+
#backdropClick;
|
2390
|
+
#backdropClickObs;
|
2391
|
+
#closed;
|
2392
|
+
#closedObs;
|
2393
|
+
constructor(
|
2394
|
+
/**
|
2395
|
+
* The configuration for the overlay.
|
2396
|
+
*/
|
2397
|
+
config, componentRef) {
|
2398
|
+
this.config = config;
|
2399
|
+
this.componentRef = componentRef;
|
2400
|
+
this.id = this.componentRef.instance.id;
|
2401
|
+
this.componentRef.instance.closed.subscribe(() => {
|
2402
|
+
this.#closed.next();
|
2403
|
+
this.#closed.complete();
|
2404
|
+
this.#backdropClick.complete();
|
2405
|
+
});
|
2406
|
+
this.componentRef.instance.backdropClick.subscribe(() => {
|
2407
|
+
this.#backdropClick.next();
|
2408
|
+
});
|
2409
|
+
this.#backdropClick = new Subject();
|
2410
|
+
this.#closed = new Subject();
|
2411
|
+
this.#backdropClickObs = this.#backdropClick.asObservable();
|
2412
|
+
this.#closedObs = this.#closed.asObservable();
|
2413
|
+
}
|
2414
|
+
/**
|
2415
|
+
* Creates and attaches a component to the overlay.
|
2416
|
+
* @param component The component to attach.
|
2417
|
+
* @param providers Custom providers to apply to the component.
|
2418
|
+
*/
|
2419
|
+
attachComponent(component, providers) {
|
2420
|
+
const componentRef = this.componentRef.instance.attachComponent(component, providers);
|
2421
|
+
return componentRef.instance;
|
2422
|
+
}
|
2423
|
+
/**
|
2424
|
+
* Attaches a `TemplateRef` to the overlay.
|
2425
|
+
* @param templateRef The `TemplateRef` to attach.
|
2426
|
+
* @param context The context to provide to the template.
|
2427
|
+
*/
|
2428
|
+
attachTemplate(templateRef, context) {
|
2429
|
+
this.componentRef.instance.attachTemplate(templateRef, context);
|
2430
|
+
}
|
2431
|
+
}
|
2432
|
+
|
2433
|
+
/**
|
2434
|
+
* @internal
|
2435
|
+
*/
|
2436
|
+
const SKY_STACKING_CONTEXT = new InjectionToken('SkyStackingContext');
|
2437
|
+
|
2438
|
+
/**
|
2439
|
+
* Contextual information for each overlay.
|
2440
|
+
* @internal
|
2441
|
+
*/
|
2442
|
+
class SkyOverlayContext {
|
2443
|
+
constructor(config) {
|
2444
|
+
this.config = config;
|
2445
|
+
}
|
2446
|
+
}
|
2447
|
+
|
2448
|
+
const POSITION_DEFAULT = 'fixed';
|
2449
|
+
/**
|
2450
|
+
* Omnibar is 1000.
|
2451
|
+
* See: https://github.com/blackbaud/auth-client/blob/master/src/omnibar/omnibar.ts#L139
|
2452
|
+
* ---
|
2453
|
+
* Modals start their z-indexes at 1040. However, each modal's z-index is a multiple of 10, so it
|
2454
|
+
* will be difficult to reliably predict a z-index that will always appear above all other
|
2455
|
+
* layers. Starting the z-index for overlays at a number much greater than modals will accommodate
|
2456
|
+
* the most reasonable of scenarios.
|
2457
|
+
* See: https://github.com/blackbaud/skyux-modals/blob/master/src/app/public/modules/modal/modal-host.service.ts#L22
|
2458
|
+
* (NOTE: It should be noted that modals do not use the overlay service, which is something we
|
2459
|
+
* should do in the near future to make sure z-indexes are predictable across all component
|
2460
|
+
* libraries.)
|
2461
|
+
*/
|
2462
|
+
let uniqueZIndex = 5000;
|
2463
|
+
/**
|
2464
|
+
* @internal
|
2465
|
+
*/
|
2466
|
+
class SkyOverlayComponent {
|
2467
|
+
get backdropClick() {
|
2468
|
+
return this.#backdropClickObs;
|
2469
|
+
}
|
2470
|
+
get closed() {
|
2471
|
+
return this.#closedObs;
|
2472
|
+
}
|
2473
|
+
#backdropClick;
|
2474
|
+
#backdropClickObs;
|
2475
|
+
#changeDetector;
|
2476
|
+
#closed;
|
2477
|
+
#closedObs;
|
2478
|
+
#context;
|
2479
|
+
#coreAdapter;
|
2480
|
+
#injector;
|
2481
|
+
#ngUnsubscribe;
|
2482
|
+
#router;
|
2483
|
+
#routerSubscription;
|
2484
|
+
constructor(changeDetector, injector, coreAdapter, context, idSvc, router) {
|
2485
|
+
this.wrapperClass = '';
|
2486
|
+
this.enablePointerEvents = false;
|
2487
|
+
this.showBackdrop = false;
|
2488
|
+
this.zIndex = `${++uniqueZIndex}`;
|
2489
|
+
this.clipPath$ = new ReplaySubject(1);
|
2490
|
+
this.position = POSITION_DEFAULT;
|
2491
|
+
this.#ngUnsubscribe = new Subject();
|
2492
|
+
this.#changeDetector = changeDetector;
|
2493
|
+
this.#injector = injector;
|
2494
|
+
this.#coreAdapter = coreAdapter;
|
2495
|
+
this.#context = context;
|
2496
|
+
this.#router = router;
|
2497
|
+
this.id = idSvc.generateId();
|
2498
|
+
this.#backdropClick = new Subject();
|
2499
|
+
this.#closed = new Subject();
|
2500
|
+
this.#backdropClickObs = this.#backdropClick.asObservable();
|
2501
|
+
this.#closedObs = this.#closed.asObservable();
|
2502
|
+
}
|
2503
|
+
ngOnInit() {
|
2504
|
+
this.#applyConfig(this.#context.config);
|
2505
|
+
setTimeout(() => {
|
2506
|
+
this.#addBackdropClickListener();
|
2507
|
+
});
|
2508
|
+
if (this.#context.config.closeOnNavigation) {
|
2509
|
+
this.#addRouteListener();
|
2510
|
+
}
|
2511
|
+
}
|
2512
|
+
ngOnDestroy() {
|
2513
|
+
this.#removeRouteListener();
|
2514
|
+
this.#ngUnsubscribe.next();
|
2515
|
+
this.#ngUnsubscribe.complete();
|
2516
|
+
this.#backdropClick.complete();
|
2517
|
+
this.#closed.next();
|
2518
|
+
this.#closed.complete();
|
2519
|
+
}
|
2520
|
+
attachComponent(component, providers = []) {
|
2521
|
+
/*istanbul ignore if: untestable*/
|
2522
|
+
if (!this.targetRef) {
|
2523
|
+
throw new Error('[SkyOverlayComponent] Could not attach the component because the target element could not be found.');
|
2524
|
+
}
|
2525
|
+
this.targetRef.clear();
|
2526
|
+
const injector = Injector.create({
|
2527
|
+
providers: [
|
2528
|
+
{
|
2529
|
+
provide: SKY_STACKING_CONTEXT,
|
2530
|
+
useValue: {
|
2531
|
+
zIndex: new BehaviorSubject(parseInt(this.zIndex, 10))
|
2532
|
+
.asObservable()
|
2533
|
+
.pipe(takeUntil(this.#ngUnsubscribe)),
|
2534
|
+
},
|
2535
|
+
},
|
2536
|
+
...providers,
|
2537
|
+
],
|
2538
|
+
parent: this.#injector,
|
2539
|
+
});
|
2540
|
+
const componentRef = this.targetRef.createComponent(component, {
|
2541
|
+
injector,
|
2542
|
+
});
|
2543
|
+
// Run an initial change detection cycle after the component has been created.
|
2544
|
+
componentRef.changeDetectorRef.detectChanges();
|
2545
|
+
return componentRef;
|
2546
|
+
}
|
2547
|
+
attachTemplate(templateRef, context) {
|
2548
|
+
/*istanbul ignore if: untestable*/
|
2549
|
+
if (!this.targetRef) {
|
2550
|
+
throw new Error('[SkyOverlayComponent] Could not attach the template because the target element could not be found.');
|
2551
|
+
}
|
2552
|
+
this.targetRef.clear();
|
2553
|
+
return this.targetRef.createEmbeddedView(templateRef, context);
|
2554
|
+
}
|
2555
|
+
updateClipPath(clipPath) {
|
2556
|
+
this.clipPath$.next(clipPath);
|
2557
|
+
}
|
2558
|
+
#applyConfig(config) {
|
2559
|
+
this.wrapperClass = config.wrapperClass || '';
|
2560
|
+
this.showBackdrop = !!config.showBackdrop;
|
2561
|
+
this.enablePointerEvents = !!config.enablePointerEvents;
|
2562
|
+
this.position = config.position || POSITION_DEFAULT;
|
2563
|
+
this.#changeDetector.markForCheck();
|
2564
|
+
}
|
2565
|
+
#addBackdropClickListener() {
|
2566
|
+
fromEvent(window.document, 'click')
|
2567
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
2568
|
+
.subscribe((event) => {
|
2569
|
+
if (event.target && this.overlayContentRef && this.overlayRef) {
|
2570
|
+
const isChild = this.overlayContentRef.nativeElement.contains(event.target);
|
2571
|
+
const isAbove = this.#coreAdapter.isTargetAboveElement(event.target, this.overlayRef.nativeElement);
|
2572
|
+
/* istanbul ignore else */
|
2573
|
+
if (!isChild && !isAbove) {
|
2574
|
+
this.#backdropClick.next();
|
2575
|
+
if (this.#context.config.enableClose) {
|
2576
|
+
this.#closed.next();
|
2577
|
+
}
|
2578
|
+
}
|
2579
|
+
}
|
2580
|
+
});
|
2581
|
+
}
|
2582
|
+
#addRouteListener() {
|
2583
|
+
/*istanbul ignore else*/
|
2584
|
+
if (this.#router) {
|
2585
|
+
this.#routerSubscription = this.#router.events.subscribe((event) => {
|
2586
|
+
/* istanbul ignore else */
|
2587
|
+
if (event instanceof NavigationStart) {
|
2588
|
+
this.#closed.next();
|
2589
|
+
}
|
2590
|
+
});
|
2591
|
+
}
|
2592
|
+
}
|
2593
|
+
#removeRouteListener() {
|
2594
|
+
if (this.#routerSubscription) {
|
2595
|
+
this.#routerSubscription.unsubscribe();
|
2596
|
+
this.#routerSubscription = undefined;
|
2597
|
+
}
|
2598
|
+
}
|
2599
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.Injector }, { token: SkyCoreAdapterService }, { token: SkyOverlayContext }, { token: SkyIdService }, { token: i4.Router, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
2600
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: SkyOverlayComponent, selector: "sky-overlay", host: { properties: { "id": "this.id" } }, viewQueries: [{ propertyName: "overlayContentRef", first: true, predicate: ["overlayContentRef"], descendants: true, read: ElementRef, static: true }, { propertyName: "overlayRef", first: true, predicate: ["overlayRef"], descendants: true, read: ElementRef, static: true }, { propertyName: "targetRef", first: true, predicate: ["target"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<div\n [class]=\"'sky-overlay-position-' + position + ' ' + wrapperClass\"\n [style.z-index]=\"zIndex\"\n [style.clip-path]=\"clipPath$ | async\"\n [ngClass]=\"{\n 'enable-pointer-events-pass-through': enablePointerEvents,\n 'sky-overlay': true\n }\"\n #overlayRef\n>\n <div class=\"sky-overlay-content\" #overlayContentRef>\n <ng-template #target> </ng-template>\n </div>\n <div *ngIf=\"showBackdrop\" class=\"sky-overlay-backdrop\"></div>\n</div>\n", styles: [".sky-overlay{inset:0;width:100%;height:100%;display:flex;pointer-events:auto}.sky-overlay-position-absolute{position:absolute}.sky-overlay-position-fixed{position:fixed}.sky-overlay-content{position:relative;z-index:1;display:inline-flex;align-self:start;pointer-events:auto}.sky-overlay-backdrop{background:rgba(0,0,0,.5);inset:0;width:100%;height:100%;position:absolute}.enable-pointer-events-pass-through,.enable-pointer-events-pass-through .sky-overlay-backdrop{pointer-events:none}.enable-pointer-events-pass-through .sky-overlay-content{pointer-events:auto}\n"], dependencies: [{ kind: "directive", type: i5.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i5.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
2601
|
+
}
|
2602
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayComponent, decorators: [{
|
2603
|
+
type: Component,
|
2604
|
+
args: [{ selector: 'sky-overlay', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n [class]=\"'sky-overlay-position-' + position + ' ' + wrapperClass\"\n [style.z-index]=\"zIndex\"\n [style.clip-path]=\"clipPath$ | async\"\n [ngClass]=\"{\n 'enable-pointer-events-pass-through': enablePointerEvents,\n 'sky-overlay': true\n }\"\n #overlayRef\n>\n <div class=\"sky-overlay-content\" #overlayContentRef>\n <ng-template #target> </ng-template>\n </div>\n <div *ngIf=\"showBackdrop\" class=\"sky-overlay-backdrop\"></div>\n</div>\n", styles: [".sky-overlay{inset:0;width:100%;height:100%;display:flex;pointer-events:auto}.sky-overlay-position-absolute{position:absolute}.sky-overlay-position-fixed{position:fixed}.sky-overlay-content{position:relative;z-index:1;display:inline-flex;align-self:start;pointer-events:auto}.sky-overlay-backdrop{background:rgba(0,0,0,.5);inset:0;width:100%;height:100%;position:absolute}.enable-pointer-events-pass-through,.enable-pointer-events-pass-through .sky-overlay-backdrop{pointer-events:none}.enable-pointer-events-pass-through .sky-overlay-content{pointer-events:auto}\n"] }]
|
2605
|
+
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.Injector }, { type: SkyCoreAdapterService }, { type: SkyOverlayContext }, { type: SkyIdService }, { type: i4.Router, decorators: [{
|
2606
|
+
type: Optional
|
2607
|
+
}] }]; }, propDecorators: { id: [{
|
2608
|
+
type: HostBinding,
|
2609
|
+
args: ['id']
|
2610
|
+
}], overlayContentRef: [{
|
2611
|
+
type: ViewChild,
|
2612
|
+
args: ['overlayContentRef', {
|
2613
|
+
read: ElementRef,
|
2614
|
+
static: true,
|
2615
|
+
}]
|
2616
|
+
}], overlayRef: [{
|
2617
|
+
type: ViewChild,
|
2618
|
+
args: ['overlayRef', {
|
2619
|
+
read: ElementRef,
|
2620
|
+
static: true,
|
2621
|
+
}]
|
2622
|
+
}], targetRef: [{
|
2623
|
+
type: ViewChild,
|
2624
|
+
args: ['target', {
|
2625
|
+
read: ViewContainerRef,
|
2626
|
+
static: true,
|
2627
|
+
}]
|
2628
|
+
}] } });
|
2629
|
+
|
2630
|
+
class SkyOverlayModule {
|
2631
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
2632
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayModule, declarations: [SkyOverlayComponent], imports: [CommonModule] }); }
|
2633
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayModule, imports: [CommonModule] }); }
|
2634
|
+
}
|
2635
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayModule, decorators: [{
|
2636
|
+
type: NgModule,
|
2637
|
+
args: [{
|
2638
|
+
imports: [CommonModule],
|
2639
|
+
declarations: [SkyOverlayComponent],
|
2640
|
+
}]
|
2641
|
+
}] });
|
2642
|
+
|
2643
|
+
/**
|
2644
|
+
* @internal
|
2645
|
+
*/
|
2646
|
+
class SkyOverlayAdapterService {
|
2647
|
+
#renderer;
|
2648
|
+
#styleElement;
|
2649
|
+
constructor(rendererFactory) {
|
2650
|
+
this.#renderer = rendererFactory.createRenderer(undefined, null);
|
2651
|
+
}
|
2652
|
+
restrictBodyScroll() {
|
2653
|
+
// Create a style element to avoid overwriting any existing inline body styles.
|
2654
|
+
const styleElement = this.#renderer.createElement('style');
|
2655
|
+
const textNode = this.#renderer.createText('body { overflow: hidden }');
|
2656
|
+
// Apply a `data-` attribute to make unit testing easier.
|
2657
|
+
this.#renderer.setAttribute(styleElement, 'data-test-selector', 'sky-overlay-restrict-scroll-styles');
|
2658
|
+
this.#renderer.appendChild(styleElement, textNode);
|
2659
|
+
this.#renderer.appendChild(document.head, styleElement);
|
2660
|
+
if (this.#styleElement) {
|
2661
|
+
this.#destroyStyleElement();
|
2662
|
+
}
|
2663
|
+
this.#styleElement = styleElement;
|
2664
|
+
}
|
2665
|
+
releaseBodyScroll() {
|
2666
|
+
this.#destroyStyleElement();
|
2667
|
+
}
|
2668
|
+
#destroyStyleElement() {
|
2669
|
+
/* istanbul ignore else */
|
2670
|
+
if (this.#styleElement &&
|
2671
|
+
this.#styleElement.parentElement === document.head) {
|
2672
|
+
this.#renderer.removeChild(document.head, this.#styleElement);
|
2673
|
+
}
|
2674
|
+
}
|
2675
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayAdapterService, deps: [{ token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
2676
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayAdapterService, providedIn: 'root' }); }
|
2677
|
+
}
|
2678
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayAdapterService, decorators: [{
|
2679
|
+
type: Injectable,
|
2680
|
+
args: [{
|
2681
|
+
providedIn: 'root',
|
2682
|
+
}]
|
2683
|
+
}], ctorParameters: function () { return [{ type: i0.RendererFactory2 }]; } });
|
2684
|
+
|
2685
|
+
/**
|
2686
|
+
* This service is used to create new overlays.
|
2687
|
+
* @dynamic
|
2688
|
+
*/
|
2689
|
+
class SkyOverlayService {
|
2690
|
+
static { this.overlays = []; }
|
2691
|
+
#adapter;
|
2692
|
+
#applicationRef;
|
2693
|
+
#componentFactoryResolver;
|
2694
|
+
#injector;
|
2695
|
+
// TODO: Replace deprecated `ComponentFactoryResolver`.
|
2696
|
+
constructor(applicationRef, componentFactoryResolver, injector, adapter) {
|
2697
|
+
this.#applicationRef = applicationRef;
|
2698
|
+
this.#componentFactoryResolver = componentFactoryResolver;
|
2699
|
+
this.#injector = injector;
|
2700
|
+
this.#adapter = adapter;
|
2701
|
+
}
|
2702
|
+
/**
|
2703
|
+
* Creates an empty overlay. Use the returned `SkyOverlayInstance` to append content.
|
2704
|
+
* @param config Configuration for the overlay.
|
2705
|
+
*/
|
2706
|
+
create(config) {
|
2707
|
+
const settings = this.#prepareConfig(config);
|
2708
|
+
if (settings.enableScroll === false) {
|
2709
|
+
this.#adapter.restrictBodyScroll();
|
2710
|
+
}
|
2711
|
+
const componentRef = this.#createOverlay(settings);
|
2712
|
+
const instance = new SkyOverlayInstance(settings, componentRef);
|
2713
|
+
instance.closed.subscribe(() => {
|
2714
|
+
// Only execute the service's close method if the instance still exists.
|
2715
|
+
// This is needed to address a race condition if the deprecated instance.close method is used instead.
|
2716
|
+
if (SkyOverlayService.overlays.indexOf(instance) > -1) {
|
2717
|
+
this.close(instance);
|
2718
|
+
}
|
2719
|
+
});
|
2720
|
+
SkyOverlayService.overlays.push(instance);
|
2721
|
+
return instance;
|
2722
|
+
}
|
2723
|
+
/**
|
2724
|
+
* Closes (and destroys) an overlay instance.
|
2725
|
+
* @param instance The instance to close.
|
2726
|
+
*/
|
2727
|
+
close(instance) {
|
2728
|
+
this.#destroyOverlay(instance);
|
2729
|
+
this.#applicationRef.detachView(instance.componentRef.hostView);
|
2730
|
+
instance.componentRef.destroy();
|
2731
|
+
// In some cases, Angular keeps dynamically-generated component's nodes in the DOM during
|
2732
|
+
// unit tests. This can make querying difficult because the older DOM nodes still exist and
|
2733
|
+
// produce inconsistent results.
|
2734
|
+
// Angular Material's overlay appears to do the same thing:
|
2735
|
+
// https://github.com/angular/components/blob/master/src/cdk/portal/dom-portal-outlet.ts#L143-L145
|
2736
|
+
// (Ignoring coverage since this branch will only be hit by consumer unit tests.)
|
2737
|
+
const componentElement = instance.componentRef.location.nativeElement;
|
2738
|
+
/* istanbul ignore if */
|
2739
|
+
if (componentElement.parentNode !== null) {
|
2740
|
+
componentElement.parentNode.removeChild(componentElement);
|
2741
|
+
}
|
2742
|
+
}
|
2743
|
+
/**
|
2744
|
+
* Closes all overlay instances.
|
2745
|
+
*/
|
2746
|
+
closeAll() {
|
2747
|
+
// The `close` event handler for each instance alters the array's length asynchronously,
|
2748
|
+
// so the only "safe" index to call is zero.
|
2749
|
+
while (SkyOverlayService.overlays.length > 0) {
|
2750
|
+
this.close(SkyOverlayService.overlays[0]);
|
2751
|
+
}
|
2752
|
+
}
|
2753
|
+
#createOverlay(config) {
|
2754
|
+
const injector = Injector.create({
|
2755
|
+
parent: this.#injector,
|
2756
|
+
providers: [
|
2757
|
+
{
|
2758
|
+
provide: SkyOverlayContext,
|
2759
|
+
useValue: new SkyOverlayContext(config),
|
2760
|
+
},
|
2761
|
+
],
|
2762
|
+
});
|
2763
|
+
const componentRef = this.#componentFactoryResolver
|
2764
|
+
.resolveComponentFactory(SkyOverlayComponent)
|
2765
|
+
.create(injector);
|
2766
|
+
this.#applicationRef.attachView(componentRef.hostView);
|
2767
|
+
const domElem = componentRef.hostView
|
2768
|
+
.rootNodes[0];
|
2769
|
+
document.body.appendChild(domElem);
|
2770
|
+
return componentRef;
|
2771
|
+
}
|
2772
|
+
#prepareConfig(config = {}) {
|
2773
|
+
const defaults = {
|
2774
|
+
closeOnNavigation: true,
|
2775
|
+
enableClose: false,
|
2776
|
+
enablePointerEvents: false,
|
2777
|
+
enableScroll: true,
|
2778
|
+
showBackdrop: false,
|
2779
|
+
wrapperClass: '',
|
2780
|
+
};
|
2781
|
+
return { ...defaults, ...config };
|
2782
|
+
}
|
2783
|
+
#destroyOverlay(instance) {
|
2784
|
+
SkyOverlayService.overlays.splice(SkyOverlayService.overlays.indexOf(instance), 1);
|
2785
|
+
if (instance.config.enableScroll === false) {
|
2786
|
+
// Only release the body scroll if no other overlay wishes it to be disabled.
|
2787
|
+
const anotherOverlayDisablesScroll = SkyOverlayService.overlays.some((o) => !o.config.enableScroll);
|
2788
|
+
if (!anotherOverlayDisablesScroll) {
|
2789
|
+
this.#adapter.releaseBodyScroll();
|
2790
|
+
}
|
2791
|
+
}
|
2792
|
+
}
|
2793
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayService, deps: [{ token: i0.ApplicationRef }, { token: i0.ComponentFactoryResolver }, { token: i0.Injector }, { token: SkyOverlayAdapterService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
2794
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayService, providedIn: 'root' }); }
|
2795
|
+
}
|
2796
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyOverlayService, decorators: [{
|
2797
|
+
type: Injectable,
|
2798
|
+
args: [{
|
2799
|
+
providedIn: 'root',
|
2800
|
+
}]
|
2801
|
+
}], ctorParameters: function () { return [{ type: i0.ApplicationRef }, { type: i0.ComponentFactoryResolver }, { type: i0.Injector }, { type: SkyOverlayAdapterService }]; } });
|
2802
|
+
|
2803
|
+
class SkyPercentPipe {
|
2804
|
+
get defaultLocale() {
|
2805
|
+
return this.#defaultLocale;
|
2806
|
+
}
|
2807
|
+
#defaultFormat = '1.0-2';
|
2808
|
+
#defaultLocale = 'en-US';
|
2809
|
+
#format;
|
2810
|
+
#formattedValue = '';
|
2811
|
+
#locale;
|
2812
|
+
#ngUnsubscribe = new Subject();
|
2813
|
+
#value;
|
2814
|
+
constructor(localeProvider) {
|
2815
|
+
localeProvider
|
2816
|
+
.getLocaleInfo()
|
2817
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
2818
|
+
.subscribe((localeInfo) => {
|
2819
|
+
this.#defaultLocale = localeInfo.locale;
|
2820
|
+
this.#updateFormattedValue();
|
2821
|
+
});
|
2822
|
+
}
|
2823
|
+
ngOnDestroy() {
|
2824
|
+
this.#ngUnsubscribe.next();
|
2825
|
+
this.#ngUnsubscribe.complete();
|
2826
|
+
}
|
2827
|
+
transform(value, format, locale) {
|
2828
|
+
this.#value = value;
|
2829
|
+
this.#format = format;
|
2830
|
+
this.#locale = locale;
|
2831
|
+
this.#updateFormattedValue();
|
2832
|
+
return this.#formattedValue;
|
2833
|
+
}
|
2834
|
+
#updateFormattedValue() {
|
2835
|
+
const locale = this.#locale || this.#defaultLocale;
|
2836
|
+
const format = this.#format || this.#defaultFormat;
|
2837
|
+
this.#formattedValue = this.#value
|
2838
|
+
? SkyNumberFormatUtility.formatNumber(locale, this.#value, SkyIntlNumberFormatStyle.Percent, format)
|
2839
|
+
: '';
|
2840
|
+
}
|
2841
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipe, deps: [{ token: i1.SkyAppLocaleProvider }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
2842
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipe, name: "skyPercent", pure: false }); }
|
2843
|
+
}
|
2844
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipe, decorators: [{
|
2845
|
+
type: Pipe,
|
2846
|
+
args: [{
|
2847
|
+
name: 'skyPercent',
|
2848
|
+
pure: false,
|
2849
|
+
}]
|
2850
|
+
}], ctorParameters: function () { return [{ type: i1.SkyAppLocaleProvider }]; } });
|
2851
|
+
|
2852
|
+
class SkyPercentPipeModule {
|
2853
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
2854
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipeModule, declarations: [SkyPercentPipe], imports: [CommonModule, SkyCoreResourcesModule], exports: [SkyPercentPipe] }); }
|
2855
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipeModule, providers: [SkyPercentPipe], imports: [CommonModule, SkyCoreResourcesModule] }); }
|
2856
|
+
}
|
2857
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyPercentPipeModule, decorators: [{
|
2858
|
+
type: NgModule,
|
2859
|
+
args: [{
|
2860
|
+
declarations: [SkyPercentPipe],
|
2861
|
+
providers: [SkyPercentPipe],
|
2862
|
+
imports: [CommonModule, SkyCoreResourcesModule],
|
2863
|
+
exports: [SkyPercentPipe],
|
2864
|
+
}]
|
2865
|
+
}] });
|
2866
|
+
|
2867
|
+
/**
|
2868
|
+
* Service to create rxjs observables for changes to the content box dimensions of elements.
|
2869
|
+
*/
|
2870
|
+
class SkyResizeObserverService {
|
2871
|
+
#resizeObserver;
|
2872
|
+
#tracking = [];
|
2873
|
+
#zone;
|
2874
|
+
constructor(zone) {
|
2875
|
+
this.#zone = zone;
|
2876
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
2877
|
+
entries.forEach((entry) => this.#callback(entry));
|
2878
|
+
});
|
2879
|
+
}
|
2880
|
+
ngOnDestroy() {
|
2881
|
+
this.#resizeObserver.disconnect();
|
2882
|
+
}
|
2883
|
+
/**
|
2884
|
+
* Create rxjs observable to get size changes for an element ref.
|
2885
|
+
*/
|
2886
|
+
observe(element) {
|
2887
|
+
return this.#observeAndTrack(element).subjectObservable;
|
2888
|
+
}
|
2889
|
+
#observeAndTrack(element) {
|
2890
|
+
const checkTracking = this.#tracking.findIndex((value) => {
|
2891
|
+
return !value.subject.closed && value.element === element.nativeElement;
|
2892
|
+
});
|
2893
|
+
if (checkTracking === -1) {
|
2894
|
+
this.#resizeObserver.observe(element.nativeElement);
|
2895
|
+
}
|
2896
|
+
const subject = new Subject();
|
2897
|
+
const subjectObservable = subject.pipe(finalize(() => {
|
2898
|
+
// Are there any other tracking entries still watching this element?
|
2899
|
+
const checkTracking = this.#tracking.findIndex((value) => {
|
2900
|
+
return (value.subject !== subject &&
|
2901
|
+
!value.subject.closed &&
|
2902
|
+
value.element === element.nativeElement);
|
2903
|
+
});
|
2904
|
+
if (checkTracking === -1) {
|
2905
|
+
this.#resizeObserver.unobserve(element.nativeElement);
|
2906
|
+
}
|
2907
|
+
}));
|
2908
|
+
const tracking = {
|
2909
|
+
element: element.nativeElement,
|
2910
|
+
subject,
|
2911
|
+
subjectObservable,
|
2912
|
+
};
|
2913
|
+
this.#tracking.push(tracking);
|
2914
|
+
return tracking;
|
2915
|
+
}
|
2916
|
+
#callback(entry) {
|
2917
|
+
this.#tracking
|
2918
|
+
.filter((value) => !(value.subject.closed || value.subject.isStopped))
|
2919
|
+
.forEach((value) => {
|
2920
|
+
/* istanbul ignore else */
|
2921
|
+
if (value.element === entry.target) {
|
2922
|
+
// Execute the callback within NgZone because Angular does not "monkey patch"
|
2923
|
+
// ResizeObserver like it does for other features in the DOM.
|
2924
|
+
this.#zone.run(() => {
|
2925
|
+
value.subject.next(entry);
|
2926
|
+
});
|
2927
|
+
}
|
2928
|
+
});
|
2929
|
+
}
|
2930
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
2931
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverService, providedIn: 'any' }); }
|
2932
|
+
}
|
2933
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverService, decorators: [{
|
2934
|
+
type: Injectable,
|
2935
|
+
args: [{
|
2936
|
+
providedIn: 'any',
|
2937
|
+
}]
|
2938
|
+
}], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
|
2939
|
+
|
2940
|
+
const DEFAULT_BREAKPOINT = SkyMediaBreakpoints.md;
|
2941
|
+
/**
|
2942
|
+
* Acts like `SkyMediaQueryService` for a container element, emitting the same responsive breakpoints.
|
2943
|
+
*/
|
2944
|
+
class SkyResizeObserverMediaQueryService {
|
2945
|
+
/**
|
2946
|
+
* Returns the current breakpoint.
|
2947
|
+
*/
|
2948
|
+
get current() {
|
2949
|
+
return this.#currentBreakpoint;
|
2950
|
+
}
|
2951
|
+
#breakpoints = [
|
2952
|
+
{
|
2953
|
+
check: (width) => width > 0 && width <= 767,
|
2954
|
+
name: SkyMediaBreakpoints.xs,
|
2955
|
+
},
|
2956
|
+
{
|
2957
|
+
check: (width) => width > 767 && width <= 991,
|
2958
|
+
name: SkyMediaBreakpoints.sm,
|
2959
|
+
},
|
2960
|
+
{
|
2961
|
+
check: (width) => width > 991 && width <= 1199,
|
2962
|
+
name: SkyMediaBreakpoints.md,
|
2963
|
+
},
|
2964
|
+
{
|
2965
|
+
check: (width) => width > 1199,
|
2966
|
+
name: SkyMediaBreakpoints.lg,
|
2967
|
+
},
|
2968
|
+
];
|
2969
|
+
#currentBreakpoint = DEFAULT_BREAKPOINT;
|
2970
|
+
#currentBreakpointObs = new ReplaySubject(1);
|
2971
|
+
#ngUnsubscribe = new Subject();
|
2972
|
+
#resizeObserverSvc;
|
2973
|
+
#target;
|
2974
|
+
constructor(resizeObserverSvc) {
|
2975
|
+
this.#resizeObserverSvc = resizeObserverSvc;
|
2976
|
+
}
|
2977
|
+
ngOnDestroy() {
|
2978
|
+
this.unobserve();
|
2979
|
+
this.#target = undefined;
|
2980
|
+
this.#currentBreakpointObs.complete();
|
2981
|
+
}
|
2982
|
+
/**
|
2983
|
+
* @internal
|
2984
|
+
*/
|
2985
|
+
destroy() {
|
2986
|
+
this.ngOnDestroy();
|
2987
|
+
}
|
2988
|
+
/**
|
2989
|
+
* Sets the container element to watch. The `SkyResizeObserverMediaQueryService` will only observe one element at a
|
2990
|
+
* time. Any previous subscriptions will be unsubscribed when a new element is observed.
|
2991
|
+
*/
|
2992
|
+
observe(element) {
|
2993
|
+
if (this.#target) {
|
2994
|
+
if (this.#target === element) {
|
2995
|
+
return this;
|
2996
|
+
}
|
2997
|
+
this.unobserve();
|
2998
|
+
}
|
2999
|
+
this.#target = element;
|
3000
|
+
this.#checkWidth(element);
|
3001
|
+
this.#resizeObserverSvc
|
3002
|
+
.observe(element)
|
3003
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
3004
|
+
.subscribe((value) => {
|
3005
|
+
const breakpoint = this.#checkBreakpoint(value.contentRect.width);
|
3006
|
+
if (breakpoint && breakpoint !== this.current) {
|
3007
|
+
this.#updateBreakpoint(breakpoint);
|
3008
|
+
}
|
3009
|
+
});
|
3010
|
+
return this;
|
3011
|
+
}
|
3012
|
+
/**
|
3013
|
+
* Stop watching the container element.
|
3014
|
+
*/
|
3015
|
+
unobserve() {
|
3016
|
+
this.#ngUnsubscribe.next();
|
3017
|
+
this.#ngUnsubscribe.complete();
|
3018
|
+
}
|
3019
|
+
/**
|
3020
|
+
* Subscribes to element size changes that cross breakpoints.
|
3021
|
+
*/
|
3022
|
+
subscribe(listener) {
|
3023
|
+
return this.#currentBreakpointObs
|
3024
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
3025
|
+
.subscribe((value) => {
|
3026
|
+
listener(value);
|
3027
|
+
});
|
3028
|
+
}
|
3029
|
+
#updateBreakpoint(breakpoint) {
|
3030
|
+
this.#currentBreakpoint = breakpoint;
|
3031
|
+
this.#currentBreakpointObs.next(breakpoint);
|
3032
|
+
}
|
3033
|
+
#checkBreakpoint(width) {
|
3034
|
+
const breakpoint = this.#breakpoints.find((breakpoint) => breakpoint.check(width));
|
3035
|
+
return breakpoint ? breakpoint.name : undefined;
|
3036
|
+
}
|
3037
|
+
#checkWidth(el) {
|
3038
|
+
const width = el.nativeElement.offsetWidth || 0;
|
3039
|
+
const breakpoint = this.#checkBreakpoint(width);
|
3040
|
+
if (breakpoint && breakpoint !== this.#currentBreakpoint) {
|
3041
|
+
this.#updateBreakpoint(breakpoint);
|
3042
|
+
}
|
3043
|
+
}
|
3044
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, deps: [{ token: SkyResizeObserverService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3045
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, providedIn: 'any' }); }
|
3046
|
+
}
|
3047
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, decorators: [{
|
3048
|
+
type: Injectable,
|
3049
|
+
args: [{
|
3050
|
+
providedIn: 'any',
|
3051
|
+
}]
|
3052
|
+
}], ctorParameters: function () { return [{ type: SkyResizeObserverService }]; } });
|
3053
|
+
|
3054
|
+
function notifySubscribers(subscribers, item) {
|
3055
|
+
for (const subscriber of subscribers) {
|
3056
|
+
subscriber.next(item);
|
3057
|
+
}
|
3058
|
+
}
|
3059
|
+
class SkyScrollableHostService {
|
3060
|
+
#mutationObserverSvc;
|
3061
|
+
#windowRef;
|
3062
|
+
#resizeObserverSvc;
|
3063
|
+
constructor(mutationObserverSvc, windowRef, resizeObserverSvc) {
|
3064
|
+
this.#mutationObserverSvc = mutationObserverSvc;
|
3065
|
+
this.#resizeObserverSvc = resizeObserverSvc;
|
3066
|
+
this.#windowRef = windowRef;
|
3067
|
+
}
|
3068
|
+
/**
|
3069
|
+
* Returns the given element's current scrollable host
|
3070
|
+
* @param elementRef The element whose scrollable host is being requested
|
3071
|
+
* @returns The current scrollable host
|
3072
|
+
*/
|
3073
|
+
getScrollableHost(elementRef) {
|
3074
|
+
return this.#findScrollableHost(elementRef.nativeElement);
|
3075
|
+
}
|
3076
|
+
/**
|
3077
|
+
* Returns an observable which emits the given element's current scrollable host
|
3078
|
+
* @param elementRef The element whose scrollable host is being requested
|
3079
|
+
* @returns An observable which emits the current scrollable host element.
|
3080
|
+
* @internal
|
3081
|
+
*/
|
3082
|
+
watchScrollableHost(elementRef) {
|
3083
|
+
const subscribers = [];
|
3084
|
+
let parentMutationObserver;
|
3085
|
+
let documentHiddenElementMutationObserver;
|
3086
|
+
return new Observable((subscriber) => {
|
3087
|
+
subscribers.push(subscriber);
|
3088
|
+
let scrollableHost = this.#findScrollableHost(elementRef.nativeElement);
|
3089
|
+
// Setup mutation observers only once, for all subscribers.
|
3090
|
+
if (subscribers.length === 1) {
|
3091
|
+
parentMutationObserver = this.#mutationObserverSvc.create(() => {
|
3092
|
+
const newScrollableHost = this.#findScrollableHost(elementRef.nativeElement);
|
3093
|
+
// Reset observer if scrollable host changes.
|
3094
|
+
if (newScrollableHost !== scrollableHost &&
|
3095
|
+
this.#isElementVisible(elementRef)) {
|
3096
|
+
scrollableHost = newScrollableHost;
|
3097
|
+
this.#observeForScrollableHostChanges(scrollableHost, parentMutationObserver);
|
3098
|
+
notifySubscribers(subscribers, scrollableHost);
|
3099
|
+
}
|
3100
|
+
});
|
3101
|
+
this.#observeForScrollableHostChanges(scrollableHost, parentMutationObserver);
|
3102
|
+
documentHiddenElementMutationObserver =
|
3103
|
+
this.#mutationObserverSvc.create(() => {
|
3104
|
+
if (scrollableHost && !this.#isElementVisible(elementRef)) {
|
3105
|
+
// If the scrollable host is not visible, set it to undefined and unsubscribe from its mutation changes.
|
3106
|
+
// Then, observe the document element so that a new scrollable host can be found.
|
3107
|
+
scrollableHost = undefined;
|
3108
|
+
this.#observeForScrollableHostChanges(scrollableHost, parentMutationObserver);
|
3109
|
+
notifySubscribers(subscribers, scrollableHost);
|
3110
|
+
}
|
3111
|
+
});
|
3112
|
+
this.#observeDocumentHiddenElementChanges(documentHiddenElementMutationObserver);
|
3113
|
+
}
|
3114
|
+
// Emit the scrollable host to the subscriber.
|
3115
|
+
subscriber.next(scrollableHost);
|
3116
|
+
// Teardown callback for the subscription.
|
3117
|
+
subscriber.add(() => {
|
3118
|
+
const subIndex = subscribers.indexOf(subscriber);
|
3119
|
+
/* istanbul ignore else */
|
3120
|
+
if (subIndex >= 0) {
|
3121
|
+
subscribers.splice(subIndex, 1);
|
3122
|
+
}
|
3123
|
+
if (subscribers.length === 0) {
|
3124
|
+
documentHiddenElementMutationObserver.disconnect();
|
3125
|
+
parentMutationObserver.disconnect();
|
3126
|
+
}
|
3127
|
+
});
|
3128
|
+
});
|
3129
|
+
}
|
3130
|
+
/**
|
3131
|
+
* Returns an observable which emits whenever the element's scrollable host emits a scroll event. The observable will always emit the scroll events from the elements current scrollable host and will update based on any scrollable host changes. The observable will also emit once whenever the scrollable host changes.
|
3132
|
+
* @param elementRef The element whose scrollable host scroll events are being requested
|
3133
|
+
* @returns An observable which emits when the elements scrollable host is scrolled or is changed
|
3134
|
+
*/
|
3135
|
+
watchScrollableHostScrollEvents(elementRef) {
|
3136
|
+
const subscribers = [];
|
3137
|
+
let scrollableHost;
|
3138
|
+
let newScrollableHostObservable = new Subject();
|
3139
|
+
let scrollableHostSubscription;
|
3140
|
+
let scrollEventSubscription;
|
3141
|
+
return new Observable((subscriber) => {
|
3142
|
+
subscribers.push(subscriber);
|
3143
|
+
// Setup mutation observers only once, for all subscribers.
|
3144
|
+
if (subscribers.length === 1) {
|
3145
|
+
scrollableHostSubscription = this.watchScrollableHost(elementRef).subscribe((newScrollableHost) => {
|
3146
|
+
newScrollableHostObservable.next();
|
3147
|
+
newScrollableHostObservable.complete();
|
3148
|
+
if (scrollableHost && scrollableHost !== newScrollableHost) {
|
3149
|
+
notifySubscribers(subscribers);
|
3150
|
+
}
|
3151
|
+
scrollableHost = newScrollableHost;
|
3152
|
+
newScrollableHostObservable = new Subject();
|
3153
|
+
// Only subscribe to scroll events if the host element is defined.
|
3154
|
+
/* istanbul ignore else */
|
3155
|
+
if (newScrollableHost) {
|
3156
|
+
scrollEventSubscription = fromEvent(newScrollableHost, 'scroll')
|
3157
|
+
.pipe(takeUntil(newScrollableHostObservable))
|
3158
|
+
.subscribe(() => {
|
3159
|
+
notifySubscribers(subscribers);
|
3160
|
+
});
|
3161
|
+
}
|
3162
|
+
});
|
3163
|
+
}
|
3164
|
+
// Teardown callback for the subscription.
|
3165
|
+
subscriber.add(() => {
|
3166
|
+
const subIndex = subscribers.indexOf(subscriber);
|
3167
|
+
/* istanbul ignore else */
|
3168
|
+
if (subIndex >= 0) {
|
3169
|
+
subscribers.splice(subIndex, 1);
|
3170
|
+
}
|
3171
|
+
if (subscribers.length === 0) {
|
3172
|
+
scrollableHostSubscription.unsubscribe();
|
3173
|
+
scrollEventSubscription.unsubscribe();
|
3174
|
+
newScrollableHostObservable.complete();
|
3175
|
+
}
|
3176
|
+
});
|
3177
|
+
});
|
3178
|
+
}
|
3179
|
+
watchScrollableHostClipPathChanges(elementRef) {
|
3180
|
+
if (!this.#resizeObserverSvc) {
|
3181
|
+
return of('none');
|
3182
|
+
}
|
3183
|
+
return this.watchScrollableHost(elementRef).pipe(switchMap((scrollableHost) => {
|
3184
|
+
if (!this.#resizeObserverSvc ||
|
3185
|
+
!scrollableHost ||
|
3186
|
+
scrollableHost === this.#windowRef.nativeWindow) {
|
3187
|
+
return of('none');
|
3188
|
+
}
|
3189
|
+
return concat([
|
3190
|
+
of(undefined),
|
3191
|
+
this.#resizeObserverSvc.observe({ nativeElement: scrollableHost }),
|
3192
|
+
]).pipe(debounceTime(0, animationFrameScheduler), map(() => {
|
3193
|
+
const viewportSize = this.#getViewportSize();
|
3194
|
+
const { top, left, width, height } = scrollableHost.getBoundingClientRect();
|
3195
|
+
const right = Math.max(viewportSize.width - left - width, 0);
|
3196
|
+
const bottom = Math.max(viewportSize.height - top - height, 0);
|
3197
|
+
return `inset(${top}px ${right}px ${bottom}px ${left}px)`;
|
3198
|
+
}));
|
3199
|
+
}));
|
3200
|
+
}
|
3201
|
+
#findScrollableHost(element) {
|
3202
|
+
const regex = /(auto|scroll)/;
|
3203
|
+
const windowObj = this.#windowRef.nativeWindow;
|
3204
|
+
const bodyObj = windowObj.document.body;
|
3205
|
+
if (!element) {
|
3206
|
+
return windowObj;
|
3207
|
+
}
|
3208
|
+
let style = windowObj.getComputedStyle(element);
|
3209
|
+
let parent = element;
|
3210
|
+
do {
|
3211
|
+
parent = parent.parentNode;
|
3212
|
+
// Return `window` if the parent element has been removed from the DOM.
|
3213
|
+
if (!(parent instanceof HTMLElement)) {
|
3214
|
+
return windowObj;
|
3215
|
+
}
|
3216
|
+
style = windowObj.getComputedStyle(parent);
|
3217
|
+
} while (!regex.test(style.overflow) &&
|
3218
|
+
!regex.test(style.overflowY) &&
|
3219
|
+
parent !== bodyObj);
|
3220
|
+
if (parent === bodyObj) {
|
3221
|
+
return windowObj;
|
3222
|
+
}
|
3223
|
+
return parent;
|
3224
|
+
}
|
3225
|
+
#observeDocumentHiddenElementChanges(mutationObserver) {
|
3226
|
+
mutationObserver.observe(document.documentElement, {
|
3227
|
+
attributes: true,
|
3228
|
+
attributeFilter: ['class', 'style', 'hidden'],
|
3229
|
+
childList: true,
|
3230
|
+
subtree: true,
|
3231
|
+
});
|
3232
|
+
}
|
3233
|
+
#observeForScrollableHostChanges(element, mutationObserver) {
|
3234
|
+
mutationObserver.disconnect();
|
3235
|
+
const target = element instanceof HTMLElement ? element : document.documentElement;
|
3236
|
+
mutationObserver.observe(target, {
|
3237
|
+
attributes: true,
|
3238
|
+
attributeFilter: ['class', 'style'],
|
3239
|
+
childList: true,
|
3240
|
+
subtree: true,
|
3241
|
+
});
|
3242
|
+
}
|
3243
|
+
/**
|
3244
|
+
* Determines if an element is "visible" in the DOM.
|
3245
|
+
* @see https://stackoverflow.com/a/11639664/6178885
|
3246
|
+
*/
|
3247
|
+
#isElementVisible(elementRef) {
|
3248
|
+
return !!elementRef.nativeElement?.offsetParent;
|
3249
|
+
}
|
3250
|
+
#getViewportSize() {
|
3251
|
+
const win = this.#windowRef.nativeWindow;
|
3252
|
+
const docElem = win.document.documentElement;
|
3253
|
+
return {
|
3254
|
+
width: docElem.clientWidth,
|
3255
|
+
height: docElem.clientHeight,
|
3256
|
+
};
|
3257
|
+
}
|
3258
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyScrollableHostService, deps: [{ token: SkyMutationObserverService }, { token: SkyAppWindowRef }, { token: SkyResizeObserverService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3259
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyScrollableHostService, providedIn: 'root' }); }
|
3260
|
+
}
|
3261
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyScrollableHostService, decorators: [{
|
3262
|
+
type: Injectable,
|
3263
|
+
args: [{
|
3264
|
+
providedIn: 'root',
|
3265
|
+
}]
|
3266
|
+
}], ctorParameters: function () { return [{ type: SkyMutationObserverService }, { type: SkyAppWindowRef }, { type: SkyResizeObserverService, decorators: [{
|
3267
|
+
type: Optional
|
3268
|
+
}] }]; } });
|
3269
|
+
|
3270
|
+
/**
|
3271
|
+
* Provides a method for setting a formatted title on the current window.
|
3272
|
+
*/
|
3273
|
+
class SkyAppTitleService {
|
3274
|
+
#title;
|
3275
|
+
constructor(title) {
|
3276
|
+
this.#title = title;
|
3277
|
+
}
|
3278
|
+
/**
|
3279
|
+
* Sets the title on the current window.
|
3280
|
+
* @param args An array of title parts. The parts will be concatenated with a hyphen between
|
3281
|
+
* each part.
|
3282
|
+
*/
|
3283
|
+
setTitle(args) {
|
3284
|
+
if (args?.titleParts) {
|
3285
|
+
this.#title.setTitle(args.titleParts.join(' - '));
|
3286
|
+
}
|
3287
|
+
}
|
3288
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppTitleService, deps: [{ token: i1$1.Title }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3289
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppTitleService, providedIn: 'root' }); }
|
3290
|
+
}
|
3291
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyAppTitleService, decorators: [{
|
3292
|
+
type: Injectable,
|
3293
|
+
args: [{
|
3294
|
+
providedIn: 'root',
|
3295
|
+
}]
|
3296
|
+
}], ctorParameters: function () { return [{ type: i1$1.Title }]; } });
|
3297
|
+
|
3298
|
+
/**
|
3299
|
+
* Trims whitespace in each text node that is a direct descendent of the current element.
|
3300
|
+
*/
|
3301
|
+
class SkyTrimDirective {
|
3302
|
+
#elRef;
|
3303
|
+
#obs;
|
3304
|
+
constructor(elRef, mutationObs) {
|
3305
|
+
this.#elRef = elRef;
|
3306
|
+
this.#obs = mutationObs.create((mutations) => {
|
3307
|
+
const nodes = [];
|
3308
|
+
// Only trim white space inside direct descendants of the current element.
|
3309
|
+
for (const mutation of mutations) {
|
3310
|
+
if (mutation.target.parentNode === elRef.nativeElement) {
|
3311
|
+
nodes.push(mutation.target);
|
3312
|
+
}
|
3313
|
+
}
|
3314
|
+
this.#trim(nodes);
|
3315
|
+
});
|
3316
|
+
this.#observe();
|
3317
|
+
}
|
3318
|
+
ngOnInit() {
|
3319
|
+
const el = this.#elRef.nativeElement;
|
3320
|
+
this.#trim(Array.from(el.childNodes));
|
3321
|
+
}
|
3322
|
+
ngOnDestroy() {
|
3323
|
+
this.#disconnect();
|
3324
|
+
}
|
3325
|
+
#observe() {
|
3326
|
+
this.#obs.observe(this.#elRef.nativeElement, {
|
3327
|
+
characterData: true,
|
3328
|
+
subtree: true,
|
3329
|
+
});
|
3330
|
+
}
|
3331
|
+
#disconnect() {
|
3332
|
+
this.#obs.disconnect();
|
3333
|
+
}
|
3334
|
+
#trim(nodes) {
|
3335
|
+
// Suspend the MutationObserver so altering the text content of each node
|
3336
|
+
// doesn't retrigger the observe callback.
|
3337
|
+
this.#disconnect();
|
3338
|
+
for (const node of nodes) {
|
3339
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent) {
|
3340
|
+
const textContent = node.textContent;
|
3341
|
+
const textContentTrimmed = textContent.trim();
|
3342
|
+
if (textContent !== textContentTrimmed) {
|
3343
|
+
node.textContent = textContentTrimmed;
|
3344
|
+
}
|
3345
|
+
}
|
3346
|
+
}
|
3347
|
+
this.#observe();
|
3348
|
+
}
|
3349
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimDirective, deps: [{ token: i0.ElementRef }, { token: SkyMutationObserverService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
3350
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: SkyTrimDirective, selector: "[skyTrim]", ngImport: i0 }); }
|
3351
|
+
}
|
3352
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimDirective, decorators: [{
|
3353
|
+
type: Directive,
|
3354
|
+
args: [{
|
3355
|
+
selector: '[skyTrim]',
|
3356
|
+
}]
|
3357
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: SkyMutationObserverService }]; } });
|
3358
|
+
|
3359
|
+
class SkyTrimModule {
|
3360
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
3361
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimModule, declarations: [SkyTrimDirective], exports: [SkyTrimDirective] }); }
|
3362
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimModule }); }
|
3363
|
+
}
|
3364
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyTrimModule, decorators: [{
|
3365
|
+
type: NgModule,
|
3366
|
+
args: [{
|
3367
|
+
declarations: [SkyTrimDirective],
|
3368
|
+
exports: [SkyTrimDirective],
|
3369
|
+
}]
|
3370
|
+
}] });
|
3371
|
+
|
3372
|
+
class SkyUIConfigService {
|
3373
|
+
getConfig(key, defaultConfig) {
|
3374
|
+
return of(defaultConfig);
|
3375
|
+
}
|
3376
|
+
/* istanbul ignore next */
|
3377
|
+
setConfig(key, value) {
|
3378
|
+
return of({});
|
3379
|
+
}
|
3380
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyUIConfigService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3381
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyUIConfigService, providedIn: 'root' }); }
|
3382
|
+
}
|
3383
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyUIConfigService, decorators: [{
|
3384
|
+
type: Injectable,
|
3385
|
+
args: [{
|
3386
|
+
providedIn: 'root',
|
3387
|
+
}]
|
3388
|
+
}] });
|
3389
|
+
|
3390
|
+
class SkyViewkeeperHostOptions {
|
3391
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperHostOptions, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3392
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperHostOptions }); }
|
3393
|
+
}
|
3394
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperHostOptions, decorators: [{
|
3395
|
+
type: Injectable
|
3396
|
+
}] });
|
3397
|
+
|
3398
|
+
const CLS_VIEWKEEPER_FIXED = 'sky-viewkeeper-fixed';
|
3399
|
+
const EVT_AFTER_VIEWKEEPER_SYNC = 'afterViewkeeperSync';
|
3400
|
+
let styleEl;
|
3401
|
+
let nextIdIndex;
|
3402
|
+
function ensureStyleEl() {
|
3403
|
+
if (!styleEl) {
|
3404
|
+
styleEl = document.createElement('style');
|
3405
|
+
const css = document.createTextNode(`
|
3406
|
+
.${CLS_VIEWKEEPER_FIXED} {
|
3407
|
+
position: fixed !important;
|
3408
|
+
z-index: 999;
|
3409
|
+
opacity: 0.95;
|
3410
|
+
overflow: hidden;
|
3411
|
+
}
|
3412
|
+
|
3413
|
+
.sky-theme-modern .${CLS_VIEWKEEPER_FIXED} {
|
3414
|
+
box-shadow: 0px 1px 8px -1px rgba(0, 0, 0, 0.3);
|
3415
|
+
opacity: initial;
|
3416
|
+
}
|
3417
|
+
`);
|
3418
|
+
styleEl.appendChild(css);
|
3419
|
+
document.head.appendChild(styleEl);
|
3420
|
+
}
|
3421
|
+
}
|
3422
|
+
function nextId() {
|
3423
|
+
nextIdIndex = (nextIdIndex || 0) + 1;
|
3424
|
+
return 'viewkeeper-' + nextIdIndex;
|
3425
|
+
}
|
3426
|
+
function getOffset(el, scrollableHost) {
|
3427
|
+
const rect = el.getBoundingClientRect();
|
3428
|
+
const parent = scrollableHost ? scrollableHost : document.documentElement;
|
3429
|
+
return {
|
3430
|
+
top: rect.top + parent.scrollTop,
|
3431
|
+
left: rect.left + parent.scrollLeft,
|
3432
|
+
};
|
3433
|
+
}
|
3434
|
+
function px(value) {
|
3435
|
+
let pxValue = value ? value.toString() : '';
|
3436
|
+
if (typeof value === 'number') {
|
3437
|
+
pxValue = value + 'px';
|
3438
|
+
}
|
3439
|
+
return pxValue;
|
3440
|
+
}
|
3441
|
+
function setElPosition(el, left, top, width, marginTop, clipTop, clipLeft) {
|
3442
|
+
el.style.top = px(top);
|
3443
|
+
el.style.left = px(left);
|
3444
|
+
el.style.marginTop = px(marginTop);
|
3445
|
+
el.style.clipPath =
|
3446
|
+
clipTop || clipLeft ? `inset(${px(clipTop)} 0 0 ${px(clipLeft)})` : 'none';
|
3447
|
+
/*istanbul ignore else*/
|
3448
|
+
/* sanity check */
|
3449
|
+
if (width !== null) {
|
3450
|
+
el.style.width = px(width);
|
3451
|
+
}
|
3452
|
+
}
|
3453
|
+
function getHeightWithMargin(el) {
|
3454
|
+
const computedStyle = getComputedStyle(el);
|
3455
|
+
return (el.offsetHeight +
|
3456
|
+
parseInt(computedStyle.marginTop, 10) +
|
3457
|
+
parseInt(computedStyle.marginBottom, 10));
|
3458
|
+
}
|
3459
|
+
function createCustomEvent(name) {
|
3460
|
+
const evt = document.createEvent('CustomEvent');
|
3461
|
+
evt.initCustomEvent(name, false, false, undefined);
|
3462
|
+
return evt;
|
3463
|
+
}
|
3464
|
+
class SkyViewkeeper {
|
3465
|
+
#boundaryEl;
|
3466
|
+
#el;
|
3467
|
+
#id;
|
3468
|
+
#setWidth;
|
3469
|
+
#verticalOffset;
|
3470
|
+
#verticalOffsetEl;
|
3471
|
+
#viewportMarginTop = 0;
|
3472
|
+
#currentElFixedLeft;
|
3473
|
+
#currentElFixedTop;
|
3474
|
+
#currentElFixedWidth;
|
3475
|
+
#currentElClipLeft;
|
3476
|
+
#currentElClipTop;
|
3477
|
+
#isDestroyed = false;
|
3478
|
+
#scrollableHost;
|
3479
|
+
#syncElPositionHandler;
|
3480
|
+
#intersectionObserver;
|
3481
|
+
constructor(options) {
|
3482
|
+
options = options || /* istanbul ignore next */ {};
|
3483
|
+
this.#el = options.el;
|
3484
|
+
this.#boundaryEl = options.boundaryEl;
|
3485
|
+
if (!this.#el) {
|
3486
|
+
throw new Error('[SkyViewkeeper] The option `el` is required.');
|
3487
|
+
}
|
3488
|
+
if (!this.#boundaryEl) {
|
3489
|
+
throw new Error('[SkyViewkeeper] The option `boundaryEl` is required.');
|
3490
|
+
}
|
3491
|
+
const el = this.#el;
|
3492
|
+
const boundaryEl = this.#boundaryEl;
|
3493
|
+
this.#setWidth = !!options.setWidth;
|
3494
|
+
this.#id = nextId();
|
3495
|
+
this.#scrollableHost = options.scrollableHost;
|
3496
|
+
this.#verticalOffset = options.verticalOffset || 0;
|
3497
|
+
this.#verticalOffsetEl = options.verticalOffsetEl;
|
3498
|
+
// Only set viewport margin if the scrollable host is undefined.
|
3499
|
+
if (!this.#scrollableHost) {
|
3500
|
+
this.#viewportMarginTop = options.viewportMarginTop ?? 0;
|
3501
|
+
}
|
3502
|
+
this.#syncElPositionHandler = () => this.syncElPosition(el, boundaryEl);
|
3503
|
+
if (this.#verticalOffsetEl) {
|
3504
|
+
this.#verticalOffsetEl.addEventListener(EVT_AFTER_VIEWKEEPER_SYNC, this.#syncElPositionHandler);
|
3505
|
+
}
|
3506
|
+
window.addEventListener('scroll', this.#syncElPositionHandler, true);
|
3507
|
+
window.addEventListener('resize', this.#syncElPositionHandler);
|
3508
|
+
window.addEventListener('orientationchange', this.#syncElPositionHandler);
|
3509
|
+
ensureStyleEl();
|
3510
|
+
this.syncElPosition(el, boundaryEl);
|
3511
|
+
}
|
3512
|
+
syncElPosition(el, boundaryEl) {
|
3513
|
+
const verticalOffset = this.#calculateVerticalOffset();
|
3514
|
+
// When the element isn't visible, its size can't be calculated, so don't attempt syncing position in this case.
|
3515
|
+
if (el.offsetWidth === 0 && el.offsetHeight === 0) {
|
3516
|
+
return;
|
3517
|
+
}
|
3518
|
+
const boundaryInfo = this.#getBoundaryInfo(el, boundaryEl);
|
3519
|
+
const fixedStyles = this.#getFixedStyles(boundaryInfo, verticalOffset);
|
3520
|
+
const doFixEl = this.#shouldFixEl(el, boundaryInfo, verticalOffset);
|
3521
|
+
if (this.#needsUpdating(doFixEl, fixedStyles)) {
|
3522
|
+
if (doFixEl) {
|
3523
|
+
this.#fixEl(el, boundaryInfo, fixedStyles);
|
3524
|
+
}
|
3525
|
+
else {
|
3526
|
+
this.#unfixEl(el);
|
3527
|
+
}
|
3528
|
+
}
|
3529
|
+
const evt = createCustomEvent(EVT_AFTER_VIEWKEEPER_SYNC);
|
3530
|
+
el.dispatchEvent(evt);
|
3531
|
+
}
|
3532
|
+
destroy() {
|
3533
|
+
if (!this.#isDestroyed) {
|
3534
|
+
this.#intersectionObserver?.disconnect();
|
3535
|
+
window.removeEventListener('scroll', this.#syncElPositionHandler, true);
|
3536
|
+
window.removeEventListener('resize', this.#syncElPositionHandler);
|
3537
|
+
window.removeEventListener('orientationchange', this.#syncElPositionHandler);
|
3538
|
+
if (this.#el) {
|
3539
|
+
this.#unfixEl(this.#el);
|
3540
|
+
}
|
3541
|
+
if (this.#verticalOffsetEl) {
|
3542
|
+
this.#verticalOffsetEl.removeEventListener(EVT_AFTER_VIEWKEEPER_SYNC, this.#syncElPositionHandler);
|
3543
|
+
}
|
3544
|
+
this.#el = this.#boundaryEl = this.#verticalOffsetEl = undefined;
|
3545
|
+
this.#isDestroyed = true;
|
3546
|
+
}
|
3547
|
+
}
|
3548
|
+
#getSpacerId() {
|
3549
|
+
return this.#id + '-spacer';
|
3550
|
+
}
|
3551
|
+
#unfixEl(el) {
|
3552
|
+
const spacerEl = document.getElementById(this.#getSpacerId());
|
3553
|
+
/*istanbul ignore else*/
|
3554
|
+
if (spacerEl?.parentElement) {
|
3555
|
+
spacerEl.parentElement.removeChild(spacerEl);
|
3556
|
+
}
|
3557
|
+
el.classList.remove(CLS_VIEWKEEPER_FIXED);
|
3558
|
+
this.#currentElFixedLeft =
|
3559
|
+
this.#currentElFixedTop =
|
3560
|
+
this.#currentElFixedWidth =
|
3561
|
+
undefined;
|
3562
|
+
let width = '';
|
3563
|
+
if (this.#setWidth) {
|
3564
|
+
width = 'auto';
|
3565
|
+
}
|
3566
|
+
setElPosition(el, '', '', width, '', 0, 0);
|
3567
|
+
}
|
3568
|
+
#calculateVerticalOffset() {
|
3569
|
+
let offset = this.#verticalOffset;
|
3570
|
+
if (this.#verticalOffsetEl) {
|
3571
|
+
const verticalOffsetElTopStyle = this.#verticalOffsetEl.style.top;
|
3572
|
+
const verticalOffsetElTop = parseInt(verticalOffsetElTopStyle, 10) || 0;
|
3573
|
+
offset += this.#verticalOffsetEl.offsetHeight + verticalOffsetElTop;
|
3574
|
+
}
|
3575
|
+
else if (this.#scrollableHost) {
|
3576
|
+
offset += this.#scrollableHost.getBoundingClientRect().top;
|
3577
|
+
}
|
3578
|
+
return offset;
|
3579
|
+
}
|
3580
|
+
#shouldFixEl(el, boundaryInfo, verticalOffset) {
|
3581
|
+
let anchorTop;
|
3582
|
+
if (boundaryInfo.spacerEl) {
|
3583
|
+
anchorTop = getOffset(boundaryInfo.spacerEl, this.#scrollableHost).top;
|
3584
|
+
}
|
3585
|
+
else {
|
3586
|
+
anchorTop = getOffset(el, this.#scrollableHost).top;
|
3587
|
+
}
|
3588
|
+
const doFixEl = boundaryInfo.scrollTop + verticalOffset + this.#viewportMarginTop >
|
3589
|
+
anchorTop;
|
3590
|
+
return doFixEl;
|
3591
|
+
}
|
3592
|
+
#getFixedStyles(boundaryInfo, verticalOffset) {
|
3593
|
+
// If the element needs to be fixed, this will calculate its position. The position
|
3594
|
+
// will be 0 (fully visible) unless the user is scrolling the boundary out of view.
|
3595
|
+
// In that case, the element should begin to scroll out of view with the
|
3596
|
+
// rest of the boundary by setting its top position to a negative value.
|
3597
|
+
const elTop = boundaryInfo.boundaryBottom -
|
3598
|
+
boundaryInfo.elHeight -
|
3599
|
+
boundaryInfo.scrollTop;
|
3600
|
+
const elClipTop = elTop < verticalOffset ? verticalOffset - elTop : 0;
|
3601
|
+
const elFixedTop = Math.min(elTop, verticalOffset);
|
3602
|
+
const elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;
|
3603
|
+
const elFixedLeft = boundaryInfo.boundaryOffset.left - boundaryInfo.scrollLeft;
|
3604
|
+
const elClipLeft = elFixedLeft < 0 ? 0 - elFixedLeft : 0;
|
3605
|
+
return {
|
3606
|
+
elFixedLeft,
|
3607
|
+
elFixedTop,
|
3608
|
+
elFixedWidth,
|
3609
|
+
elClipLeft,
|
3610
|
+
elClipTop,
|
3611
|
+
};
|
3612
|
+
}
|
3613
|
+
#needsUpdating(doFixEl, fixedStyles) {
|
3614
|
+
if ((doFixEl &&
|
3615
|
+
this.#currentElFixedLeft === fixedStyles.elFixedLeft &&
|
3616
|
+
this.#currentElFixedTop === fixedStyles.elFixedTop &&
|
3617
|
+
this.#currentElClipLeft === fixedStyles.elClipLeft &&
|
3618
|
+
this.#currentElClipTop === fixedStyles.elClipTop &&
|
3619
|
+
this.#currentElFixedWidth === fixedStyles.elFixedWidth) ||
|
3620
|
+
(!doFixEl &&
|
3621
|
+
!(this.#currentElFixedLeft !== undefined &&
|
3622
|
+
this.#currentElFixedLeft !== null))) {
|
3623
|
+
// The element is either currently fixed and its position and width do not need
|
3624
|
+
// to change, or the element is not currently fixed and does not need to be fixed.
|
3625
|
+
// No changes are needed.
|
3626
|
+
return false;
|
3627
|
+
}
|
3628
|
+
return true;
|
3629
|
+
}
|
3630
|
+
#fixEl(el, boundaryInfo, fixedStyles) {
|
3631
|
+
/* istanbul ignore else */
|
3632
|
+
/* sanity check */
|
3633
|
+
if (!boundaryInfo.spacerEl) {
|
3634
|
+
const spacerHeight = boundaryInfo.elHeight;
|
3635
|
+
const spacerEl = document.createElement('div');
|
3636
|
+
spacerEl.id = boundaryInfo.spacerId;
|
3637
|
+
spacerEl.style.height = px(spacerHeight);
|
3638
|
+
/*istanbul ignore else*/
|
3639
|
+
if (el.parentNode) {
|
3640
|
+
el.parentNode.insertBefore(spacerEl, el.nextSibling);
|
3641
|
+
}
|
3642
|
+
}
|
3643
|
+
el.classList.add(CLS_VIEWKEEPER_FIXED);
|
3644
|
+
this.#currentElFixedTop = fixedStyles.elFixedTop;
|
3645
|
+
this.#currentElFixedLeft = fixedStyles.elFixedLeft;
|
3646
|
+
this.#currentElClipTop = fixedStyles.elClipTop;
|
3647
|
+
this.#currentElClipLeft = fixedStyles.elClipLeft;
|
3648
|
+
this.#currentElFixedWidth = fixedStyles.elFixedWidth;
|
3649
|
+
let width = 0;
|
3650
|
+
if (this.#setWidth) {
|
3651
|
+
width = fixedStyles.elFixedWidth;
|
3652
|
+
}
|
3653
|
+
setElPosition(el, fixedStyles.elFixedLeft, fixedStyles.elFixedTop, width, this.#viewportMarginTop, fixedStyles.elClipTop, fixedStyles.elClipLeft);
|
3654
|
+
}
|
3655
|
+
#getBoundaryInfo(el, boundaryEl) {
|
3656
|
+
const spacerId = this.#getSpacerId();
|
3657
|
+
const spacerEl = document.getElementById(spacerId);
|
3658
|
+
const boundaryOffset = getOffset(boundaryEl, this.#scrollableHost);
|
3659
|
+
const boundaryTop = boundaryOffset.top;
|
3660
|
+
const boundaryBottom = boundaryTop + boundaryEl.getBoundingClientRect().height;
|
3661
|
+
const scrollLeft = this.#scrollableHost
|
3662
|
+
? this.#scrollableHost.scrollLeft
|
3663
|
+
: document.documentElement.scrollLeft;
|
3664
|
+
const scrollTop = this.#scrollableHost
|
3665
|
+
? this.#scrollableHost.scrollTop
|
3666
|
+
: document.documentElement.scrollTop;
|
3667
|
+
const elHeight = getHeightWithMargin(el);
|
3668
|
+
return {
|
3669
|
+
boundaryBottom,
|
3670
|
+
boundaryOffset,
|
3671
|
+
boundaryEl,
|
3672
|
+
elHeight,
|
3673
|
+
scrollLeft,
|
3674
|
+
scrollTop,
|
3675
|
+
spacerId,
|
3676
|
+
spacerEl,
|
3677
|
+
};
|
3678
|
+
}
|
3679
|
+
}
|
3680
|
+
|
3681
|
+
/**
|
3682
|
+
* Provides methods for creating and destroying viewkeeper instances.
|
3683
|
+
*/
|
3684
|
+
class SkyViewkeeperService {
|
3685
|
+
#hostOptions;
|
3686
|
+
constructor(hostOptions) {
|
3687
|
+
this.#hostOptions = hostOptions;
|
3688
|
+
}
|
3689
|
+
/**
|
3690
|
+
*
|
3691
|
+
* @param options Creates a viewkeeper instance, applying host options where applicable.
|
3692
|
+
*/
|
3693
|
+
create(options) {
|
3694
|
+
options = Object.assign({}, this.#hostOptions || {}, options);
|
3695
|
+
return new SkyViewkeeper(options);
|
3696
|
+
}
|
3697
|
+
/**
|
3698
|
+
* Destroys a viewkeeper instance.
|
3699
|
+
* @param vk Viewkeeper instance to destroy.
|
3700
|
+
*/
|
3701
|
+
destroy(vk) {
|
3702
|
+
vk.destroy();
|
3703
|
+
}
|
3704
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperService, deps: [{ token: SkyViewkeeperHostOptions, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
3705
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperService, providedIn: 'root' }); }
|
3706
|
+
}
|
3707
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperService, decorators: [{
|
3708
|
+
type: Injectable,
|
3709
|
+
args: [{
|
3710
|
+
providedIn: 'root',
|
3711
|
+
}]
|
3712
|
+
}], ctorParameters: function () { return [{ type: SkyViewkeeperHostOptions, decorators: [{
|
3713
|
+
type: Optional
|
3714
|
+
}] }]; } });
|
3715
|
+
|
3716
|
+
class SkyViewkeeperDirective {
|
3717
|
+
set skyViewkeeper(value) {
|
3718
|
+
this.#_skyViewkeeper = value;
|
3719
|
+
this.#detectElements();
|
3720
|
+
}
|
3721
|
+
get skyViewkeeper() {
|
3722
|
+
return this.#_skyViewkeeper;
|
3723
|
+
}
|
3724
|
+
#_skyViewkeeper;
|
3725
|
+
#currentViewkeeperEls;
|
3726
|
+
#el;
|
3727
|
+
#mutationObserverSvc;
|
3728
|
+
#observer;
|
3729
|
+
#scrollableHostSvc;
|
3730
|
+
#scrollableHostWatchUnsubscribe;
|
3731
|
+
#viewkeepers = [];
|
3732
|
+
#viewkeeperSvc;
|
3733
|
+
constructor(el, mutationObserverSvc, viewkeeperSvc, scrollableHostSvc) {
|
3734
|
+
this.#el = el;
|
3735
|
+
this.#mutationObserverSvc = mutationObserverSvc;
|
3736
|
+
this.#viewkeeperSvc = viewkeeperSvc;
|
3737
|
+
this.#scrollableHostSvc = scrollableHostSvc;
|
3738
|
+
}
|
3739
|
+
ngOnInit() {
|
3740
|
+
this.#observer = this.#mutationObserverSvc.create(() => this.#detectElements());
|
3741
|
+
this.#observer.observe(this.#el.nativeElement, {
|
3742
|
+
childList: true,
|
3743
|
+
subtree: true,
|
3744
|
+
});
|
3745
|
+
}
|
3746
|
+
ngOnDestroy() {
|
3747
|
+
/*istanbul ignore else*/
|
3748
|
+
if (this.#observer) {
|
3749
|
+
this.#observer.disconnect();
|
3750
|
+
}
|
3751
|
+
/*istanbul ignore else*/
|
3752
|
+
if (this.#scrollableHostWatchUnsubscribe) {
|
3753
|
+
this.#scrollableHostWatchUnsubscribe.next();
|
3754
|
+
this.#scrollableHostWatchUnsubscribe.complete();
|
3755
|
+
}
|
3756
|
+
this.#destroyViewkeepers();
|
3757
|
+
}
|
3758
|
+
#destroyViewkeepers() {
|
3759
|
+
for (const viewkeeper of this.#viewkeepers) {
|
3760
|
+
this.#viewkeeperSvc.destroy(viewkeeper);
|
3761
|
+
}
|
3762
|
+
this.#viewkeepers = [];
|
3763
|
+
}
|
3764
|
+
#getViewkeeperEls() {
|
3765
|
+
let viewkeeperEls = [];
|
3766
|
+
if (this.skyViewkeeper) {
|
3767
|
+
viewkeeperEls = [];
|
3768
|
+
for (const item of this.skyViewkeeper) {
|
3769
|
+
const matchingEls = Array.from(this.#el.nativeElement.querySelectorAll(item));
|
3770
|
+
viewkeeperEls = [...viewkeeperEls, ...matchingEls];
|
3771
|
+
}
|
3772
|
+
}
|
3773
|
+
return viewkeeperEls;
|
3774
|
+
}
|
3775
|
+
#viewkeeperElsChanged(viewkeeperEls) {
|
3776
|
+
if (!viewkeeperEls !== !this.#currentViewkeeperEls) {
|
3777
|
+
return true;
|
3778
|
+
}
|
3779
|
+
if (viewkeeperEls && this.#currentViewkeeperEls) {
|
3780
|
+
if (viewkeeperEls.length !== this.#currentViewkeeperEls.length) {
|
3781
|
+
return true;
|
3782
|
+
}
|
3783
|
+
for (let i = 0, n = viewkeeperEls.length; i < n; i++) {
|
3784
|
+
if (viewkeeperEls[i] !== this.#currentViewkeeperEls[i]) {
|
3785
|
+
return true;
|
3786
|
+
}
|
3787
|
+
}
|
3788
|
+
}
|
3789
|
+
return false;
|
3790
|
+
}
|
3791
|
+
#detectElements() {
|
3792
|
+
const viewkeeperEls = this.#getViewkeeperEls();
|
3793
|
+
if (this.#viewkeeperElsChanged(viewkeeperEls)) {
|
3794
|
+
if (this.#scrollableHostWatchUnsubscribe) {
|
3795
|
+
this.#scrollableHostWatchUnsubscribe.next();
|
3796
|
+
this.#scrollableHostWatchUnsubscribe.complete();
|
3797
|
+
this.#scrollableHostWatchUnsubscribe = new Subject();
|
3798
|
+
}
|
3799
|
+
else {
|
3800
|
+
this.#scrollableHostWatchUnsubscribe = new Subject();
|
3801
|
+
}
|
3802
|
+
if (this.#scrollableHostSvc) {
|
3803
|
+
this.#scrollableHostSvc
|
3804
|
+
.watchScrollableHost(this.#el)
|
3805
|
+
.pipe(takeUntil(this.#scrollableHostWatchUnsubscribe))
|
3806
|
+
.subscribe((scrollableHost) => {
|
3807
|
+
this.#destroyViewkeepers();
|
3808
|
+
let previousViewkeeperEl;
|
3809
|
+
for (const viewkeeperEl of viewkeeperEls) {
|
3810
|
+
this.#viewkeepers.push(this.#viewkeeperSvc.create({
|
3811
|
+
boundaryEl: this.#el.nativeElement,
|
3812
|
+
scrollableHost: scrollableHost instanceof HTMLElement
|
3813
|
+
? scrollableHost
|
3814
|
+
: undefined,
|
3815
|
+
el: viewkeeperEl,
|
3816
|
+
setWidth: true,
|
3817
|
+
verticalOffsetEl: previousViewkeeperEl,
|
3818
|
+
}));
|
3819
|
+
previousViewkeeperEl = viewkeeperEl;
|
3820
|
+
}
|
3821
|
+
});
|
3822
|
+
}
|
3823
|
+
this.#currentViewkeeperEls = viewkeeperEls;
|
3824
|
+
}
|
3825
|
+
}
|
3826
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperDirective, deps: [{ token: i0.ElementRef }, { token: SkyMutationObserverService }, { token: SkyViewkeeperService }, { token: SkyScrollableHostService, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
|
3827
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: SkyViewkeeperDirective, selector: "[skyViewkeeper]", inputs: { skyViewkeeper: "skyViewkeeper" }, ngImport: i0 }); }
|
3828
|
+
}
|
3829
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperDirective, decorators: [{
|
3830
|
+
type: Directive,
|
3831
|
+
args: [{
|
3832
|
+
selector: '[skyViewkeeper]',
|
3833
|
+
}]
|
3834
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: SkyMutationObserverService }, { type: SkyViewkeeperService }, { type: SkyScrollableHostService, decorators: [{
|
3835
|
+
type: Optional
|
3836
|
+
}] }]; }, propDecorators: { skyViewkeeper: [{
|
3837
|
+
type: Input
|
3838
|
+
}] } });
|
3839
|
+
|
3840
|
+
class SkyViewkeeperModule {
|
3841
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
3842
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperModule, declarations: [SkyViewkeeperDirective], exports: [SkyViewkeeperDirective] }); }
|
3843
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperModule }); }
|
3844
|
+
}
|
3845
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: SkyViewkeeperModule, decorators: [{
|
3846
|
+
type: NgModule,
|
3847
|
+
args: [{
|
3848
|
+
declarations: [SkyViewkeeperDirective],
|
3849
|
+
exports: [SkyViewkeeperDirective],
|
3850
|
+
}]
|
3851
|
+
}] });
|
3852
|
+
|
3853
|
+
/**
|
3854
|
+
* Generated bundle index. Do not edit.
|
3855
|
+
*/
|
3856
|
+
|
3857
|
+
export { NumericOptions, SKY_LOG_LEVEL, SKY_STACKING_CONTEXT, SkyAffixAutoFitContext, SkyAffixModule, SkyAffixService, SkyAffixer, SkyAppFormat, SkyAppTitleService, SkyAppWindowRef, SkyCoreAdapterModule, SkyCoreAdapterService, SkyDefaultInputProvider, SkyDockItem, SkyDockLocation, SkyDockModule, SkyDockService, SkyDynamicComponentLocation, SkyDynamicComponentModule, SkyDynamicComponentService, SkyIdModule, SkyIdService, SkyLayoutHostService, SkyLiveAnnouncerService, SkyLogModule, SkyLogService, SkyMediaBreakpoints, SkyMediaQueryModule, SkyMediaQueryService, SkyMutationObserverService, SkyNumericModule, SkyNumericPipe, SkyNumericService, SkyOverlayInstance, SkyOverlayModule, SkyOverlayService, SkyPercentPipe, SkyPercentPipeModule, SkyResizeObserverMediaQueryService, SkyResizeObserverService, SkyScrollableHostService, SkyTrimModule, SkyUIConfigService, SkyViewkeeperHostOptions, SkyViewkeeperModule, SkyViewkeeperService, getWindow, SkyAffixDirective as λ1, SkyIdDirective as λ2, SkyViewkeeperDirective as λ3, SkyTrimDirective as λ4 };
|
3858
|
+
//# sourceMappingURL=skyux-core.mjs.map
|