@colijnit/corecomponents_v12 261.20.18 → 261.20.20

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';
@@ -9337,6 +9337,9 @@ class InputNumberPickerComponent extends BaseInputComponent {
9337
9337
  }
9338
9338
  handleInputKeyDown(event) {
9339
9339
  // event.preventDefault();
9340
+ if (this.readonly) {
9341
+ return false;
9342
+ }
9340
9343
  if (event.code === 'Enter' || event.code === 'NumpadEnter') {
9341
9344
  this.modelChange.next(this.model);
9342
9345
  return false;
@@ -18043,6 +18046,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18043
18046
  }]
18044
18047
  }] });
18045
18048
 
18049
+ const ARROW_CENTER_PROPERTY = '--co-tooltip-arrow-center';
18050
+ const ARROW_EDGE_INSET_PX = 15;
18051
+ const VIEWPORT_MARGIN_PX = 5;
18052
+ const ORIENTATIONS = [CoDirection.Up, CoDirection.Down, CoDirection.Left, CoDirection.Right];
18053
+ const OPPOSITE_ORIENTATION = new Map([
18054
+ [CoDirection.Up, CoDirection.Down],
18055
+ [CoDirection.Down, CoDirection.Up],
18056
+ [CoDirection.Left, CoDirection.Right],
18057
+ [CoDirection.Right, CoDirection.Left]
18058
+ ]);
18046
18059
  class TooltipComponent {
18047
18060
  _elementRef;
18048
18061
  _changeDetector;
@@ -18055,14 +18068,27 @@ class TooltipComponent {
18055
18068
  return this._hostElement;
18056
18069
  }
18057
18070
  toolTip;
18071
+ orientation = CoDirection.Up;
18058
18072
  tooltipClosed = new EventEmitter();
18059
18073
  showClass() {
18060
18074
  return true;
18061
18075
  }
18062
18076
  top = -100;
18063
18077
  left = -100;
18064
- bottom = false;
18078
+ get isTop() {
18079
+ return this._resolvedOrientation === CoDirection.Up;
18080
+ }
18081
+ get isBottom() {
18082
+ return this._resolvedOrientation === CoDirection.Down;
18083
+ }
18084
+ get isLeft() {
18085
+ return this._resolvedOrientation === CoDirection.Left;
18086
+ }
18087
+ get isRight() {
18088
+ return this._resolvedOrientation === CoDirection.Right;
18089
+ }
18065
18090
  animate = true;
18091
+ _resolvedOrientation = CoDirection.Up;
18066
18092
  _hostElement;
18067
18093
  _documentClickListener;
18068
18094
  constructor(_elementRef, _changeDetector, _renderer) {
@@ -18087,31 +18113,103 @@ class TooltipComponent {
18087
18113
  }
18088
18114
  }
18089
18115
  _positionTooltip() {
18090
- if (this.hostElement && this._elementRef && this._elementRef.nativeElement) {
18091
- const rect = this.hostElement.getBoundingClientRect();
18092
- const ownRect = this._elementRef.nativeElement.getBoundingClientRect();
18093
- let wantedLeft = rect.left;
18094
- let wantedTop = rect.top - ownRect.height;
18095
- if (wantedTop < 0) { // out of view, move to bottom
18096
- this.bottom = true;
18097
- wantedTop = rect.bottom;
18098
- }
18099
- else {
18100
- this.bottom = false;
18101
- }
18102
- this.left = wantedLeft;
18103
- this.top = wantedTop;
18104
- this._changeDetector.markForCheck();
18105
- this._changeDetector.detectChanges();
18116
+ if (!this.hostElement || !this._elementRef || !this._elementRef.nativeElement) {
18117
+ return;
18106
18118
  }
18119
+ const element = this._elementRef.nativeElement;
18120
+ const hostRect = this.hostElement.getBoundingClientRect();
18121
+ this._resolvedOrientation = this._resolveOrientation(hostRect, element.getBoundingClientRect());
18122
+ // Apply the horizontal position first: it determines the available width, and therefore the height.
18123
+ this.left = this._calculateLeft(hostRect, element.getBoundingClientRect());
18124
+ this._changeDetector.detectChanges();
18125
+ const ownRect = element.getBoundingClientRect();
18126
+ this.top = this._calculateTop(hostRect, ownRect);
18127
+ this._positionArrow(hostRect, ownRect);
18128
+ this._changeDetector.markForCheck();
18129
+ this._changeDetector.detectChanges();
18130
+ }
18131
+ _resolveOrientation(hostRect, ownRect) {
18132
+ const preferred = ORIENTATIONS.indexOf(this.orientation) < 0 ? CoDirection.Up : this.orientation;
18133
+ const opposite = OPPOSITE_ORIENTATION.get(preferred);
18134
+ const candidates = [
18135
+ preferred,
18136
+ opposite,
18137
+ ...ORIENTATIONS.filter((orientation) => orientation !== preferred && orientation !== opposite)
18138
+ ];
18139
+ const fitting = candidates.find((orientation) => this._fits(orientation, hostRect, ownRect));
18140
+ if (fitting) {
18141
+ return fitting;
18142
+ }
18143
+ // Nothing fits: fall back to the side with the most room, so the tooltip overlaps the host as little as possible.
18144
+ return candidates.reduce((best, orientation) => this._availableSpace(orientation, hostRect) > this._availableSpace(best, hostRect) ? orientation : best, preferred);
18145
+ }
18146
+ _fits(orientation, hostRect, ownRect) {
18147
+ switch (orientation) {
18148
+ case CoDirection.Up:
18149
+ return (hostRect.top - ownRect.height) >= VIEWPORT_MARGIN_PX;
18150
+ case CoDirection.Down:
18151
+ return (hostRect.bottom + ownRect.height) <= (document.documentElement.clientHeight - VIEWPORT_MARGIN_PX);
18152
+ case CoDirection.Left:
18153
+ return (hostRect.left - ownRect.width) >= VIEWPORT_MARGIN_PX;
18154
+ default:
18155
+ return (hostRect.right + ownRect.width) <= (document.documentElement.clientWidth - VIEWPORT_MARGIN_PX);
18156
+ }
18157
+ }
18158
+ _availableSpace(orientation, hostRect) {
18159
+ switch (orientation) {
18160
+ case CoDirection.Up:
18161
+ return hostRect.top;
18162
+ case CoDirection.Down:
18163
+ return document.documentElement.clientHeight - hostRect.bottom;
18164
+ case CoDirection.Left:
18165
+ return hostRect.left;
18166
+ default:
18167
+ return document.documentElement.clientWidth - hostRect.right;
18168
+ }
18169
+ }
18170
+ _calculateLeft(hostRect, ownRect) {
18171
+ let wantedLeft = hostRect.left; // aligned with the host for the vertical orientations
18172
+ if (this._resolvedOrientation === CoDirection.Left) {
18173
+ wantedLeft = hostRect.left - ownRect.width;
18174
+ }
18175
+ else if (this._resolvedOrientation === CoDirection.Right) {
18176
+ wantedLeft = hostRect.right;
18177
+ }
18178
+ const maxLeft = document.documentElement.clientWidth - ownRect.width - VIEWPORT_MARGIN_PX;
18179
+ return Math.max(VIEWPORT_MARGIN_PX, Math.min(wantedLeft, maxLeft));
18180
+ }
18181
+ _calculateTop(hostRect, ownRect) {
18182
+ // Centred on the host for the horizontal orientations, so the arrow lands halfway up the edge
18183
+ // instead of being clamped against the top corner by hosts that are shorter than the tooltip.
18184
+ let wantedTop = hostRect.top + ((hostRect.height - ownRect.height) / 2);
18185
+ if (this._resolvedOrientation === CoDirection.Up) {
18186
+ wantedTop = hostRect.top - ownRect.height;
18187
+ }
18188
+ else if (this._resolvedOrientation === CoDirection.Down) {
18189
+ wantedTop = hostRect.bottom;
18190
+ }
18191
+ const maxTop = document.documentElement.clientHeight - ownRect.height - VIEWPORT_MARGIN_PX;
18192
+ return Math.max(VIEWPORT_MARGIN_PX, Math.min(wantedTop, maxTop));
18193
+ }
18194
+ _positionArrow(hostRect, ownRect) {
18195
+ const element = this._elementRef.nativeElement;
18196
+ const alongVerticalEdge = this.isLeft || this.isRight;
18197
+ const borderWidth = alongVerticalEdge ? element.clientTop : element.clientLeft;
18198
+ const paddingBoxSize = (alongVerticalEdge ? ownRect.height : ownRect.width) - (2 * borderWidth);
18199
+ const hostCenter = alongVerticalEdge
18200
+ ? (hostRect.top + (hostRect.height / 2)) - this.top - borderWidth
18201
+ : (hostRect.left + (hostRect.width / 2)) - this.left - borderWidth;
18202
+ const maxCenter = Math.max(ARROW_EDGE_INSET_PX, paddingBoxSize - ARROW_EDGE_INSET_PX);
18203
+ const arrowCenter = Math.min(Math.max(hostCenter, ARROW_EDGE_INSET_PX), maxCenter);
18204
+ this._renderer.setStyle(element, ARROW_CENTER_PROPERTY, `${arrowCenter}px`, RendererStyleFlags2.DashCase);
18107
18205
  }
18108
18206
  closeTooltip() {
18109
18207
  this.tooltipClosed.emit();
18110
18208
  }
18111
18209
  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 });
18112
- 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: `
18113
- <div class="tooltip" [innerHTML]="toolTip"></div>
18114
- `, isInline: true, animations: [
18210
+ 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: `
18211
+ <div class="tooltip" [innerHTML]="toolTip"></div>
18212
+ `, isInline: true, animations: [
18115
18213
  trigger("showHide", [
18116
18214
  state("void", style({ opacity: 0 })),
18117
18215
  state("*", style({ opacity: 1 })),
@@ -18124,8 +18222,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18124
18222
  args: [{
18125
18223
  selector: 'co-tooltip',
18126
18224
  template: `
18127
- <div class="tooltip" [innerHTML]="toolTip"></div>
18128
- `,
18225
+ <div class="tooltip" [innerHTML]="toolTip"></div>
18226
+ `,
18129
18227
  animations: [
18130
18228
  trigger("showHide", [
18131
18229
  state("void", style({ opacity: 0 })),
@@ -18141,6 +18239,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18141
18239
  type: Input
18142
18240
  }], toolTip: [{
18143
18241
  type: Input
18242
+ }], orientation: [{
18243
+ type: Input
18144
18244
  }], tooltipClosed: [{
18145
18245
  type: Output
18146
18246
  }], showClass: [{
@@ -18152,14 +18252,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18152
18252
  }], left: [{
18153
18253
  type: HostBinding,
18154
18254
  args: ["style.left.px"]
18155
- }], bottom: [{
18255
+ }], isTop: [{
18256
+ type: HostBinding,
18257
+ args: ["class.top"]
18258
+ }], isBottom: [{
18156
18259
  type: HostBinding,
18157
18260
  args: ["class.bottom"]
18261
+ }], isLeft: [{
18262
+ type: HostBinding,
18263
+ args: ["class.left"]
18264
+ }], isRight: [{
18265
+ type: HostBinding,
18266
+ args: ["class.right"]
18158
18267
  }], animate: [{
18159
18268
  type: HostBinding,
18160
18269
  args: ['@showHide']
18161
18270
  }] } });
18162
18271
 
18272
+ const SHOW_DELAY_PROPERTY = '--co-tooltip-show-delay';
18273
+ const AUTO_HIDE_DELAY_PROPERTY = '--co-tooltip-auto-hide-delay';
18274
+ const DEFAULT_SHOW_DELAY_MS = 400;
18275
+ const DEFAULT_AUTO_HIDE_DELAY_MS = 10000;
18163
18276
  class TooltipDirective {
18164
18277
  _compFactoryResolver;
18165
18278
  _appRef;
@@ -18168,9 +18281,15 @@ class TooltipDirective {
18168
18281
  set tooltip(str) {
18169
18282
  this._tooltipMessage = str;
18170
18283
  }
18284
+ orientation = CoDirection.Up;
18171
18285
  _elementRef;
18172
18286
  _tooltipMessage;
18173
18287
  _componentRef;
18288
+ _showTimeoutId = undefined;
18289
+ _autoHideTimeoutId = undefined;
18290
+ _mouseEnterHandler = () => this._startShowTimeout();
18291
+ _mouseLeaveHandler = () => this._removeTooltip();
18292
+ _scrollHandler = () => this._handleScroll();
18174
18293
  constructor(elementRef, _compFactoryResolver, _appRef, _injector, _sanitizer) {
18175
18294
  this._compFactoryResolver = _compFactoryResolver;
18176
18295
  this._appRef = _appRef;
@@ -18179,37 +18298,79 @@ class TooltipDirective {
18179
18298
  this._elementRef = elementRef;
18180
18299
  }
18181
18300
  ngOnDestroy() {
18301
+ this._removeTooltip();
18182
18302
  if (this._elementRef && this._elementRef.nativeElement) {
18183
- this._elementRef.nativeElement.removeEventListener('mouseenter', (event) => this._handleMouseMove(event));
18184
- this._elementRef.nativeElement.removeEventListener('mouseleave', () => this._removeTooltip());
18303
+ this._elementRef.nativeElement.removeEventListener('mouseenter', this._mouseEnterHandler);
18304
+ this._elementRef.nativeElement.removeEventListener('mouseleave', this._mouseLeaveHandler);
18185
18305
  }
18186
- window.removeEventListener("scroll", (event) => this._handleScroll);
18306
+ window.removeEventListener("scroll", this._scrollHandler);
18187
18307
  this._elementRef = undefined;
18188
18308
  }
18189
18309
  ngOnInit() {
18190
- window.addEventListener("scroll", (event) => this._handleScroll);
18310
+ window.addEventListener("scroll", this._scrollHandler);
18191
18311
  if (this._elementRef && this._elementRef.nativeElement) {
18192
- this._elementRef.nativeElement.addEventListener('mouseenter', (event) => this._handleMouseMove(event));
18193
- this._elementRef.nativeElement.addEventListener('mouseleave', () => this._removeTooltip());
18312
+ this._elementRef.nativeElement.addEventListener('mouseenter', this._mouseEnterHandler);
18313
+ this._elementRef.nativeElement.addEventListener('mouseleave', this._mouseLeaveHandler);
18194
18314
  }
18195
18315
  }
18196
18316
  _handleScroll() {
18197
18317
  this._removeTooltip();
18198
18318
  }
18199
- _handleMouseMove(event) {
18200
- this._showTooltip(event.clientY, event.clientX);
18319
+ _startShowTimeout() {
18320
+ this._clearShowTimeout();
18321
+ this._showTimeoutId = window.setTimeout(() => {
18322
+ this._showTimeoutId = undefined;
18323
+ this._createTooltipComponent();
18324
+ }, this._resolveDelay(SHOW_DELAY_PROPERTY, DEFAULT_SHOW_DELAY_MS));
18201
18325
  }
18202
- _showTooltip(top, left) {
18203
- this._createTooltipComponent(top, left);
18326
+ // Delays come from custom properties, read from the host so a scoped override wins over the
18327
+ // :root default; falls back when the stylesheet is absent. A bare number is read as milliseconds.
18328
+ _resolveDelay(property, fallback) {
18329
+ if (!this._elementRef || !this._elementRef.nativeElement) {
18330
+ return fallback;
18331
+ }
18332
+ const raw = window.getComputedStyle(this._elementRef.nativeElement)
18333
+ .getPropertyValue(property)
18334
+ .trim();
18335
+ const value = parseFloat(raw);
18336
+ if (isNaN(value)) {
18337
+ return fallback;
18338
+ }
18339
+ return Math.max(0, raw.endsWith('ms') || !raw.endsWith('s') ? value : value * 1000);
18340
+ }
18341
+ _clearShowTimeout() {
18342
+ if (this._showTimeoutId !== undefined) {
18343
+ window.clearTimeout(this._showTimeoutId);
18344
+ this._showTimeoutId = undefined;
18345
+ }
18204
18346
  }
18205
18347
  _removeTooltip() {
18348
+ this._clearShowTimeout();
18349
+ this._clearAutoHideTimeout();
18206
18350
  if (this._componentRef) {
18207
18351
  this._appRef.detachView(this._componentRef.hostView);
18208
18352
  this._componentRef.destroy();
18209
18353
  this._componentRef = undefined;
18210
18354
  }
18211
18355
  }
18212
- _createTooltipComponent(top, left) {
18356
+ _startAutoHideTimeout() {
18357
+ this._clearAutoHideTimeout();
18358
+ const delay = this._resolveDelay(AUTO_HIDE_DELAY_PROPERTY, DEFAULT_AUTO_HIDE_DELAY_MS);
18359
+ if (delay <= 0) { // guard switched off by the consumer
18360
+ return;
18361
+ }
18362
+ this._autoHideTimeoutId = window.setTimeout(() => {
18363
+ this._autoHideTimeoutId = undefined;
18364
+ this._removeTooltip();
18365
+ }, delay);
18366
+ }
18367
+ _clearAutoHideTimeout() {
18368
+ if (this._autoHideTimeoutId !== undefined) {
18369
+ window.clearTimeout(this._autoHideTimeoutId);
18370
+ this._autoHideTimeoutId = undefined;
18371
+ }
18372
+ }
18373
+ _createTooltipComponent() {
18213
18374
  if (!this._tooltipMessage) {
18214
18375
  return;
18215
18376
  }
@@ -18220,13 +18381,15 @@ class TooltipDirective {
18220
18381
  .resolveComponentFactory(TooltipComponent)
18221
18382
  .create(this._injector);
18222
18383
  this._componentRef.instance.hostElement = this._elementRef.nativeElement;
18384
+ this._componentRef.instance.orientation = this.orientation;
18223
18385
  this._componentRef.instance.toolTip = this._sanitizer.bypassSecurityTrustHtml(this._tooltipMessage);
18224
18386
  this._appRef.attachView(this._componentRef.hostView);
18225
18387
  const domElem = this._componentRef.hostView.rootNodes[0];
18226
18388
  document.body.appendChild(domElem);
18389
+ this._startAutoHideTimeout();
18227
18390
  }
18228
18391
  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 });
18229
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.16", type: TooltipDirective, isStandalone: false, selector: "[tooltip]", inputs: { tooltip: "tooltip" }, ngImport: i0 });
18392
+ 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 });
18230
18393
  }
18231
18394
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TooltipDirective, decorators: [{
18232
18395
  type: Directive,
@@ -18237,6 +18400,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
18237
18400
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }, { type: i1.DomSanitizer }], propDecorators: { tooltip: [{
18238
18401
  type: Input,
18239
18402
  args: ["tooltip"]
18403
+ }], orientation: [{
18404
+ type: Input,
18405
+ args: ["tooltipOrientation"]
18240
18406
  }] } });
18241
18407
 
18242
18408
  class TooltipModule {