@colijnit/corecomponents_v12 262.1.16 → 262.1.17

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.
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
- import { Input, Injectable, HostBinding, ViewEncapsulation, Component, Directive, ElementRef, Pipe, EventEmitter, Output, ViewChildren, ViewContainerRef, HostListener, ViewChild, Optional, NgModule, SkipSelf, InjectionToken, Inject, forwardRef, ChangeDetectionStrategy, ContentChildren, LOCALE_ID, NO_ERRORS_SCHEMA, Injector, QueryList } from '@angular/core';
3
+ import { Input, Injectable, HostBinding, ViewEncapsulation, Component, Directive, ElementRef, Pipe, EventEmitter, Output, ViewChildren, ViewContainerRef, HostListener, ViewChild, Optional, NgModule, SkipSelf, InjectionToken, Inject, forwardRef, ChangeDetectionStrategy, ContentChildren, LOCALE_ID, NO_ERRORS_SCHEMA, Injector, RendererStyleFlags2, QueryList } from '@angular/core';
4
4
  import * as i5 from '@angular/forms';
5
5
  import { NgModel, UntypedFormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
6
6
  import * as i1 from '@angular/platform-browser';
@@ -18110,6 +18110,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18110
18110
  }]
18111
18111
  }] });
18112
18112
 
18113
+ const ARROW_CENTER_PROPERTY = '--co-tooltip-arrow-center';
18114
+ const ARROW_EDGE_INSET_PX = 15;
18115
+ const VIEWPORT_MARGIN_PX = 5;
18116
+ const ORIENTATIONS = [CoDirection.Up, CoDirection.Down, CoDirection.Left, CoDirection.Right];
18117
+ const OPPOSITE_ORIENTATION = new Map([
18118
+ [CoDirection.Up, CoDirection.Down],
18119
+ [CoDirection.Down, CoDirection.Up],
18120
+ [CoDirection.Left, CoDirection.Right],
18121
+ [CoDirection.Right, CoDirection.Left]
18122
+ ]);
18113
18123
  class TooltipComponent {
18114
18124
  _elementRef;
18115
18125
  _changeDetector;
@@ -18122,14 +18132,27 @@ class TooltipComponent {
18122
18132
  return this._hostElement;
18123
18133
  }
18124
18134
  toolTip;
18135
+ orientation = CoDirection.Up;
18125
18136
  tooltipClosed = new EventEmitter();
18126
18137
  showClass() {
18127
18138
  return true;
18128
18139
  }
18129
18140
  top = -100;
18130
18141
  left = -100;
18131
- bottom = false;
18142
+ get isTop() {
18143
+ return this._resolvedOrientation === CoDirection.Up;
18144
+ }
18145
+ get isBottom() {
18146
+ return this._resolvedOrientation === CoDirection.Down;
18147
+ }
18148
+ get isLeft() {
18149
+ return this._resolvedOrientation === CoDirection.Left;
18150
+ }
18151
+ get isRight() {
18152
+ return this._resolvedOrientation === CoDirection.Right;
18153
+ }
18132
18154
  animate = true;
18155
+ _resolvedOrientation = CoDirection.Up;
18133
18156
  _hostElement;
18134
18157
  _documentClickListener;
18135
18158
  constructor(_elementRef, _changeDetector, _renderer) {
@@ -18154,31 +18177,103 @@ class TooltipComponent {
18154
18177
  }
18155
18178
  }
18156
18179
  _positionTooltip() {
18157
- if (this.hostElement && this._elementRef && this._elementRef.nativeElement) {
18158
- const rect = this.hostElement.getBoundingClientRect();
18159
- const ownRect = this._elementRef.nativeElement.getBoundingClientRect();
18160
- let wantedLeft = rect.left;
18161
- let wantedTop = rect.top - ownRect.height;
18162
- if (wantedTop < 0) { // out of view, move to bottom
18163
- this.bottom = true;
18164
- wantedTop = rect.bottom;
18165
- }
18166
- else {
18167
- this.bottom = false;
18168
- }
18169
- this.left = wantedLeft;
18170
- this.top = wantedTop;
18171
- this._changeDetector.markForCheck();
18172
- this._changeDetector.detectChanges();
18180
+ if (!this.hostElement || !this._elementRef || !this._elementRef.nativeElement) {
18181
+ return;
18182
+ }
18183
+ const element = this._elementRef.nativeElement;
18184
+ const hostRect = this.hostElement.getBoundingClientRect();
18185
+ this._resolvedOrientation = this._resolveOrientation(hostRect, element.getBoundingClientRect());
18186
+ // Apply the horizontal position first: it determines the available width, and therefore the height.
18187
+ this.left = this._calculateLeft(hostRect, element.getBoundingClientRect());
18188
+ this._changeDetector.detectChanges();
18189
+ const ownRect = element.getBoundingClientRect();
18190
+ this.top = this._calculateTop(hostRect, ownRect);
18191
+ this._positionArrow(hostRect, ownRect);
18192
+ this._changeDetector.markForCheck();
18193
+ this._changeDetector.detectChanges();
18194
+ }
18195
+ _resolveOrientation(hostRect, ownRect) {
18196
+ const preferred = ORIENTATIONS.indexOf(this.orientation) < 0 ? CoDirection.Up : this.orientation;
18197
+ const opposite = OPPOSITE_ORIENTATION.get(preferred);
18198
+ const candidates = [
18199
+ preferred,
18200
+ opposite,
18201
+ ...ORIENTATIONS.filter((orientation) => orientation !== preferred && orientation !== opposite)
18202
+ ];
18203
+ const fitting = candidates.find((orientation) => this._fits(orientation, hostRect, ownRect));
18204
+ if (fitting) {
18205
+ return fitting;
18206
+ }
18207
+ // Nothing fits: fall back to the side with the most room, so the tooltip overlaps the host as little as possible.
18208
+ return candidates.reduce((best, orientation) => this._availableSpace(orientation, hostRect) > this._availableSpace(best, hostRect) ? orientation : best, preferred);
18209
+ }
18210
+ _fits(orientation, hostRect, ownRect) {
18211
+ switch (orientation) {
18212
+ case CoDirection.Up:
18213
+ return (hostRect.top - ownRect.height) >= VIEWPORT_MARGIN_PX;
18214
+ case CoDirection.Down:
18215
+ return (hostRect.bottom + ownRect.height) <= (document.documentElement.clientHeight - VIEWPORT_MARGIN_PX);
18216
+ case CoDirection.Left:
18217
+ return (hostRect.left - ownRect.width) >= VIEWPORT_MARGIN_PX;
18218
+ default:
18219
+ return (hostRect.right + ownRect.width) <= (document.documentElement.clientWidth - VIEWPORT_MARGIN_PX);
18220
+ }
18221
+ }
18222
+ _availableSpace(orientation, hostRect) {
18223
+ switch (orientation) {
18224
+ case CoDirection.Up:
18225
+ return hostRect.top;
18226
+ case CoDirection.Down:
18227
+ return document.documentElement.clientHeight - hostRect.bottom;
18228
+ case CoDirection.Left:
18229
+ return hostRect.left;
18230
+ default:
18231
+ return document.documentElement.clientWidth - hostRect.right;
18232
+ }
18233
+ }
18234
+ _calculateLeft(hostRect, ownRect) {
18235
+ let wantedLeft = hostRect.left; // aligned with the host for the vertical orientations
18236
+ if (this._resolvedOrientation === CoDirection.Left) {
18237
+ wantedLeft = hostRect.left - ownRect.width;
18238
+ }
18239
+ else if (this._resolvedOrientation === CoDirection.Right) {
18240
+ wantedLeft = hostRect.right;
18241
+ }
18242
+ const maxLeft = document.documentElement.clientWidth - ownRect.width - VIEWPORT_MARGIN_PX;
18243
+ return Math.max(VIEWPORT_MARGIN_PX, Math.min(wantedLeft, maxLeft));
18244
+ }
18245
+ _calculateTop(hostRect, ownRect) {
18246
+ // Centred on the host for the horizontal orientations, so the arrow lands halfway up the edge
18247
+ // instead of being clamped against the top corner by hosts that are shorter than the tooltip.
18248
+ let wantedTop = hostRect.top + ((hostRect.height - ownRect.height) / 2);
18249
+ if (this._resolvedOrientation === CoDirection.Up) {
18250
+ wantedTop = hostRect.top - ownRect.height;
18173
18251
  }
18252
+ else if (this._resolvedOrientation === CoDirection.Down) {
18253
+ wantedTop = hostRect.bottom;
18254
+ }
18255
+ const maxTop = document.documentElement.clientHeight - ownRect.height - VIEWPORT_MARGIN_PX;
18256
+ return Math.max(VIEWPORT_MARGIN_PX, Math.min(wantedTop, maxTop));
18257
+ }
18258
+ _positionArrow(hostRect, ownRect) {
18259
+ const element = this._elementRef.nativeElement;
18260
+ const alongVerticalEdge = this.isLeft || this.isRight;
18261
+ const borderWidth = alongVerticalEdge ? element.clientTop : element.clientLeft;
18262
+ const paddingBoxSize = (alongVerticalEdge ? ownRect.height : ownRect.width) - (2 * borderWidth);
18263
+ const hostCenter = alongVerticalEdge
18264
+ ? (hostRect.top + (hostRect.height / 2)) - this.top - borderWidth
18265
+ : (hostRect.left + (hostRect.width / 2)) - this.left - borderWidth;
18266
+ const maxCenter = Math.max(ARROW_EDGE_INSET_PX, paddingBoxSize - ARROW_EDGE_INSET_PX);
18267
+ const arrowCenter = Math.min(Math.max(hostCenter, ARROW_EDGE_INSET_PX), maxCenter);
18268
+ this._renderer.setStyle(element, ARROW_CENTER_PROPERTY, `${arrowCenter}px`, RendererStyleFlags2.DashCase);
18174
18269
  }
18175
18270
  closeTooltip() {
18176
18271
  this.tooltipClosed.emit();
18177
18272
  }
18178
18273
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TooltipComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
18179
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: TooltipComponent, isStandalone: false, selector: "co-tooltip", inputs: { hostElement: "hostElement", toolTip: "toolTip" }, outputs: { tooltipClosed: "tooltipClosed" }, host: { properties: { "class.co-tooltip": "this.showClass", "style.top.px": "this.top", "style.left.px": "this.left", "class.bottom": "this.bottom", "@showHide": "this.animate" } }, ngImport: i0, template: `
18180
- <div class="tooltip" [innerHTML]="toolTip"></div>
18181
- `, isInline: true, animations: [
18274
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: TooltipComponent, isStandalone: false, selector: "co-tooltip", inputs: { hostElement: "hostElement", toolTip: "toolTip", orientation: "orientation" }, outputs: { tooltipClosed: "tooltipClosed" }, host: { properties: { "class.co-tooltip": "this.showClass", "style.top.px": "this.top", "style.left.px": "this.left", "class.top": "this.isTop", "class.bottom": "this.isBottom", "class.left": "this.isLeft", "class.right": "this.isRight", "@showHide": "this.animate" } }, ngImport: i0, template: `
18275
+ <div class="tooltip" [innerHTML]="toolTip"></div>
18276
+ `, isInline: true, animations: [
18182
18277
  trigger("showHide", [
18183
18278
  state("void", style({ opacity: 0 })),
18184
18279
  state("*", style({ opacity: 1 })),
@@ -18191,8 +18286,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18191
18286
  args: [{
18192
18287
  selector: 'co-tooltip',
18193
18288
  template: `
18194
- <div class="tooltip" [innerHTML]="toolTip"></div>
18195
- `,
18289
+ <div class="tooltip" [innerHTML]="toolTip"></div>
18290
+ `,
18196
18291
  animations: [
18197
18292
  trigger("showHide", [
18198
18293
  state("void", style({ opacity: 0 })),
@@ -18208,6 +18303,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18208
18303
  type: Input
18209
18304
  }], toolTip: [{
18210
18305
  type: Input
18306
+ }], orientation: [{
18307
+ type: Input
18211
18308
  }], tooltipClosed: [{
18212
18309
  type: Output
18213
18310
  }], showClass: [{
@@ -18219,14 +18316,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18219
18316
  }], left: [{
18220
18317
  type: HostBinding,
18221
18318
  args: ["style.left.px"]
18222
- }], bottom: [{
18319
+ }], isTop: [{
18320
+ type: HostBinding,
18321
+ args: ["class.top"]
18322
+ }], isBottom: [{
18223
18323
  type: HostBinding,
18224
18324
  args: ["class.bottom"]
18325
+ }], isLeft: [{
18326
+ type: HostBinding,
18327
+ args: ["class.left"]
18328
+ }], isRight: [{
18329
+ type: HostBinding,
18330
+ args: ["class.right"]
18225
18331
  }], animate: [{
18226
18332
  type: HostBinding,
18227
18333
  args: ['@showHide']
18228
18334
  }] } });
18229
18335
 
18336
+ const SHOW_DELAY_PROPERTY = '--co-tooltip-show-delay';
18337
+ const AUTO_HIDE_DELAY_PROPERTY = '--co-tooltip-auto-hide-delay';
18338
+ const DEFAULT_SHOW_DELAY_MS = 400;
18339
+ const DEFAULT_AUTO_HIDE_DELAY_MS = 10000;
18230
18340
  class TooltipDirective {
18231
18341
  _compFactoryResolver;
18232
18342
  _appRef;
@@ -18235,9 +18345,15 @@ class TooltipDirective {
18235
18345
  set tooltip(str) {
18236
18346
  this._tooltipMessage = str;
18237
18347
  }
18348
+ orientation = CoDirection.Up;
18238
18349
  _elementRef;
18239
18350
  _tooltipMessage;
18240
18351
  _componentRef;
18352
+ _showTimeoutId = undefined;
18353
+ _autoHideTimeoutId = undefined;
18354
+ _mouseEnterHandler = () => this._startShowTimeout();
18355
+ _mouseLeaveHandler = () => this._removeTooltip();
18356
+ _scrollHandler = () => this._handleScroll();
18241
18357
  constructor(elementRef, _compFactoryResolver, _appRef, _injector, _sanitizer) {
18242
18358
  this._compFactoryResolver = _compFactoryResolver;
18243
18359
  this._appRef = _appRef;
@@ -18246,37 +18362,79 @@ class TooltipDirective {
18246
18362
  this._elementRef = elementRef;
18247
18363
  }
18248
18364
  ngOnDestroy() {
18365
+ this._removeTooltip();
18249
18366
  if (this._elementRef && this._elementRef.nativeElement) {
18250
- this._elementRef.nativeElement.removeEventListener('mouseenter', (event) => this._handleMouseMove(event));
18251
- this._elementRef.nativeElement.removeEventListener('mouseleave', () => this._removeTooltip());
18367
+ this._elementRef.nativeElement.removeEventListener('mouseenter', this._mouseEnterHandler);
18368
+ this._elementRef.nativeElement.removeEventListener('mouseleave', this._mouseLeaveHandler);
18252
18369
  }
18253
- window.removeEventListener("scroll", (event) => this._handleScroll);
18370
+ window.removeEventListener("scroll", this._scrollHandler);
18254
18371
  this._elementRef = undefined;
18255
18372
  }
18256
18373
  ngOnInit() {
18257
- window.addEventListener("scroll", (event) => this._handleScroll);
18374
+ window.addEventListener("scroll", this._scrollHandler);
18258
18375
  if (this._elementRef && this._elementRef.nativeElement) {
18259
- this._elementRef.nativeElement.addEventListener('mouseenter', (event) => this._handleMouseMove(event));
18260
- this._elementRef.nativeElement.addEventListener('mouseleave', () => this._removeTooltip());
18376
+ this._elementRef.nativeElement.addEventListener('mouseenter', this._mouseEnterHandler);
18377
+ this._elementRef.nativeElement.addEventListener('mouseleave', this._mouseLeaveHandler);
18261
18378
  }
18262
18379
  }
18263
18380
  _handleScroll() {
18264
18381
  this._removeTooltip();
18265
18382
  }
18266
- _handleMouseMove(event) {
18267
- this._showTooltip(event.clientY, event.clientX);
18383
+ _startShowTimeout() {
18384
+ this._clearShowTimeout();
18385
+ this._showTimeoutId = window.setTimeout(() => {
18386
+ this._showTimeoutId = undefined;
18387
+ this._createTooltipComponent();
18388
+ }, this._resolveDelay(SHOW_DELAY_PROPERTY, DEFAULT_SHOW_DELAY_MS));
18268
18389
  }
18269
- _showTooltip(top, left) {
18270
- this._createTooltipComponent(top, left);
18390
+ // Delays come from custom properties, read from the host so a scoped override wins over the
18391
+ // :root default; falls back when the stylesheet is absent. A bare number is read as milliseconds.
18392
+ _resolveDelay(property, fallback) {
18393
+ if (!this._elementRef || !this._elementRef.nativeElement) {
18394
+ return fallback;
18395
+ }
18396
+ const raw = window.getComputedStyle(this._elementRef.nativeElement)
18397
+ .getPropertyValue(property)
18398
+ .trim();
18399
+ const value = parseFloat(raw);
18400
+ if (isNaN(value)) {
18401
+ return fallback;
18402
+ }
18403
+ return Math.max(0, raw.endsWith('ms') || !raw.endsWith('s') ? value : value * 1000);
18404
+ }
18405
+ _clearShowTimeout() {
18406
+ if (this._showTimeoutId !== undefined) {
18407
+ window.clearTimeout(this._showTimeoutId);
18408
+ this._showTimeoutId = undefined;
18409
+ }
18271
18410
  }
18272
18411
  _removeTooltip() {
18412
+ this._clearShowTimeout();
18413
+ this._clearAutoHideTimeout();
18273
18414
  if (this._componentRef) {
18274
18415
  this._appRef.detachView(this._componentRef.hostView);
18275
18416
  this._componentRef.destroy();
18276
18417
  this._componentRef = undefined;
18277
18418
  }
18278
18419
  }
18279
- _createTooltipComponent(top, left) {
18420
+ _startAutoHideTimeout() {
18421
+ this._clearAutoHideTimeout();
18422
+ const delay = this._resolveDelay(AUTO_HIDE_DELAY_PROPERTY, DEFAULT_AUTO_HIDE_DELAY_MS);
18423
+ if (delay <= 0) { // guard switched off by the consumer
18424
+ return;
18425
+ }
18426
+ this._autoHideTimeoutId = window.setTimeout(() => {
18427
+ this._autoHideTimeoutId = undefined;
18428
+ this._removeTooltip();
18429
+ }, delay);
18430
+ }
18431
+ _clearAutoHideTimeout() {
18432
+ if (this._autoHideTimeoutId !== undefined) {
18433
+ window.clearTimeout(this._autoHideTimeoutId);
18434
+ this._autoHideTimeoutId = undefined;
18435
+ }
18436
+ }
18437
+ _createTooltipComponent() {
18280
18438
  if (!this._tooltipMessage) {
18281
18439
  return;
18282
18440
  }
@@ -18287,13 +18445,15 @@ class TooltipDirective {
18287
18445
  .resolveComponentFactory(TooltipComponent)
18288
18446
  .create(this._injector);
18289
18447
  this._componentRef.instance.hostElement = this._elementRef.nativeElement;
18448
+ this._componentRef.instance.orientation = this.orientation;
18290
18449
  this._componentRef.instance.toolTip = this._sanitizer.bypassSecurityTrustHtml(this._tooltipMessage);
18291
18450
  this._appRef.attachView(this._componentRef.hostView);
18292
18451
  const domElem = this._componentRef.hostView.rootNodes[0];
18293
18452
  document.body.appendChild(domElem);
18453
+ this._startAutoHideTimeout();
18294
18454
  }
18295
18455
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TooltipDirective, deps: [{ token: i0.ElementRef }, { token: i0.ComponentFactoryResolver }, { token: i0.ApplicationRef }, { token: i0.Injector }, { token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Directive });
18296
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: TooltipDirective, isStandalone: false, selector: "[tooltip]", inputs: { tooltip: "tooltip" }, ngImport: i0 });
18456
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: TooltipDirective, isStandalone: false, selector: "[tooltip]", inputs: { tooltip: "tooltip", orientation: ["tooltipOrientation", "orientation"] }, ngImport: i0 });
18297
18457
  }
18298
18458
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TooltipDirective, decorators: [{
18299
18459
  type: Directive,
@@ -18304,6 +18464,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18304
18464
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.DomSanitizer }], propDecorators: { tooltip: [{
18305
18465
  type: Input,
18306
18466
  args: ["tooltip"]
18467
+ }], orientation: [{
18468
+ type: Input,
18469
+ args: ["tooltipOrientation"]
18307
18470
  }] } });
18308
18471
 
18309
18472
  class TooltipModule {