@libs-ui/components-popover 0.1.1-1

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.
@@ -0,0 +1,653 @@
1
+ import * as i0 from '@angular/core';
2
+ import { signal, viewChild, inject, ElementRef, ChangeDetectionStrategy, Component, input, output, effect, untracked } from '@angular/core';
3
+ import { LibsUiDynamicComponentService } from '@libs-ui/services-dynamic-component';
4
+ import { UtilsUrlSearchParams, get, cloneIBoundingClientRect, cloneDeep, getViewport, getEventNameHandleClick, checkMouseOverInContainer, set, isNil } from '@libs-ui/utils';
5
+ import { Subject, interval, take, takeUntil, Subscription, fromEvent } from 'rxjs';
6
+ import { debounceTime, tap, takeUntil as takeUntil$1 } from 'rxjs/operators';
7
+ import { NgStyle, AsyncPipe, NgTemplateOutlet } from '@angular/common';
8
+ import { LibsUiComponentsScrollOverlayDirective } from '@libs-ui/components-scroll-overlay';
9
+ import * as i1 from '@ngx-translate/core';
10
+ import { TranslateModule } from '@ngx-translate/core';
11
+
12
+ const KEY_QUERY_POPOVER_TIMER_DESTROY = 'popover-timer-destroy';
13
+ const timerDestroy = parseInt(new UtilsUrlSearchParams(location.href).get(KEY_QUERY_POPOVER_TIMER_DESTROY) || '0');
14
+ const getPopoverTimerDestroyInQueryUrl = () => {
15
+ return timerDestroy;
16
+ };
17
+ const getListDirections = (direction) => {
18
+ return get({
19
+ bottom: ['bottom', 'top', 'right', 'left'],
20
+ right: ['right', 'left', 'bottom', 'top'],
21
+ left: ['left', 'right', 'bottom', 'top'],
22
+ top: ['top', 'bottom', 'right', 'left'],
23
+ }, direction);
24
+ };
25
+
26
+ class LibsUiComponentsPopoverOverlayComponent {
27
+ /* PROPERTIES */
28
+ currentDirection = signal('bottom');
29
+ arrowClass = signal('');
30
+ top = signal(0);
31
+ left = signal(0);
32
+ arrowLeft = signal(0);
33
+ arrowTop = signal(0);
34
+ config = signal({});
35
+ timeout = signal(0);
36
+ onDestroy = new Subject();
37
+ // #region OUTPUT
38
+ outEvent = new Subject();
39
+ /* VIEW CHILD */
40
+ container = viewChild.required('container');
41
+ // #region INJECT
42
+ elementRef = inject(ElementRef);
43
+ // #region FUNCTIONS
44
+ get ElementRef() {
45
+ return this.elementRef;
46
+ }
47
+ get ContainerElement() {
48
+ return this.container().nativeElement;
49
+ }
50
+ setConfig(rectOrigin, config, isAddContentToParentDocument) {
51
+ isAddContentToParentDocument = isAddContentToParentDocument || config.isAddContentToParentDocument;
52
+ rectOrigin = cloneIBoundingClientRect(rectOrigin);
53
+ this.config.set(cloneDeep(config));
54
+ this.container().nativeElement.style.opacity = 0;
55
+ if (this.config().widthByParent) {
56
+ this.config.update((config) => ({ ...config, width: rectOrigin.width - (config?.parentBorderWidth || 0) * 2 }));
57
+ }
58
+ let viewPort = getViewport();
59
+ let rectFrame = undefined;
60
+ if (isAddContentToParentDocument) {
61
+ viewPort = getViewport(window.parent);
62
+ const url = new UtilsUrlSearchParams(location.href);
63
+ const iframeId = url.get('iframeId');
64
+ rectFrame = window.parent.document.getElementById(`iframe-${iframeId}`)?.getBoundingClientRect();
65
+ if (rectFrame) {
66
+ rectOrigin.top += rectFrame.top;
67
+ rectOrigin.left += rectFrame.left;
68
+ }
69
+ }
70
+ if (this.config().maxHeight === null) {
71
+ this.config.update((config) => ({ ...config, maxHeight: viewPort.height - rectOrigin.top - 44 }));
72
+ }
73
+ clearTimeout(this.timeout());
74
+ this.setVariableCss();
75
+ this.setDirections(rectOrigin, viewPort, rectFrame);
76
+ let rectContent = cloneIBoundingClientRect(this.container().nativeElement.getBoundingClientRect());
77
+ if (rectFrame) {
78
+ rectContent.top += rectFrame.top;
79
+ rectContent.left += rectFrame.left;
80
+ }
81
+ interval(250)
82
+ .pipe(take(4), takeUntil(this.onDestroy))
83
+ .subscribe(() => {
84
+ const rect = cloneIBoundingClientRect(this.container().nativeElement.getBoundingClientRect());
85
+ if (rectFrame) {
86
+ rect.top += rectFrame.top;
87
+ rect.left += rectFrame.left;
88
+ }
89
+ if (rect.width !== rectContent.width || rect.height !== rectContent.height || rect.top !== rectContent.top || rect.left !== rectContent.left) {
90
+ clearTimeout(this.timeout());
91
+ this.setDirections(rectOrigin, viewPort, rectFrame);
92
+ rectContent = rect;
93
+ }
94
+ });
95
+ }
96
+ setDirections(rectOrigin, viewPort, rectFrame) {
97
+ const directions = getListDirections(this.config().direction || 'bottom');
98
+ const positionLast = directions.length - 1;
99
+ this.timeout.set(setTimeout(async () => {
100
+ const rectContent = cloneIBoundingClientRect(this.container().nativeElement.getBoundingClientRect());
101
+ if (rectFrame) {
102
+ rectContent.top += rectFrame.top;
103
+ rectContent.left += rectFrame.left;
104
+ }
105
+ for (const index in directions) {
106
+ if (await this.loopDirection(rectOrigin, rectContent, directions[index], positionLast === +index, viewPort)) {
107
+ return;
108
+ }
109
+ }
110
+ const directionByHeight = viewPort.height - rectOrigin.top - rectOrigin.height > rectOrigin.top - 4 ? 'bottom' : 'top';
111
+ this.loopDirection(rectOrigin, rectContent, directionByHeight, true, viewPort);
112
+ }, 50));
113
+ }
114
+ loopDirection(rectOrigin, rectContent, direction, isLast, viewPort) {
115
+ return new Promise((resolve) => {
116
+ const positionMode = this.config().position?.mode || 'start';
117
+ const { position } = this.config();
118
+ let result = this.setPosition(direction, rectOrigin, rectContent, viewPort, isLast);
119
+ if (!result) {
120
+ if (position) {
121
+ position.mode = positionMode === 'center' || positionMode === 'start' ? 'end' : 'start';
122
+ if (!this.config().ignoreArrow && position.autoUpdatePosition) {
123
+ position.distance = position.mode === 'end' ? position.autoUpdatePosition.endDistance : position.autoUpdatePosition.startDistance;
124
+ }
125
+ this.config.update((config) => ({ ...config }));
126
+ }
127
+ result = this.setPosition(direction, rectOrigin, rectContent, viewPort, isLast);
128
+ }
129
+ if (!result && positionMode === 'center') {
130
+ if (position) {
131
+ position.mode = position.mode === 'start' ? 'end' : 'start';
132
+ this.config.update((config) => ({ ...config }));
133
+ }
134
+ result = this.setPosition(direction, rectOrigin, rectContent, viewPort, isLast);
135
+ }
136
+ if (!result) {
137
+ if (position) {
138
+ position.mode = positionMode;
139
+ this.config.update((config) => ({ ...config }));
140
+ }
141
+ return resolve(false);
142
+ }
143
+ this.currentDirection.set(direction);
144
+ this.setVariableCss();
145
+ this.setClassArrow(direction);
146
+ this.container().nativeElement.style.opacity = 1;
147
+ this.outEvent.next(direction);
148
+ return resolve(true);
149
+ });
150
+ }
151
+ setPosition(direction, rectOrigin, rectContent, viewPort, isLast) {
152
+ const halfSquare = 6;
153
+ const distanceArrow = 4;
154
+ let bottomPositionRectContent = 0;
155
+ let positionTop = 0;
156
+ let positionLeft = 0;
157
+ let top = 0;
158
+ let left = 0;
159
+ const configValue = this.config();
160
+ switch (direction) {
161
+ case 'bottom':
162
+ positionTop = rectOrigin.top + rectOrigin.height + distanceArrow;
163
+ positionLeft = rectOrigin.left + rectOrigin.width / 2 - halfSquare;
164
+ top = positionTop + halfSquare;
165
+ left = positionLeft - rectContent.width / 2 + halfSquare;
166
+ if (configValue.ignoreArrow) {
167
+ top = top - halfSquare - distanceArrow;
168
+ }
169
+ top += configValue.directionDistance || 0;
170
+ if (configValue.position?.mode === 'start') {
171
+ left = rectOrigin.left + (configValue.position.distance || 0);
172
+ }
173
+ if (configValue.position?.mode === 'end') {
174
+ left = rectOrigin.left + rectOrigin.width - rectContent.width + (configValue.position.distance || 0);
175
+ }
176
+ left += configValue.parentBorderWidth || 0;
177
+ this.arrowLeft.set(positionLeft - left);
178
+ this.arrowTop.set(-6);
179
+ this.top.set(top);
180
+ this.left.set(left);
181
+ if (top + rectContent.height < viewPort.height && left >= 0 && left + rectContent.width < viewPort.width) {
182
+ return true;
183
+ }
184
+ if (isLast) {
185
+ if (this.config) {
186
+ this.config.update((config) => ({ ...config, maxHeight: viewPort.height - rectOrigin.top - rectOrigin.height }));
187
+ }
188
+ this.left.set(this.getLeftPositionIsLast(isLast, left >= 0 ? left : 0, viewPort, rectOrigin, rectContent, halfSquare));
189
+ return true;
190
+ }
191
+ return false;
192
+ case 'right':
193
+ positionTop = rectOrigin.top + rectOrigin.height / 2 - halfSquare;
194
+ positionLeft = rectOrigin.left + rectOrigin.width + distanceArrow;
195
+ top = positionTop - rectContent.height / 2 + halfSquare;
196
+ left = positionLeft + halfSquare;
197
+ if (configValue.ignoreArrow) {
198
+ left = positionLeft - distanceArrow;
199
+ }
200
+ left += configValue.directionDistance || 0;
201
+ if (configValue.position?.mode === 'start') {
202
+ top = rectOrigin.top + (configValue.position?.distance || 0);
203
+ }
204
+ if (configValue.position?.mode === 'end') {
205
+ top = rectOrigin.top + rectOrigin.height - rectContent.height + (configValue.position.distance || 0);
206
+ }
207
+ bottomPositionRectContent = top + rectContent.height;
208
+ if (bottomPositionRectContent > viewPort.height) {
209
+ top = top - (bottomPositionRectContent - viewPort.height);
210
+ }
211
+ this.arrowTop.set(positionTop - top + 2);
212
+ this.arrowLeft.set(-9);
213
+ this.top.set(top);
214
+ this.left.set(left);
215
+ if (top > 0 && left + rectContent.width < viewPort.width) {
216
+ return true;
217
+ }
218
+ if (isLast) {
219
+ if (this.config) {
220
+ this.config.update((config) => ({ ...config, maxHeight: viewPort.height }));
221
+ }
222
+ this.left.set(this.getLeftPositionIsLast(isLast, left >= 0 ? left : 0, viewPort, rectOrigin, rectContent, halfSquare));
223
+ return true;
224
+ }
225
+ return false;
226
+ case 'left':
227
+ positionTop = rectOrigin.top + rectOrigin.height / 2 - halfSquare;
228
+ positionLeft = rectOrigin.left - halfSquare * 2 - distanceArrow;
229
+ top = positionTop - rectContent.height / 2 + halfSquare;
230
+ left = positionLeft - rectContent.width + halfSquare;
231
+ if (configValue.ignoreArrow) {
232
+ left = left + halfSquare + distanceArrow;
233
+ }
234
+ left -= configValue?.directionDistance || 0;
235
+ if (configValue.position?.mode === 'start') {
236
+ top = rectOrigin.top + (configValue.position.distance || 0);
237
+ }
238
+ if (configValue.position?.mode === 'end') {
239
+ top = rectOrigin.top + rectOrigin.height - rectContent.height + (configValue.position.distance || 0);
240
+ }
241
+ bottomPositionRectContent = top + rectContent.height;
242
+ if (bottomPositionRectContent > viewPort.height) {
243
+ top = top - (bottomPositionRectContent - viewPort.height);
244
+ }
245
+ this.arrowTop.set(positionTop - top + 2);
246
+ this.arrowLeft.set(rectContent.width - 3);
247
+ this.top.set(top);
248
+ this.left.set(left);
249
+ if (left > 0 && top > 0) {
250
+ return true;
251
+ }
252
+ if (isLast) {
253
+ if (this.config) {
254
+ this.config.update((config) => ({ ...config, maxHeight: viewPort.height }));
255
+ }
256
+ this.left.set(this.getLeftPositionIsLast(isLast, left >= 0 ? left : 0, viewPort, rectOrigin, rectContent, halfSquare));
257
+ return true;
258
+ }
259
+ return false;
260
+ case 'top':
261
+ positionTop = rectOrigin.top - halfSquare * 2 - distanceArrow;
262
+ positionLeft = rectOrigin.left + rectOrigin.width / 2 - halfSquare;
263
+ top = positionTop - rectContent.height + halfSquare;
264
+ left = positionLeft - rectContent.width / 2 + halfSquare;
265
+ if (configValue.ignoreArrow) {
266
+ top = top + halfSquare + distanceArrow;
267
+ }
268
+ top -= configValue.directionDistance || 0;
269
+ if (configValue.position && configValue.position?.mode === 'start') {
270
+ left = rectOrigin.left + (configValue.position.distance || 0);
271
+ }
272
+ if (configValue.position && configValue.position?.mode === 'end') {
273
+ left = rectOrigin.left + rectOrigin.width - rectContent.width + (configValue.position.distance || 0);
274
+ }
275
+ left += configValue.parentBorderWidth || 0;
276
+ this.arrowLeft.set(positionLeft - left);
277
+ this.arrowTop.set(rectContent.height);
278
+ this.top.set(top);
279
+ this.left.set(left);
280
+ if (top > 0 && left >= 0 && left + rectContent.width < viewPort.width) {
281
+ return true;
282
+ }
283
+ if (isLast) {
284
+ this.config.update((config) => ({ ...config, maxHeight: rectOrigin.top - 4 }));
285
+ top = 0;
286
+ this.left.set(this.getLeftPositionIsLast(isLast, left >= 0 ? left : 0, viewPort, rectOrigin, rectContent, halfSquare));
287
+ return true;
288
+ }
289
+ return false;
290
+ }
291
+ }
292
+ setClassArrow(direction) {
293
+ if (direction === 'right') {
294
+ return this.arrowClass.set('libs-ui-popover-overlay-arrow-right');
295
+ }
296
+ if (direction === 'left') {
297
+ return this.arrowClass.set('libs-ui-popover-overlay-arrow-left');
298
+ }
299
+ if (direction === 'top') {
300
+ return this.arrowClass.set('libs-ui-popover-overlay-arrow-down');
301
+ }
302
+ return this.arrowClass.set('libs-ui-popover-overlay-arrow-up');
303
+ }
304
+ setVariableCss() {
305
+ const configValue = this.config();
306
+ this.ContainerElement.style.setProperty('--libs-ui-popover-overlay-time-animation-time', `${configValue.animationConfig?.time || 0.4}s`);
307
+ this.ContainerElement.style.setProperty('--libs-ui-popover-overlay-time-animation-distance', `${this.currentDirection() === 'top' ? '-' : ''}${configValue.animationConfig?.distance || 12}px`);
308
+ }
309
+ getLeftPositionIsLast(isLast, currentLeft, viewPort, rectOrigin, rectContent, halfSquare) {
310
+ if (viewPort.width - (rectOrigin.left + rectOrigin.width + rectContent.width + halfSquare) > 0) {
311
+ return rectOrigin.left + rectOrigin.width + halfSquare;
312
+ }
313
+ return currentLeft;
314
+ }
315
+ ngOnDestroy() {
316
+ clearTimeout(this.timeout());
317
+ this.onDestroy.next();
318
+ this.onDestroy.complete();
319
+ }
320
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPopoverOverlayComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
321
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: LibsUiComponentsPopoverOverlayComponent, isStandalone: true, selector: "libs_ui-components-popover-overlay", viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true, isSignal: true }], ngImport: i0, template: "<div\n #container\n class=\"libs-ui-popover-overlay {{ config().classInclude || '' }}\"\n [class.libs-ui-popover-overlay-white-theme]=\"config().whiteTheme\"\n [class.libs-ui-popover-overlay-animation-move]=\"config().animationConfig\"\n [ngStyle]=\"config().ngStyles || {}\"\n [style.width]=\"config().width ? config().width + 'px' : 'auto'\"\n [style.maxWidth.px]=\"config().maxWidth\"\n [style.maxHeight.px]=\"config().maxHeight\"\n [style.top.px]=\"top()\"\n [style.left.px]=\"left()\"\n [style.zIndex]=\"config().zIndex || 10\">\n @if (config()) {\n @if (!config().ignoreArrow) {\n <div class=\"relative\">\n <svg\n [class]=\"'libs-ui-popover-overlay-arrow ' + arrowClass() + (config().whiteTheme ? ' libs-ui-popover-overlay-white-theme ' : '')\"\n [style.top.px]=\"arrowTop()\"\n [style.left.px]=\"arrowLeft()\"\n [attr.direction]=\"outEvent | async\">\n <polygon points=\"0,0 6,6 12,0\" />\n Sorry, your browser does not support inline SVG.\n </svg>\n </div>\n }\n @if (config().template; as templateConfig) {\n <div\n LibsUiComponentsScrollOverlayDirective\n class=\"libs-ui-popover-overlay-body {{ config().classIncludeOverlayBody || '' }}\"\n [attr.isTemplate]=\"true\"\n [style.max-height]=\"config().maxHeight + 'px'\">\n <ng-container *ngTemplateOutlet=\"templateConfig; context: { itemContext: config().itemContext }\" />\n </div>\n } @else {\n @let constHtmlContent = config().content || ' ';\n <div\n class=\"libs-ui-popover-overlay-body libs-ui-font-h7r {{ config().classIncludeOverlayBody || '' }}\"\n LibsUiComponentsScrollOverlayDirective\n [options]=\"config().scrollOverlayOptions\"\n [style.maxHeight.px]=\"config().maxHeight\"\n [style.paddingTop.px]=\"config().paddingTop ?? 8\"\n [style.paddingRight.px]=\"config().paddingRight ?? 8\"\n [style.paddingLeft.px]=\"config().paddingLeft ?? 8\"\n [style.paddingBottom.px]=\"config().paddingBottom ?? 8\"\n [innerHtml]=\"constHtmlContent | translate\"></div>\n }\n }\n</div>\n", styles: ["@-webkit-keyframes animation-move{0%{transform:translateY(var(--libs-ui-popover-overlay-time-animation-distance))}to{transform:translateY(0)}}@keyframes animation-move{0%{transform:translateY(var(--libs-ui-popover-overlay-time-animation-distance))}to{transform:translateY(0)}}.libs-ui-popover-overlay{position:fixed;background-color:#071631;border-radius:8px;z-index:1000;top:-10000px;left:-10000px}.libs-ui-popover-overlay-animation-move{animation:animation-move ease var(--libs-ui-popover-overlay-time-animation-time)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow{position:absolute;width:12px;height:6px;fill:#071631}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=bottom]{transform:rotate(180deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=left]{transform:rotate(270deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=right]{transform:rotate(90deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-white-theme{fill:#fff}.libs-ui-popover-overlay .libs-ui-popover-overlay-body{color:#fff;word-break:break-word}.libs-ui-popover-overlay .libs-ui-popover-overlay-body[isTemplate=true]{font-size:inherit}.libs-ui-popover-overlay.libs-ui-popover-overlay-white-theme{background-color:#fff;box-shadow:0 1px 1px #00143305,0 4px 16px #0014331a}.libs-ui-popover-overlay.libs-ui-popover-overlay-white-theme .libs-ui-popover-overlay-body{color:#071631}\n"], dependencies: [{ kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i1.TranslatePipe, name: "translate" }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "directive", type: LibsUiComponentsScrollOverlayDirective, selector: "[LibsUiComponentsScrollOverlayDirective]", inputs: ["debugMode", "ignoreInit", "classContainer", "options", "elementCheckScrollX", "elementCheckScrollY", "elementScroll"], outputs: ["outScroll", "outScrollX", "outScrollY", "outScrollTop", "outScrollBottom"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
322
+ }
323
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPopoverOverlayComponent, decorators: [{
324
+ type: Component,
325
+ args: [{ selector: 'libs_ui-components-popover-overlay', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [TranslateModule, NgStyle, AsyncPipe, LibsUiComponentsScrollOverlayDirective, NgTemplateOutlet], template: "<div\n #container\n class=\"libs-ui-popover-overlay {{ config().classInclude || '' }}\"\n [class.libs-ui-popover-overlay-white-theme]=\"config().whiteTheme\"\n [class.libs-ui-popover-overlay-animation-move]=\"config().animationConfig\"\n [ngStyle]=\"config().ngStyles || {}\"\n [style.width]=\"config().width ? config().width + 'px' : 'auto'\"\n [style.maxWidth.px]=\"config().maxWidth\"\n [style.maxHeight.px]=\"config().maxHeight\"\n [style.top.px]=\"top()\"\n [style.left.px]=\"left()\"\n [style.zIndex]=\"config().zIndex || 10\">\n @if (config()) {\n @if (!config().ignoreArrow) {\n <div class=\"relative\">\n <svg\n [class]=\"'libs-ui-popover-overlay-arrow ' + arrowClass() + (config().whiteTheme ? ' libs-ui-popover-overlay-white-theme ' : '')\"\n [style.top.px]=\"arrowTop()\"\n [style.left.px]=\"arrowLeft()\"\n [attr.direction]=\"outEvent | async\">\n <polygon points=\"0,0 6,6 12,0\" />\n Sorry, your browser does not support inline SVG.\n </svg>\n </div>\n }\n @if (config().template; as templateConfig) {\n <div\n LibsUiComponentsScrollOverlayDirective\n class=\"libs-ui-popover-overlay-body {{ config().classIncludeOverlayBody || '' }}\"\n [attr.isTemplate]=\"true\"\n [style.max-height]=\"config().maxHeight + 'px'\">\n <ng-container *ngTemplateOutlet=\"templateConfig; context: { itemContext: config().itemContext }\" />\n </div>\n } @else {\n @let constHtmlContent = config().content || ' ';\n <div\n class=\"libs-ui-popover-overlay-body libs-ui-font-h7r {{ config().classIncludeOverlayBody || '' }}\"\n LibsUiComponentsScrollOverlayDirective\n [options]=\"config().scrollOverlayOptions\"\n [style.maxHeight.px]=\"config().maxHeight\"\n [style.paddingTop.px]=\"config().paddingTop ?? 8\"\n [style.paddingRight.px]=\"config().paddingRight ?? 8\"\n [style.paddingLeft.px]=\"config().paddingLeft ?? 8\"\n [style.paddingBottom.px]=\"config().paddingBottom ?? 8\"\n [innerHtml]=\"constHtmlContent | translate\"></div>\n }\n }\n</div>\n", styles: ["@-webkit-keyframes animation-move{0%{transform:translateY(var(--libs-ui-popover-overlay-time-animation-distance))}to{transform:translateY(0)}}@keyframes animation-move{0%{transform:translateY(var(--libs-ui-popover-overlay-time-animation-distance))}to{transform:translateY(0)}}.libs-ui-popover-overlay{position:fixed;background-color:#071631;border-radius:8px;z-index:1000;top:-10000px;left:-10000px}.libs-ui-popover-overlay-animation-move{animation:animation-move ease var(--libs-ui-popover-overlay-time-animation-time)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow{position:absolute;width:12px;height:6px;fill:#071631}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=bottom]{transform:rotate(180deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=left]{transform:rotate(270deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-arrow[direction=right]{transform:rotate(90deg)}.libs-ui-popover-overlay .libs-ui-popover-overlay-white-theme{fill:#fff}.libs-ui-popover-overlay .libs-ui-popover-overlay-body{color:#fff;word-break:break-word}.libs-ui-popover-overlay .libs-ui-popover-overlay-body[isTemplate=true]{font-size:inherit}.libs-ui-popover-overlay.libs-ui-popover-overlay-white-theme{background-color:#fff;box-shadow:0 1px 1px #00143305,0 4px 16px #0014331a}.libs-ui-popover-overlay.libs-ui-popover-overlay-white-theme .libs-ui-popover-overlay-body{color:#071631}\n"] }]
326
+ }] });
327
+
328
+ /* eslint-disable @typescript-eslint/no-explicit-any */
329
+ class LibsUiComponentsPopoverComponent {
330
+ // #region PROPERTY
331
+ mouseEnter;
332
+ mouseWheel;
333
+ mouseClick;
334
+ windowResize;
335
+ windowWheel;
336
+ windowMouseDown;
337
+ windowClick;
338
+ windowMouseUp;
339
+ windowMousemove;
340
+ popoverOverlayComponent;
341
+ subsEventPopup = new Subscription();
342
+ onDestroy = new Subject();
343
+ functionsControl;
344
+ firstClick = signal(false);
345
+ contentInnerHtml = signal('');
346
+ timer = signal(undefined);
347
+ directionPopover = signal(undefined);
348
+ frameId = signal('');
349
+ // #region INPUT
350
+ debugId = input();
351
+ flagMouse = input({ isMouseEnter: false, isMouseEnterContent: false, isContainerHasScroll: false }, {
352
+ transform: (value) => (value ? value : { isMouseEnter: false, isMouseEnterContent: false, isContainerHasScroll: false }),
353
+ });
354
+ type = input('other');
355
+ mode = input('hover');
356
+ config = input({}, { transform: (value) => (value ? value : {}) });
357
+ ignoreShowPopover = input();
358
+ elementRefCustom = input();
359
+ initEventInElementRefCustom = input(false);
360
+ classInclude = input('', { transform: (value) => value ?? '' });
361
+ ignoreHiddenPopoverContentWhenMouseLeave = input();
362
+ ignoreStopPropagationEvent = input();
363
+ ignoreCursorPointerModeLikeClick = input();
364
+ isAddContentToParentDocument = input();
365
+ ignoreClickOutside = input();
366
+ // #region OUTPUT
367
+ outEvent = output();
368
+ outChangStageFlagMouse = output();
369
+ outEventPopoverContent = output();
370
+ outFunctionsControl = output();
371
+ // #region INJECT
372
+ elementRef = inject(ElementRef);
373
+ dynamicService = inject(LibsUiDynamicComponentService);
374
+ constructor() {
375
+ let classDefault = undefined;
376
+ effect(() => {
377
+ if (classDefault === undefined) {
378
+ classDefault = this.Element.className;
379
+ }
380
+ if (this.elementRefCustom() !== this.Element) {
381
+ this.Element.className = classDefault || '';
382
+ }
383
+ if (this.type() === 'text') {
384
+ this.Element.classList.add('popover-text-ellipsis');
385
+ }
386
+ if (this.mode().includes('click') && !this.ignoreCursorPointerModeLikeClick()) {
387
+ this.Element.classList.add('cursor-pointer');
388
+ }
389
+ if (this.classInclude()) {
390
+ this.classInclude()
391
+ ?.split(' ')
392
+ .forEach((className) => {
393
+ if (!className) {
394
+ return;
395
+ }
396
+ this.Element.classList.add(className);
397
+ });
398
+ }
399
+ });
400
+ let first = true;
401
+ effect(() => {
402
+ this.config();
403
+ untracked(() => {
404
+ if (this.popoverOverlayComponent?.instance && !first) {
405
+ this.updatePopoverOverlayPosition();
406
+ }
407
+ first = false;
408
+ });
409
+ });
410
+ }
411
+ ngOnInit() {
412
+ this.outEventPopoverContent.subscribe((direction) => this.directionPopover.set(direction));
413
+ this.functionsControl = {
414
+ removePopoverOverlay: this.removePopoverOverlay.bind(this),
415
+ updatePopoverOverlayPosition: this.updatePopoverOverlayPosition.bind(this),
416
+ getRectContainer: async () => (this.elementRefCustom() || this.Element).getBoundingClientRect(),
417
+ getRectContent: async () => this.popoverOverlayComponent?.instance?.ContainerElement?.getBoundingClientRect(),
418
+ showPopover: this.addPopoverContent.bind(this),
419
+ updatePopoverOverlay: this.updatePopoverOverlay.bind(this),
420
+ };
421
+ this.outFunctionsControl.emit(this.FunctionsControl);
422
+ }
423
+ ngAfterContentInit() {
424
+ const nativeEl = this.Element;
425
+ this.mouseEnter = this.initObservable(nativeEl, 'mouseenter');
426
+ this.initObservable(nativeEl, 'click').subscribe();
427
+ this.mouseClick = this.initObservable(nativeEl, getEventNameHandleClick);
428
+ this.mouseWheel = this.initObservable(window, 'wheel');
429
+ this.windowResize = this.initObservable(window, 'resize');
430
+ this.windowWheel = this.initObservable(window, 'wheel');
431
+ this.windowMouseDown = this.initObservable(window, 'mousedown');
432
+ this.windowClick = this.initObservable(window, getEventNameHandleClick);
433
+ this.windowMouseUp = this.initObservable(window, 'mouseup');
434
+ this.windowMousemove = this.initObservable(window, 'mousemove');
435
+ this.mouseEnter.subscribe(() => {
436
+ if (!this.mode().includes('hover')) {
437
+ return;
438
+ }
439
+ if (this.type() === 'text' && nativeEl?.clientWidth >= nativeEl.scrollWidth && !this.popoverOverlayComponent) {
440
+ return;
441
+ }
442
+ this.addPopoverContent();
443
+ });
444
+ this.mouseClick.subscribe(() => {
445
+ this.firstClick.update((val) => (this.ignoreShowPopover() ? false : !val));
446
+ this.outEvent.emit('click');
447
+ if (!this.mode().startsWith('click')) {
448
+ return;
449
+ }
450
+ if (this.mode() === 'click-toggle' && !this.firstClick()) {
451
+ this.removePopoverOverlay();
452
+ return;
453
+ }
454
+ this.addPopoverContent();
455
+ });
456
+ this.windowResize.pipe(debounceTime(500)).subscribe(this.updatePopoverOverlayPosition.bind(this));
457
+ }
458
+ // #region FUNCTIONS
459
+ get FunctionsControl() {
460
+ return this.functionsControl;
461
+ }
462
+ async updatePopoverOverlay() {
463
+ const timer = setTimeout(() => {
464
+ clearTimeout(timer);
465
+ if (!this.popoverOverlayComponent || !this.popoverOverlayComponent.instance || !this.config()) {
466
+ return;
467
+ }
468
+ const instance = this.popoverOverlayComponent.instance;
469
+ const nativeEl = this.elementRefCustom() || this.Element;
470
+ instance.setConfig(nativeEl.getBoundingClientRect(), { ...(this.config() || {}), ...this.getDefaultConfigs() }, this.isAddContentToParentDocument());
471
+ });
472
+ }
473
+ async updatePopoverOverlayPosition() {
474
+ clearTimeout(this.timer());
475
+ this.timer.set(setTimeout(async () => {
476
+ if (!this.popoverOverlayComponent || !this.popoverOverlayComponent.instance || !this.config() || !this.functionsControl) {
477
+ return;
478
+ }
479
+ const viewPort = getViewport();
480
+ const rectListView = await this.functionsControl.getRectContent();
481
+ if (!rectListView) {
482
+ return;
483
+ }
484
+ const rectContainer = await this.functionsControl.getRectContainer();
485
+ const distanceListViewAndContainer = this.config()?.ignoreArrow === false ? 14 : 4;
486
+ switch (this.directionPopover()) {
487
+ case 'right':
488
+ case 'left':
489
+ case 'bottom':
490
+ if (rectListView.top + rectListView.height > viewPort.height ||
491
+ rectListView.top < rectContainer.top + rectContainer.height ||
492
+ rectListView.top - (rectContainer.top + rectContainer.height) > distanceListViewAndContainer ||
493
+ rectListView.left + rectListView.width > viewPort.width) {
494
+ this.updatePopoverOverlay();
495
+ }
496
+ break;
497
+ case 'top':
498
+ if (rectContainer.top - (rectListView.top + rectListView.height) > distanceListViewAndContainer ||
499
+ rectListView.top + rectListView.height + distanceListViewAndContainer > rectContainer.top + 2 ||
500
+ rectListView.left + rectListView.width > viewPort.width) {
501
+ this.updatePopoverOverlay();
502
+ }
503
+ break;
504
+ }
505
+ }, 250));
506
+ }
507
+ get Element() {
508
+ if (this.initEventInElementRefCustom() && this.elementRefCustom()) {
509
+ return this.elementRefCustom();
510
+ }
511
+ return this.elementRef.nativeElement.firstElementChild || this.elementRef.nativeElement;
512
+ }
513
+ initObservable(el, eventName) {
514
+ return fromEvent(el, eventName).pipe(tap((e) => !this.ignoreStopPropagationEvent() && e.stopPropagation()), takeUntil$1(this.onDestroy));
515
+ }
516
+ async addPopoverContent(nativeEl) {
517
+ if (this.popoverOverlayComponent || this.ignoreShowPopover() || !this.config()) {
518
+ return;
519
+ }
520
+ this.popoverOverlayComponent = this.dynamicService.resolveComponentFactory(LibsUiComponentsPopoverOverlayComponent);
521
+ this.frameId.set(this.dynamicService.addToBody(this.popoverOverlayComponent, this.isAddContentToParentDocument() || this.config().isAddContentToParentDocument));
522
+ this.outEvent.emit('show');
523
+ const instance = this.popoverOverlayComponent.instance;
524
+ nativeEl = nativeEl || this.elementRefCustom() || this.Element;
525
+ instance.setConfig(nativeEl.getBoundingClientRect(), { ...(this.config() || {}), ...this.getDefaultConfigs() }, this.isAddContentToParentDocument());
526
+ const flagsMouses = {
527
+ isMouseEnter: true,
528
+ isMouseEnterContent: false,
529
+ isContainerHasScroll: nativeEl.offsetHeight < nativeEl.scrollHeight,
530
+ };
531
+ const nativeElContainer = instance.ElementRef.nativeElement;
532
+ const mouseEnterContent = this.initObservable(nativeElContainer, 'mouseenter');
533
+ const mouseLeaveContent = this.initObservable(nativeElContainer, 'mouseleave');
534
+ this.subsEventPopup.add(instance.outEvent.subscribe((direction) => {
535
+ this.outEventPopoverContent.emit(direction);
536
+ }));
537
+ this.subsEventPopup.add(mouseEnterContent.subscribe(() => {
538
+ this.outEvent.emit('mouseenter-content');
539
+ flagsMouses.isMouseEnterContent = true;
540
+ this.outChangStageFlagMouse.emit(flagsMouses);
541
+ }));
542
+ this.subsEventPopup.add(this.mouseEnter.subscribe(() => {
543
+ this.outEvent.emit('mouseenter-element');
544
+ this.outChangStageFlagMouse.emit(flagsMouses);
545
+ }));
546
+ this.subsEventPopup.add(this.mouseWheel.subscribe(() => {
547
+ flagsMouses.isContainerHasScroll = false;
548
+ if (nativeEl.offsetHeight < nativeEl.scrollHeight) {
549
+ flagsMouses.isContainerHasScroll = true;
550
+ }
551
+ if ((flagsMouses.isMouseEnter && flagsMouses.isContainerHasScroll) || flagsMouses.isMouseEnterContent || this.flagMouse().isMouseEnter || this.flagMouse().isMouseEnterContent) {
552
+ return;
553
+ }
554
+ this.removePopoverOverlay();
555
+ }));
556
+ this.handlerMouseLeaveRemovePopoverOverlay(this.windowMousemove, flagsMouses, 'isMouseEnter', 'isMouseEnterContent', 'mouseleave-element');
557
+ this.handlerMouseLeaveRemovePopoverOverlay(mouseLeaveContent, flagsMouses, 'isMouseEnterContent', 'isMouseEnter', 'mouseleave-content');
558
+ if (this.mode() === 'click_open_and_click_panel_content_hidden') {
559
+ this.subsEventPopup.add(this.initObservable(nativeElContainer, 'click').subscribe(() => {
560
+ this.removePopoverOverlay();
561
+ }));
562
+ }
563
+ this.handlerWindowEventRemovePopoverOverlay(this.windowClick, flagsMouses);
564
+ this.handlerWindowEventRemovePopoverOverlay(this.windowMouseDown, flagsMouses);
565
+ this.handlerWindowEventRemovePopoverOverlay(this.windowMouseUp, flagsMouses);
566
+ this.handlerWindowEventRemovePopoverOverlay(this.windowWheel, flagsMouses);
567
+ }
568
+ handlerWindowEventRemovePopoverOverlay(obs, flagsMouses) {
569
+ this.subsEventPopup.add(obs.pipe(debounceTime(10)).subscribe(() => {
570
+ if (flagsMouses.isMouseEnter || flagsMouses.isMouseEnterContent || this.ignoreClickOutside()) {
571
+ return;
572
+ }
573
+ if (this.flagMouse() && (this.flagMouse().isMouseEnter || this.flagMouse().isMouseEnterContent)) {
574
+ return;
575
+ }
576
+ this.firstClick.set(false);
577
+ this.removePopoverOverlay();
578
+ }));
579
+ }
580
+ handlerMouseLeaveRemovePopoverOverlay(obs, flagsMouses, flagKeyChangeValue, flagKeyCheck, outEvent) {
581
+ this.subsEventPopup.add(obs
582
+ .pipe(tap(() => this.outEvent.emit(outEvent)), debounceTime(getPopoverTimerDestroyInQueryUrl() || this.config()?.timerDestroy || 0))
583
+ .subscribe((e) => {
584
+ if (outEvent === 'mouseleave-element' &&
585
+ (checkMouseOverInContainer(e, this.Element) || checkMouseOverInContainer({ clientX: e.clientX + 2, clientY: e.clientY + 2 }, this.Element) || checkMouseOverInContainer({ clientX: e.clientX - 2, clientY: e.clientY - 2 }, this.Element))) {
586
+ return;
587
+ }
588
+ set(flagsMouses, flagKeyChangeValue, false);
589
+ this.outChangStageFlagMouse.emit(flagsMouses);
590
+ if (this.flagMouse() && (this.flagMouse().isMouseEnter || this.flagMouse().isMouseEnterContent)) {
591
+ return;
592
+ }
593
+ if (get(flagsMouses, flagKeyCheck) || this.ignoreHiddenPopoverContentWhenMouseLeave()) {
594
+ return;
595
+ }
596
+ this.removePopoverOverlay();
597
+ }));
598
+ }
599
+ getDefaultConfigs() {
600
+ const configValue = this.config() || {};
601
+ if (isNil(configValue.content) || (configValue.content === this.contentInnerHtml() && this.contentInnerHtml() !== this.Element.innerHTML)) {
602
+ configValue.content = this.Element.innerHTML;
603
+ }
604
+ this.contentInnerHtml.set(this.Element.innerHTML);
605
+ if (!configValue.maxWidth) {
606
+ configValue.maxWidth = 250;
607
+ }
608
+ if (configValue.maxHeight === undefined || configValue.maxHeight === 0) {
609
+ configValue.maxHeight = 140;
610
+ }
611
+ if (!configValue.direction) {
612
+ configValue.direction = 'bottom';
613
+ }
614
+ if (!configValue.position) {
615
+ configValue.position = {
616
+ mode: 'center',
617
+ distance: 0,
618
+ };
619
+ }
620
+ return configValue;
621
+ }
622
+ async removePopoverOverlay() {
623
+ if (this.popoverOverlayComponent) {
624
+ this.outEvent.emit('remove');
625
+ this.subsEventPopup.unsubscribe();
626
+ this.subsEventPopup = new Subscription();
627
+ }
628
+ this.dynamicService.remove(this.popoverOverlayComponent, this.frameId());
629
+ this.frameId.set('');
630
+ this.popoverOverlayComponent = undefined;
631
+ this.firstClick.set(false);
632
+ }
633
+ ngOnDestroy() {
634
+ clearTimeout(this.timer());
635
+ this.removePopoverOverlay();
636
+ this.onDestroy.next();
637
+ this.onDestroy.complete();
638
+ this.subsEventPopup.unsubscribe();
639
+ }
640
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPopoverComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
641
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "18.2.14", type: LibsUiComponentsPopoverComponent, isStandalone: true, selector: "libs_ui-components-popover,[LibsUiComponentsPopoverDirective]", inputs: { debugId: { classPropertyName: "debugId", publicName: "debugId", isSignal: true, isRequired: false, transformFunction: null }, flagMouse: { classPropertyName: "flagMouse", publicName: "flagMouse", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, ignoreShowPopover: { classPropertyName: "ignoreShowPopover", publicName: "ignoreShowPopover", isSignal: true, isRequired: false, transformFunction: null }, elementRefCustom: { classPropertyName: "elementRefCustom", publicName: "elementRefCustom", isSignal: true, isRequired: false, transformFunction: null }, initEventInElementRefCustom: { classPropertyName: "initEventInElementRefCustom", publicName: "initEventInElementRefCustom", isSignal: true, isRequired: false, transformFunction: null }, classInclude: { classPropertyName: "classInclude", publicName: "classInclude", isSignal: true, isRequired: false, transformFunction: null }, ignoreHiddenPopoverContentWhenMouseLeave: { classPropertyName: "ignoreHiddenPopoverContentWhenMouseLeave", publicName: "ignoreHiddenPopoverContentWhenMouseLeave", isSignal: true, isRequired: false, transformFunction: null }, ignoreStopPropagationEvent: { classPropertyName: "ignoreStopPropagationEvent", publicName: "ignoreStopPropagationEvent", isSignal: true, isRequired: false, transformFunction: null }, ignoreCursorPointerModeLikeClick: { classPropertyName: "ignoreCursorPointerModeLikeClick", publicName: "ignoreCursorPointerModeLikeClick", isSignal: true, isRequired: false, transformFunction: null }, isAddContentToParentDocument: { classPropertyName: "isAddContentToParentDocument", publicName: "isAddContentToParentDocument", isSignal: true, isRequired: false, transformFunction: null }, ignoreClickOutside: { classPropertyName: "ignoreClickOutside", publicName: "ignoreClickOutside", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { outEvent: "outEvent", outChangStageFlagMouse: "outChangStageFlagMouse", outEventPopoverContent: "outEventPopoverContent", outFunctionsControl: "outFunctionsControl" }, ngImport: i0, template: "<ng-content />\n", styles: ["::ng-deep .popover-text-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}::ng-deep .cursor-pointer{cursor:pointer}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
642
+ }
643
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LibsUiComponentsPopoverComponent, decorators: [{
644
+ type: Component,
645
+ args: [{ selector: 'libs_ui-components-popover,[LibsUiComponentsPopoverDirective]', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-content />\n", styles: ["::ng-deep .popover-text-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}::ng-deep .cursor-pointer{cursor:pointer}\n"] }]
646
+ }], ctorParameters: () => [] });
647
+
648
+ /**
649
+ * Generated bundle index. Do not edit.
650
+ */
651
+
652
+ export { KEY_QUERY_POPOVER_TIMER_DESTROY, LibsUiComponentsPopoverComponent, getListDirections, getPopoverTimerDestroyInQueryUrl };
653
+ //# sourceMappingURL=libs-ui-components-popover.mjs.map