@colijnit/corecomponents_v12 262.1.15 → 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';
@@ -9344,6 +9344,9 @@ class InputNumberPickerComponent extends BaseInputComponent {
9344
9344
  }
9345
9345
  handleInputKeyDown(event) {
9346
9346
  // event.preventDefault();
9347
+ if (this.readonly) {
9348
+ return false;
9349
+ }
9347
9350
  if (event.code === 'Enter' || event.code === 'NumpadEnter') {
9348
9351
  this.modelChange.next(this.model);
9349
9352
  return false;
@@ -18107,6 +18110,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18107
18110
  }]
18108
18111
  }] });
18109
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
+ ]);
18110
18123
  class TooltipComponent {
18111
18124
  _elementRef;
18112
18125
  _changeDetector;
@@ -18119,14 +18132,27 @@ class TooltipComponent {
18119
18132
  return this._hostElement;
18120
18133
  }
18121
18134
  toolTip;
18135
+ orientation = CoDirection.Up;
18122
18136
  tooltipClosed = new EventEmitter();
18123
18137
  showClass() {
18124
18138
  return true;
18125
18139
  }
18126
18140
  top = -100;
18127
18141
  left = -100;
18128
- 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
+ }
18129
18154
  animate = true;
18155
+ _resolvedOrientation = CoDirection.Up;
18130
18156
  _hostElement;
18131
18157
  _documentClickListener;
18132
18158
  constructor(_elementRef, _changeDetector, _renderer) {
@@ -18151,31 +18177,103 @@ class TooltipComponent {
18151
18177
  }
18152
18178
  }
18153
18179
  _positionTooltip() {
18154
- if (this.hostElement && this._elementRef && this._elementRef.nativeElement) {
18155
- const rect = this.hostElement.getBoundingClientRect();
18156
- const ownRect = this._elementRef.nativeElement.getBoundingClientRect();
18157
- let wantedLeft = rect.left;
18158
- let wantedTop = rect.top - ownRect.height;
18159
- if (wantedTop < 0) { // out of view, move to bottom
18160
- this.bottom = true;
18161
- wantedTop = rect.bottom;
18162
- }
18163
- else {
18164
- this.bottom = false;
18165
- }
18166
- this.left = wantedLeft;
18167
- this.top = wantedTop;
18168
- this._changeDetector.markForCheck();
18169
- this._changeDetector.detectChanges();
18180
+ if (!this.hostElement || !this._elementRef || !this._elementRef.nativeElement) {
18181
+ return;
18170
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;
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);
18171
18269
  }
18172
18270
  closeTooltip() {
18173
18271
  this.tooltipClosed.emit();
18174
18272
  }
18175
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 });
18176
- 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: `
18177
- <div class="tooltip" [innerHTML]="toolTip"></div>
18178
- `, 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: [
18179
18277
  trigger("showHide", [
18180
18278
  state("void", style({ opacity: 0 })),
18181
18279
  state("*", style({ opacity: 1 })),
@@ -18188,8 +18286,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18188
18286
  args: [{
18189
18287
  selector: 'co-tooltip',
18190
18288
  template: `
18191
- <div class="tooltip" [innerHTML]="toolTip"></div>
18192
- `,
18289
+ <div class="tooltip" [innerHTML]="toolTip"></div>
18290
+ `,
18193
18291
  animations: [
18194
18292
  trigger("showHide", [
18195
18293
  state("void", style({ opacity: 0 })),
@@ -18205,6 +18303,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18205
18303
  type: Input
18206
18304
  }], toolTip: [{
18207
18305
  type: Input
18306
+ }], orientation: [{
18307
+ type: Input
18208
18308
  }], tooltipClosed: [{
18209
18309
  type: Output
18210
18310
  }], showClass: [{
@@ -18216,14 +18316,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18216
18316
  }], left: [{
18217
18317
  type: HostBinding,
18218
18318
  args: ["style.left.px"]
18219
- }], bottom: [{
18319
+ }], isTop: [{
18320
+ type: HostBinding,
18321
+ args: ["class.top"]
18322
+ }], isBottom: [{
18220
18323
  type: HostBinding,
18221
18324
  args: ["class.bottom"]
18325
+ }], isLeft: [{
18326
+ type: HostBinding,
18327
+ args: ["class.left"]
18328
+ }], isRight: [{
18329
+ type: HostBinding,
18330
+ args: ["class.right"]
18222
18331
  }], animate: [{
18223
18332
  type: HostBinding,
18224
18333
  args: ['@showHide']
18225
18334
  }] } });
18226
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;
18227
18340
  class TooltipDirective {
18228
18341
  _compFactoryResolver;
18229
18342
  _appRef;
@@ -18232,9 +18345,15 @@ class TooltipDirective {
18232
18345
  set tooltip(str) {
18233
18346
  this._tooltipMessage = str;
18234
18347
  }
18348
+ orientation = CoDirection.Up;
18235
18349
  _elementRef;
18236
18350
  _tooltipMessage;
18237
18351
  _componentRef;
18352
+ _showTimeoutId = undefined;
18353
+ _autoHideTimeoutId = undefined;
18354
+ _mouseEnterHandler = () => this._startShowTimeout();
18355
+ _mouseLeaveHandler = () => this._removeTooltip();
18356
+ _scrollHandler = () => this._handleScroll();
18238
18357
  constructor(elementRef, _compFactoryResolver, _appRef, _injector, _sanitizer) {
18239
18358
  this._compFactoryResolver = _compFactoryResolver;
18240
18359
  this._appRef = _appRef;
@@ -18243,37 +18362,79 @@ class TooltipDirective {
18243
18362
  this._elementRef = elementRef;
18244
18363
  }
18245
18364
  ngOnDestroy() {
18365
+ this._removeTooltip();
18246
18366
  if (this._elementRef && this._elementRef.nativeElement) {
18247
- this._elementRef.nativeElement.removeEventListener('mouseenter', (event) => this._handleMouseMove(event));
18248
- this._elementRef.nativeElement.removeEventListener('mouseleave', () => this._removeTooltip());
18367
+ this._elementRef.nativeElement.removeEventListener('mouseenter', this._mouseEnterHandler);
18368
+ this._elementRef.nativeElement.removeEventListener('mouseleave', this._mouseLeaveHandler);
18249
18369
  }
18250
- window.removeEventListener("scroll", (event) => this._handleScroll);
18370
+ window.removeEventListener("scroll", this._scrollHandler);
18251
18371
  this._elementRef = undefined;
18252
18372
  }
18253
18373
  ngOnInit() {
18254
- window.addEventListener("scroll", (event) => this._handleScroll);
18374
+ window.addEventListener("scroll", this._scrollHandler);
18255
18375
  if (this._elementRef && this._elementRef.nativeElement) {
18256
- this._elementRef.nativeElement.addEventListener('mouseenter', (event) => this._handleMouseMove(event));
18257
- this._elementRef.nativeElement.addEventListener('mouseleave', () => this._removeTooltip());
18376
+ this._elementRef.nativeElement.addEventListener('mouseenter', this._mouseEnterHandler);
18377
+ this._elementRef.nativeElement.addEventListener('mouseleave', this._mouseLeaveHandler);
18258
18378
  }
18259
18379
  }
18260
18380
  _handleScroll() {
18261
18381
  this._removeTooltip();
18262
18382
  }
18263
- _handleMouseMove(event) {
18264
- 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));
18265
18389
  }
18266
- _showTooltip(top, left) {
18267
- 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
+ }
18268
18410
  }
18269
18411
  _removeTooltip() {
18412
+ this._clearShowTimeout();
18413
+ this._clearAutoHideTimeout();
18270
18414
  if (this._componentRef) {
18271
18415
  this._appRef.detachView(this._componentRef.hostView);
18272
18416
  this._componentRef.destroy();
18273
18417
  this._componentRef = undefined;
18274
18418
  }
18275
18419
  }
18276
- _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() {
18277
18438
  if (!this._tooltipMessage) {
18278
18439
  return;
18279
18440
  }
@@ -18284,13 +18445,15 @@ class TooltipDirective {
18284
18445
  .resolveComponentFactory(TooltipComponent)
18285
18446
  .create(this._injector);
18286
18447
  this._componentRef.instance.hostElement = this._elementRef.nativeElement;
18448
+ this._componentRef.instance.orientation = this.orientation;
18287
18449
  this._componentRef.instance.toolTip = this._sanitizer.bypassSecurityTrustHtml(this._tooltipMessage);
18288
18450
  this._appRef.attachView(this._componentRef.hostView);
18289
18451
  const domElem = this._componentRef.hostView.rootNodes[0];
18290
18452
  document.body.appendChild(domElem);
18453
+ this._startAutoHideTimeout();
18291
18454
  }
18292
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 });
18293
- 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 });
18294
18457
  }
18295
18458
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TooltipDirective, decorators: [{
18296
18459
  type: Directive,
@@ -18301,6 +18464,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18301
18464
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.DomSanitizer }], propDecorators: { tooltip: [{
18302
18465
  type: Input,
18303
18466
  args: ["tooltip"]
18467
+ }], orientation: [{
18468
+ type: Input,
18469
+ args: ["tooltipOrientation"]
18304
18470
  }] } });
18305
18471
 
18306
18472
  class TooltipModule {