@porscheinformatik/material-addons 22.4.1 → 22.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, Component, NgModule, booleanAttribute, inject, ElementRef, Renderer2, DestroyRef, Directive, ChangeDetectionStrategy, effect, Optional, HostBinding, signal, LOCALE_ID, Inject, Injectable, output, InjectionToken, viewChild, computed, EventEmitter, Output, Input, ViewChild, forwardRef, HostListener, model, SkipSelf, ViewContainerRef, inputBinding, outputBinding, contentChildren, contentChild,
|
|
2
|
+
import { input, Component, NgModule, booleanAttribute, inject, ElementRef, Renderer2, DestroyRef, Directive, ChangeDetectionStrategy, effect, Optional, HostBinding, signal, LOCALE_ID, Inject, Injectable, output, InjectionToken, viewChild, computed, EventEmitter, Output, Input, ViewChild, ChangeDetectorRef, Injector, untracked, afterEveryRender, forwardRef, HostListener, model, SkipSelf, ViewContainerRef, inputBinding, outputBinding, contentChildren, contentChild, TemplateRef, ViewChildren, ContentChild, ViewEncapsulation, QueryList, ContentChildren, PLATFORM_ID } from '@angular/core';
|
|
3
3
|
import * as i2 from '@angular/material/icon';
|
|
4
4
|
import { MatIconModule, MatIcon } from '@angular/material/icon';
|
|
5
5
|
import * as i6 from '@angular/material/tooltip';
|
|
@@ -15,9 +15,9 @@ import { FormsModule, FormGroupDirective, ControlContainer, NG_VALUE_ACCESSOR, F
|
|
|
15
15
|
import * as i3 from '@angular/cdk/text-field';
|
|
16
16
|
import { TextFieldModule } from '@angular/cdk/text-field';
|
|
17
17
|
import * as i2$1 from '@angular/material/input';
|
|
18
|
-
import { MatInputModule } from '@angular/material/input';
|
|
18
|
+
import { MatInputModule, MatInput } from '@angular/material/input';
|
|
19
19
|
import * as i1$1 from '@angular/material/form-field';
|
|
20
|
-
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
20
|
+
import { MatFormFieldModule, MatFormField } from '@angular/material/form-field';
|
|
21
21
|
import { ObserversModule } from '@angular/cdk/observers';
|
|
22
22
|
import { Subject, Subscription, of } from 'rxjs';
|
|
23
23
|
import { throttleTime, switchMap, map, tap, startWith, takeUntil, distinctUntilChanged } from 'rxjs/operators';
|
|
@@ -329,6 +329,59 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
329
329
|
}]
|
|
330
330
|
}] });
|
|
331
331
|
|
|
332
|
+
/** Internal numeric-field precision policy, including static string attributes. */
|
|
333
|
+
function normalizeDecimalPlaces(value) {
|
|
334
|
+
if (typeof value !== 'number' && (typeof value !== 'string' || value.trim() === '')) {
|
|
335
|
+
return 2;
|
|
336
|
+
}
|
|
337
|
+
const precision = Number(value);
|
|
338
|
+
return Number.isInteger(precision) && precision >= 0 && precision <= 100 ? precision : 2;
|
|
339
|
+
}
|
|
340
|
+
/** Expand the finite number's shortest decimal representation; IEEE-754 bounds the allocation. */
|
|
341
|
+
function toDecimalString(value) {
|
|
342
|
+
if (!Number.isFinite(value)) {
|
|
343
|
+
return '';
|
|
344
|
+
}
|
|
345
|
+
const text = value.toString();
|
|
346
|
+
const [mantissa, exponent] = text.split('e');
|
|
347
|
+
if (exponent === undefined) {
|
|
348
|
+
return text;
|
|
349
|
+
}
|
|
350
|
+
const sign = value < 0 ? '-' : '';
|
|
351
|
+
const [integer, fraction = ''] = mantissa.replace('-', '').split('.');
|
|
352
|
+
const digits = integer + fraction;
|
|
353
|
+
const decimalIndex = integer.length + Number(exponent);
|
|
354
|
+
if (decimalIndex <= 0) {
|
|
355
|
+
return `${sign}0.${'0'.repeat(-decimalIndex)}${digits}`;
|
|
356
|
+
}
|
|
357
|
+
if (decimalIndex >= digits.length) {
|
|
358
|
+
return sign + digits + '0'.repeat(decimalIndex - digits.length);
|
|
359
|
+
}
|
|
360
|
+
return `${sign}${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
|
|
361
|
+
}
|
|
362
|
+
/** Operate on decimal digits so scaling cannot overflow or move a decimal boundary. */
|
|
363
|
+
function roundOrTruncateNumber(value, decimalPlaces, roundDisplayValue) {
|
|
364
|
+
if (!Number.isFinite(value) || value === 0) {
|
|
365
|
+
return value;
|
|
366
|
+
}
|
|
367
|
+
const precision = normalizeDecimalPlaces(decimalPlaces);
|
|
368
|
+
const [integer, fraction = ''] = toDecimalString(Math.abs(value)).split('.');
|
|
369
|
+
if (fraction.length <= precision) {
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
const discarded = fraction.slice(precision);
|
|
373
|
+
let digits = integer + fraction.slice(0, precision);
|
|
374
|
+
// At an exact negative tie Math.round chooses the value closer to zero.
|
|
375
|
+
const increment = discarded[0] > '5' || (discarded[0] === '5' && (value > 0 || /[1-9]/.test(discarded.slice(1))));
|
|
376
|
+
if (roundDisplayValue && increment) {
|
|
377
|
+
digits = (BigInt(digits) + 1n).toString();
|
|
378
|
+
}
|
|
379
|
+
digits = digits.padStart(precision + 1, '0');
|
|
380
|
+
const decimalIndex = digits.length - precision;
|
|
381
|
+
const result = precision > 0 ? `${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}` : digits;
|
|
382
|
+
return Number((value < 0 ? '-' : '') + result);
|
|
383
|
+
}
|
|
384
|
+
|
|
332
385
|
class NumberFormatService {
|
|
333
386
|
static { this.NEGATIVE = '-'; }
|
|
334
387
|
static { this.NUMBERS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; }
|
|
@@ -371,7 +424,6 @@ class NumberFormatService {
|
|
|
371
424
|
* @param locale the new locale
|
|
372
425
|
*/
|
|
373
426
|
prepareSeparators(locale) {
|
|
374
|
-
// try to get the current formatting
|
|
375
427
|
const localeDecimalSeparator = (1.1).toLocaleString(locale).charAt(1);
|
|
376
428
|
const decimalSeparator = localeDecimalSeparator === ',' ? ',' : '.';
|
|
377
429
|
const groupingSeparator = localeDecimalSeparator === ',' ? '.' : ',';
|
|
@@ -380,49 +432,38 @@ class NumberFormatService {
|
|
|
380
432
|
this.allowedKeysSignal.set([...NumberFormatService.NUMBERS, NumberFormatService.NEGATIVE, decimalSeparator]);
|
|
381
433
|
}
|
|
382
434
|
format(value, options) {
|
|
383
|
-
return
|
|
384
|
-
? this.formatNumber(value.toString().replace(new RegExp('[.]', 'g'), this.decimalSeparator), options)
|
|
385
|
-
: '';
|
|
435
|
+
return Number.isFinite(value) ? this.formatNumber(toDecimalString(value).replace('.', this.decimalSeparator), options) : '';
|
|
386
436
|
}
|
|
387
437
|
formatNumber(value, options) {
|
|
388
438
|
const autofillDecimals = this.valueOrDefault(options?.autofillDecimals, NumberFormatService.DEFAULT_AUTOFILL_DECIMALS);
|
|
389
|
-
const decimalPlaces =
|
|
439
|
+
const decimalPlaces = normalizeDecimalPlaces(options?.decimalPlaces);
|
|
390
440
|
const finalFormatting = this.valueOrDefault(options?.finalFormatting, NumberFormatService.DEFAULT_FINAL_FORMATTING);
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const isNegative = result.startsWith(NumberFormatService.NEGATIVE);
|
|
395
|
-
let i = decimalIndex > -1 ? decimalIndex : result.length;
|
|
396
|
-
while (i > (isNegative ? 4 : 3)) {
|
|
397
|
-
i -= 3;
|
|
398
|
-
result = result.substring(0, i) + this.groupingSeparator + result.substring(i, result.length);
|
|
399
|
-
}
|
|
400
|
-
if (finalFormatting) {
|
|
401
|
-
if (decimalPlaces > 0 && !!result) {
|
|
402
|
-
/* autofill decimal places */
|
|
403
|
-
let actualDecimalIndex = result.indexOf(this.decimalSeparator);
|
|
404
|
-
if (autofillDecimals) {
|
|
405
|
-
if (actualDecimalIndex === -1) {
|
|
406
|
-
actualDecimalIndex = result.length;
|
|
407
|
-
result += this.decimalSeparator;
|
|
408
|
-
}
|
|
409
|
-
result = this.addMissingLeadingZero(result, actualDecimalIndex);
|
|
410
|
-
actualDecimalIndex = result.indexOf(this.decimalSeparator);
|
|
411
|
-
const actualDecimalPlaces = result.length - actualDecimalIndex - 1;
|
|
412
|
-
for (let j = 0; j < decimalPlaces - actualDecimalPlaces; j++) {
|
|
413
|
-
result += '0';
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
result = this.addMissingLeadingZero(result, actualDecimalIndex);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return result;
|
|
441
|
+
const stripped = this.strip(value, { decimalPlaces, removeLeadingZeros: finalFormatting });
|
|
442
|
+
const grouped = this.addGroupingSeparators(stripped);
|
|
443
|
+
return finalFormatting && decimalPlaces > 0 && grouped ? this.finalizeDecimals(grouped, decimalPlaces, autofillDecimals) : grouped;
|
|
422
444
|
}
|
|
423
445
|
strip(value, options) {
|
|
424
|
-
const decimalPlaces =
|
|
446
|
+
const decimalPlaces = normalizeDecimalPlaces(options?.decimalPlaces);
|
|
425
447
|
const removeLeadingZeros = this.valueOrDefault(options?.removeLeadingZeros, NumberFormatService.DEFAULT_REMOVE_LEADING_ZEROS);
|
|
448
|
+
if (/^[+-]?(?:Infinity|NaN)$/.test(value)) {
|
|
449
|
+
return '';
|
|
450
|
+
}
|
|
451
|
+
// Exponent input is atomic: never silently accept the mantissa of an invalid literal.
|
|
452
|
+
if (/^[+\-0-9.,]*[eE]/.test(value)) {
|
|
453
|
+
const exponentIndex = value.search(/[eE]/);
|
|
454
|
+
const sourceMantissa = value.slice(0, exponentIndex);
|
|
455
|
+
const ungrouped = this.groupingSeparator === this.decimalSeparator ? sourceMantissa : sourceMantissa.split(this.groupingSeparator).join('');
|
|
456
|
+
const mantissa = ungrouped.replace(this.decimalSeparator, '.');
|
|
457
|
+
const normalized = mantissa + value.slice(exponentIndex);
|
|
458
|
+
if (!/^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)[eE][+-]?[0-9]+$/.test(normalized)) {
|
|
459
|
+
return '';
|
|
460
|
+
}
|
|
461
|
+
const exponentValue = Number(normalized);
|
|
462
|
+
if (!Number.isFinite(exponentValue)) {
|
|
463
|
+
return '';
|
|
464
|
+
}
|
|
465
|
+
value = this.expandScientificText(normalized, decimalPlaces).replace('.', this.decimalSeparator);
|
|
466
|
+
}
|
|
426
467
|
let result = '';
|
|
427
468
|
let indexDecimalSep = -1;
|
|
428
469
|
let j = -1;
|
|
@@ -468,6 +509,64 @@ class NumberFormatService {
|
|
|
468
509
|
break;
|
|
469
510
|
}
|
|
470
511
|
}
|
|
512
|
+
// Keep a numeric zero when leading-zero removal and zero-place truncation consume its digits.
|
|
513
|
+
if (ignoredChars > 0 && /^-?0/.test(value) && (result === '' || result === NumberFormatService.NEGATIVE)) {
|
|
514
|
+
result += '0';
|
|
515
|
+
}
|
|
516
|
+
const numericValue = Number.parseFloat(result.replace(this.decimalSeparator, '.'));
|
|
517
|
+
return numericValue === Infinity || numericValue === -Infinity ? '' : result;
|
|
518
|
+
}
|
|
519
|
+
expandScientificText(value, decimalPlaces) {
|
|
520
|
+
const [mantissa, exponent] = value.toLowerCase().split('e');
|
|
521
|
+
const sign = mantissa.startsWith('-') ? '-' : '';
|
|
522
|
+
const [integer, fraction = ''] = mantissa.replace(/^[+-]/, '').split('.');
|
|
523
|
+
const sourceDigits = integer + fraction;
|
|
524
|
+
const digits = sourceDigits.replace(/^0+/, '');
|
|
525
|
+
if (!digits) {
|
|
526
|
+
return sign + '0';
|
|
527
|
+
}
|
|
528
|
+
// Keep source digits: Number(value) is only an overflow guard, never the source of rounded digits.
|
|
529
|
+
const decimalIndex = integer.length + Number(exponent) - (sourceDigits.length - digits.length);
|
|
530
|
+
if (decimalIndex <= 0) {
|
|
531
|
+
const zeros = Math.min(-decimalIndex, decimalPlaces);
|
|
532
|
+
const subunitDecimals = '0'.repeat(zeros) + digits.slice(0, decimalPlaces - zeros);
|
|
533
|
+
return sign + '0' + (subunitDecimals ? '.' + subunitDecimals : '');
|
|
534
|
+
}
|
|
535
|
+
// A finite nonzero IEEE-754 value has at most 309 integer digits. Bound all padding explicitly.
|
|
536
|
+
if (decimalIndex > 309) {
|
|
537
|
+
return '';
|
|
538
|
+
}
|
|
539
|
+
const whole = digits.slice(0, decimalIndex).padEnd(decimalIndex, '0');
|
|
540
|
+
const decimals = digits.slice(decimalIndex, decimalIndex + decimalPlaces);
|
|
541
|
+
return sign + whole + (decimals ? '.' + decimals : '');
|
|
542
|
+
}
|
|
543
|
+
addGroupingSeparators(value) {
|
|
544
|
+
let result = value;
|
|
545
|
+
const decimalIndex = result.indexOf(this.decimalSeparator);
|
|
546
|
+
const isNegative = result.startsWith(NumberFormatService.NEGATIVE);
|
|
547
|
+
let index = decimalIndex > -1 ? decimalIndex : result.length;
|
|
548
|
+
while (index > (isNegative ? 4 : 3)) {
|
|
549
|
+
index -= 3;
|
|
550
|
+
result = result.substring(0, index) + this.groupingSeparator + result.substring(index, result.length);
|
|
551
|
+
}
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
finalizeDecimals(value, decimalPlaces, autofillDecimals) {
|
|
555
|
+
let result = value;
|
|
556
|
+
let decimalIndex = result.indexOf(this.decimalSeparator);
|
|
557
|
+
if (!autofillDecimals) {
|
|
558
|
+
return this.addMissingLeadingZero(result, decimalIndex);
|
|
559
|
+
}
|
|
560
|
+
if (decimalIndex === -1) {
|
|
561
|
+
decimalIndex = result.length;
|
|
562
|
+
result += this.decimalSeparator;
|
|
563
|
+
}
|
|
564
|
+
result = this.addMissingLeadingZero(result, decimalIndex);
|
|
565
|
+
decimalIndex = result.indexOf(this.decimalSeparator);
|
|
566
|
+
const actualDecimalPlaces = result.length - decimalIndex - 1;
|
|
567
|
+
for (let index = 0; index < decimalPlaces - actualDecimalPlaces; index++) {
|
|
568
|
+
result += '0';
|
|
569
|
+
}
|
|
471
570
|
return result;
|
|
472
571
|
}
|
|
473
572
|
addMissingLeadingZero(result, actualDecimalIndex) {
|
|
@@ -894,251 +993,709 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
894
993
|
}]
|
|
895
994
|
}] });
|
|
896
995
|
|
|
996
|
+
function mapNormalizedSelection(selection, context) {
|
|
997
|
+
const { rawValue, normalizedValue, formattedValue, groupingSeparator, decimalSeparator } = context;
|
|
998
|
+
const isExponent = /^[+\-0-9.,]+[eE][+-]?[0-9]+$/.test(rawValue) && normalizedValue !== '';
|
|
999
|
+
const mapPosition = (position) => {
|
|
1000
|
+
if (position <= 0) {
|
|
1001
|
+
return 0;
|
|
1002
|
+
}
|
|
1003
|
+
if (position >= rawValue.length) {
|
|
1004
|
+
return formattedValue.length;
|
|
1005
|
+
}
|
|
1006
|
+
if (isExponent) {
|
|
1007
|
+
// An exponent is one literal, not independently parseable prefixes. Spread its
|
|
1008
|
+
// interior boundaries monotonically across the complete expanded display.
|
|
1009
|
+
return Math.ceil((position / rawValue.length) * formattedValue.length);
|
|
1010
|
+
}
|
|
1011
|
+
let retained = 0;
|
|
1012
|
+
for (let index = 0; index < position && retained < normalizedValue.length; index++) {
|
|
1013
|
+
if (rawValue.charAt(index) === normalizedValue.charAt(retained)) {
|
|
1014
|
+
retained++;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
let formattedPosition = 0;
|
|
1018
|
+
let normalizedPosition = 0;
|
|
1019
|
+
while (formattedPosition < formattedValue.length && normalizedPosition < retained) {
|
|
1020
|
+
if (formattedValue.charAt(formattedPosition) === normalizedValue.charAt(normalizedPosition)) {
|
|
1021
|
+
normalizedPosition++;
|
|
1022
|
+
}
|
|
1023
|
+
formattedPosition++;
|
|
1024
|
+
}
|
|
1025
|
+
if (groupingSeparator !== decimalSeparator &&
|
|
1026
|
+
rawValue.charAt(position - 1) === groupingSeparator &&
|
|
1027
|
+
formattedValue.charAt(formattedPosition) === groupingSeparator) {
|
|
1028
|
+
formattedPosition++;
|
|
1029
|
+
}
|
|
1030
|
+
return formattedPosition;
|
|
1031
|
+
};
|
|
1032
|
+
const start = mapPosition(selection.start);
|
|
1033
|
+
const end = mapPosition(selection.end);
|
|
1034
|
+
return { start: Math.min(start, end), end: Math.max(start, end) };
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
class NumericFieldUnitPresentation {
|
|
1038
|
+
constructor(inputElement, renderer, onResize) {
|
|
1039
|
+
this.inputElement = inputElement;
|
|
1040
|
+
this.renderer = renderer;
|
|
1041
|
+
this.onResize = onResize;
|
|
1042
|
+
this.options = { unit: null, unitPosition: 'right', textAlign: 'right', text: '' };
|
|
1043
|
+
this.layoutDirty = true;
|
|
1044
|
+
}
|
|
1045
|
+
invalidateLayout() {
|
|
1046
|
+
this.layoutDirty = true;
|
|
1047
|
+
}
|
|
1048
|
+
destroy() {
|
|
1049
|
+
this.removeUnitSpan();
|
|
1050
|
+
this.removeTextSpan();
|
|
1051
|
+
}
|
|
1052
|
+
render(options, label) {
|
|
1053
|
+
if (this.options.unit !== options.unit ||
|
|
1054
|
+
this.options.unitPosition !== options.unitPosition ||
|
|
1055
|
+
this.options.textAlign !== options.textAlign ||
|
|
1056
|
+
this.options.text !== options.text ||
|
|
1057
|
+
(!!options.unit && !this.unitSpan)) {
|
|
1058
|
+
this.updateUnit(options);
|
|
1059
|
+
}
|
|
1060
|
+
// Restoring natural sizing and applying measured text depend on intervening
|
|
1061
|
+
// DOM reads. The directive deliberately schedules the whole transaction as mixedReadWrite.
|
|
1062
|
+
const presentation = this.measurePresentation(label);
|
|
1063
|
+
const layout = this.applyPresentation(presentation);
|
|
1064
|
+
this.positionTrailingUnit(layout);
|
|
1065
|
+
}
|
|
1066
|
+
updateUnit(options) {
|
|
1067
|
+
this.options = options;
|
|
1068
|
+
this.layoutDirty = true;
|
|
1069
|
+
if (!this.options.unit) {
|
|
1070
|
+
this.removeUnitSpan();
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (!this.unitSpan || this.unitSpanPosition !== this.options.unitPosition) {
|
|
1074
|
+
this.createUnitSpan();
|
|
1075
|
+
}
|
|
1076
|
+
if (!this.unitSpan) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
if (this.options.textAlign !== 'left' || this.options.unitPosition !== 'right' || this.options.text === '') {
|
|
1080
|
+
this.restoreInputReservation();
|
|
1081
|
+
}
|
|
1082
|
+
this.observeUnitSize();
|
|
1083
|
+
this.unitSpan.textContent = this.options.unit;
|
|
1084
|
+
if (this.options.textAlign === 'left' && this.options.unitPosition === 'right') {
|
|
1085
|
+
this.unitSpan.style.display = this.options.text !== '' ? 'unset' : 'none';
|
|
1086
|
+
this.unitSpan.style.position = 'absolute';
|
|
1087
|
+
}
|
|
1088
|
+
else {
|
|
1089
|
+
this.unitSpan.style.display = '';
|
|
1090
|
+
this.unitSpan.style.left = '';
|
|
1091
|
+
this.unitSpan.style.position = '';
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
createUnitSpan() {
|
|
1095
|
+
const unitContainer = this.getUnitContainer();
|
|
1096
|
+
if (!unitContainer) {
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
this.removeUnitSpan();
|
|
1100
|
+
this.unitSpan = this.renderer.createElement('span');
|
|
1101
|
+
this.unitSpanPosition = this.options.unitPosition;
|
|
1102
|
+
this.renderer.addClass(this.unitSpan, 'mad-numeric-field-unit');
|
|
1103
|
+
// Native compatibility spans; these attributes do not instantiate Material directives.
|
|
1104
|
+
if (this.options.unitPosition === 'left') {
|
|
1105
|
+
this.renderer.setAttribute(this.unitSpan, 'matPrefix', '');
|
|
1106
|
+
this.renderer.setAttribute(this.unitSpan, 'matTextPrefix', '');
|
|
1107
|
+
this.renderer.setStyle(this.unitSpan, 'padding-right', '5px');
|
|
1108
|
+
this.renderer.insertBefore(unitContainer, this.unitSpan, this.getUnitInsertReference(unitContainer));
|
|
1109
|
+
}
|
|
1110
|
+
else {
|
|
1111
|
+
this.renderer.setAttribute(this.unitSpan, 'matSuffix', '');
|
|
1112
|
+
this.renderer.setAttribute(this.unitSpan, 'matTextSuffix', '');
|
|
1113
|
+
this.renderer.setStyle(this.unitSpan, 'padding-left', '5px');
|
|
1114
|
+
this.renderer.appendChild(unitContainer, this.unitSpan);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
getUnitContainer() {
|
|
1118
|
+
const materialFormFieldFlex = this.inputElement.closest('.mat-mdc-form-field-flex');
|
|
1119
|
+
if (materialFormFieldFlex instanceof HTMLElement) {
|
|
1120
|
+
return materialFormFieldFlex;
|
|
1121
|
+
}
|
|
1122
|
+
return this.inputElement.parentElement;
|
|
1123
|
+
}
|
|
1124
|
+
getUnitInsertReference(unitContainer) {
|
|
1125
|
+
if (this.inputElement.parentElement?.parentElement === unitContainer) {
|
|
1126
|
+
return this.inputElement.parentElement;
|
|
1127
|
+
}
|
|
1128
|
+
if (this.inputElement.parentElement === unitContainer) {
|
|
1129
|
+
return this.inputElement;
|
|
1130
|
+
}
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
measurePresentation(label) {
|
|
1134
|
+
if (!this.unitSpan) {
|
|
1135
|
+
return undefined;
|
|
1136
|
+
}
|
|
1137
|
+
// Measure the consumer's authored width, including responsive CSS, before
|
|
1138
|
+
// reserving space. Restoration and reapplication finish in this render, so
|
|
1139
|
+
// the observed border box stays unchanged and no intermediate style paints.
|
|
1140
|
+
if (this.layoutDirty) {
|
|
1141
|
+
this.restoreInputReservation();
|
|
1142
|
+
}
|
|
1143
|
+
const view = this.inputElement.ownerDocument.defaultView;
|
|
1144
|
+
if (!view) {
|
|
1145
|
+
return undefined;
|
|
1146
|
+
}
|
|
1147
|
+
const inputStyles = view.getComputedStyle(this.inputElement);
|
|
1148
|
+
const restingLabel = this.readRestingLabel(label);
|
|
1149
|
+
const refreshLayout = this.layoutDirty;
|
|
1150
|
+
this.layoutDirty = false;
|
|
1151
|
+
if (!refreshLayout || this.options.textAlign !== 'left' || this.options.unitPosition !== 'right' || !this.inputElement.parentElement) {
|
|
1152
|
+
return { color: inputStyles.color, label: restingLabel };
|
|
1153
|
+
}
|
|
1154
|
+
const parentStyles = view.getComputedStyle(this.inputElement.parentElement);
|
|
1155
|
+
const offsetParent = this.unitSpan.offsetParent;
|
|
1156
|
+
const inputBounds = this.inputElement.getBoundingClientRect();
|
|
1157
|
+
const inputOffset = offsetParent instanceof HTMLElement ? inputBounds.left - offsetParent.getBoundingClientRect().left - offsetParent.clientLeft : 0;
|
|
1158
|
+
return {
|
|
1159
|
+
color: inputStyles.color,
|
|
1160
|
+
label: restingLabel,
|
|
1161
|
+
layout: {
|
|
1162
|
+
text: this.options.text,
|
|
1163
|
+
font: inputStyles.font,
|
|
1164
|
+
fontSize: inputStyles.fontSize,
|
|
1165
|
+
letterSpacing: inputStyles.letterSpacing,
|
|
1166
|
+
marginTop: parentStyles.getPropertyValue('border-top-width'),
|
|
1167
|
+
paddingTop: parentStyles.getPropertyValue('padding-top'),
|
|
1168
|
+
paddingBottom: parentStyles.getPropertyValue('padding-bottom'),
|
|
1169
|
+
inputWidth: this.inputElement.clientWidth,
|
|
1170
|
+
inputOffset,
|
|
1171
|
+
paddingLeft: Number.parseFloat(inputStyles.paddingLeft) || 0,
|
|
1172
|
+
paddingRight: Number.parseFloat(inputStyles.paddingRight) || 0,
|
|
1173
|
+
outerWidth: inputBounds.width ||
|
|
1174
|
+
this.inputElement.clientWidth +
|
|
1175
|
+
(Number.parseFloat(inputStyles.borderLeftWidth) || 0) +
|
|
1176
|
+
(Number.parseFloat(inputStyles.borderRightWidth) || 0),
|
|
1177
|
+
borderLeft: Number.parseFloat(inputStyles.borderLeftWidth) || 0,
|
|
1178
|
+
unitWidth: this.unitSpan.clientWidth,
|
|
1179
|
+
},
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
applyPresentation(presentation) {
|
|
1183
|
+
if (!presentation || !this.unitSpan) {
|
|
1184
|
+
return undefined;
|
|
1185
|
+
}
|
|
1186
|
+
this.writeRestingLabel(presentation.label);
|
|
1187
|
+
// Read the actual input color so filled/outlined themes and native disabled bindings agree.
|
|
1188
|
+
if (this.unitSpan.style.color !== presentation.color) {
|
|
1189
|
+
this.unitSpan.style.color = presentation.color;
|
|
1190
|
+
}
|
|
1191
|
+
const layout = presentation.layout;
|
|
1192
|
+
if (!layout) {
|
|
1193
|
+
return undefined;
|
|
1194
|
+
}
|
|
1195
|
+
if (layout.text !== '') {
|
|
1196
|
+
this.reserveInputSpace(layout);
|
|
1197
|
+
}
|
|
1198
|
+
this.unitSpan.style.marginTop = layout.marginTop;
|
|
1199
|
+
this.unitSpan.style.paddingTop = layout.paddingTop;
|
|
1200
|
+
this.unitSpan.style.paddingBottom = layout.paddingBottom;
|
|
1201
|
+
this.ensureTextSpan();
|
|
1202
|
+
if (this.textSpan) {
|
|
1203
|
+
this.textSpan.style.font = layout.font;
|
|
1204
|
+
this.textSpan.style.fontSize = layout.fontSize;
|
|
1205
|
+
this.textSpan.style.letterSpacing = layout.letterSpacing;
|
|
1206
|
+
this.textSpan.textContent = layout.text;
|
|
1207
|
+
}
|
|
1208
|
+
return layout;
|
|
1209
|
+
}
|
|
1210
|
+
positionTrailingUnit(layout) {
|
|
1211
|
+
if (!layout || !this.textSpan || !this.unitSpan) {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const textWidth = layout.inputWidth - layout.paddingLeft - layout.paddingRight - layout.unitWidth;
|
|
1215
|
+
const width = Math.min(textWidth, Math.ceil(this.textSpan.clientWidth));
|
|
1216
|
+
this.unitSpan.style.left = `${layout.inputOffset + layout.borderLeft + layout.paddingLeft + Math.max(width, 0)}px`;
|
|
1217
|
+
}
|
|
1218
|
+
observeUnitSize() {
|
|
1219
|
+
const Observer = this.inputElement.ownerDocument.defaultView?.ResizeObserver;
|
|
1220
|
+
if (this.resizeObserver || !Observer || !this.unitSpan) {
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
this.resizeObserver = new Observer(() => {
|
|
1224
|
+
this.layoutDirty = true;
|
|
1225
|
+
this.onResize();
|
|
1226
|
+
});
|
|
1227
|
+
// Padding changes the content box, not the border box. The parent also
|
|
1228
|
+
// detects responsive sizing while the input holds its measured outer width.
|
|
1229
|
+
this.resizeObserver.observe(this.inputElement, { box: 'border-box' });
|
|
1230
|
+
if (this.inputElement.parentElement) {
|
|
1231
|
+
this.resizeObserver.observe(this.inputElement.parentElement);
|
|
1232
|
+
}
|
|
1233
|
+
this.resizeObserver.observe(this.unitSpan);
|
|
1234
|
+
}
|
|
1235
|
+
reserveInputSpace(layout) {
|
|
1236
|
+
const style = this.inputElement.style;
|
|
1237
|
+
this.inputReservation ??= ['width', 'box-sizing', 'padding-right'].map((property) => this.captureStyle(style, property));
|
|
1238
|
+
style.setProperty('box-sizing', 'border-box');
|
|
1239
|
+
style.setProperty('width', `${layout.outerWidth}px`);
|
|
1240
|
+
// unitWidth includes the unit span's existing five-pixel leading gap.
|
|
1241
|
+
style.setProperty('padding-right', `${layout.paddingRight + layout.unitWidth}px`);
|
|
1242
|
+
// Read back CSSOM declarations so ownership compares browser-canonical values.
|
|
1243
|
+
for (const reservation of this.inputReservation) {
|
|
1244
|
+
reservation.appliedValue = style.getPropertyValue(reservation.property);
|
|
1245
|
+
reservation.appliedPriority = style.getPropertyPriority(reservation.property);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
restoreInputReservation() {
|
|
1249
|
+
this.restoreStyles(this.inputElement.style, this.inputReservation ?? []);
|
|
1250
|
+
this.inputReservation = undefined;
|
|
1251
|
+
}
|
|
1252
|
+
readRestingLabel(label) {
|
|
1253
|
+
const labelId = label.id;
|
|
1254
|
+
if (!labelId || label.floating) {
|
|
1255
|
+
return undefined;
|
|
1256
|
+
}
|
|
1257
|
+
const element = this.inputElement.ownerDocument.getElementById(labelId);
|
|
1258
|
+
if (!element) {
|
|
1259
|
+
return undefined;
|
|
1260
|
+
}
|
|
1261
|
+
const margin = this.labelStyles?.properties.find((property) => property.property === 'margin-left');
|
|
1262
|
+
const previousShift = margin && this.ownsStyle(element.style, margin) ? (this.labelStyles?.shift ?? 0) : 0;
|
|
1263
|
+
return {
|
|
1264
|
+
element,
|
|
1265
|
+
width: this.inputElement.clientWidth,
|
|
1266
|
+
shift: this.options.unitPosition === 'left'
|
|
1267
|
+
? previousShift + this.inputElement.getBoundingClientRect().left - element.getBoundingClientRect().left
|
|
1268
|
+
: 0,
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
writeRestingLabel(label) {
|
|
1272
|
+
if (this.labelStyles?.element !== label?.element) {
|
|
1273
|
+
this.restoreLabelStyles();
|
|
1274
|
+
}
|
|
1275
|
+
if (!label) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
if (!this.labelStyles) {
|
|
1279
|
+
this.labelStyles = {
|
|
1280
|
+
element: label.element,
|
|
1281
|
+
properties: [this.captureStyle(label.element.style, 'max-width')],
|
|
1282
|
+
shift: 0,
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
const style = label.element.style;
|
|
1286
|
+
if (this.options.unitPosition === 'left' && !this.labelStyles.properties.some(({ property }) => property === 'margin-left')) {
|
|
1287
|
+
this.labelStyles.properties.push(this.captureStyle(style, 'margin-left'));
|
|
1288
|
+
}
|
|
1289
|
+
// Keep newer consumer declarations as the restoration baseline, including
|
|
1290
|
+
// priority-only changes. Right units never take ownership of margin-left.
|
|
1291
|
+
for (const property of this.labelStyles.properties) {
|
|
1292
|
+
if (!this.ownsStyle(style, property)) {
|
|
1293
|
+
property.value = style.getPropertyValue(property.property);
|
|
1294
|
+
property.priority = style.getPropertyPriority(property.property);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
// Material owns truncation and floating transforms. Limit only the resting
|
|
1298
|
+
// label to the input's available space, using its public label relationship.
|
|
1299
|
+
style.setProperty('max-width', `${label.width}px`);
|
|
1300
|
+
if (this.options.unitPosition === 'left') {
|
|
1301
|
+
this.labelStyles.shift = label.shift;
|
|
1302
|
+
const margin = this.labelStyles.properties.find(({ property }) => property === 'margin-left');
|
|
1303
|
+
style.setProperty('margin-left', `calc(${margin?.value || '0px'} + ${label.shift}px)`);
|
|
1304
|
+
}
|
|
1305
|
+
for (const property of this.labelStyles.properties) {
|
|
1306
|
+
property.appliedValue = style.getPropertyValue(property.property);
|
|
1307
|
+
property.appliedPriority = style.getPropertyPriority(property.property);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
restoreLabelStyles() {
|
|
1311
|
+
if (this.labelStyles) {
|
|
1312
|
+
this.restoreStyles(this.labelStyles.element.style, this.labelStyles.properties);
|
|
1313
|
+
this.labelStyles = undefined;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
captureStyle(style, property) {
|
|
1317
|
+
return {
|
|
1318
|
+
property,
|
|
1319
|
+
value: style.getPropertyValue(property),
|
|
1320
|
+
priority: style.getPropertyPriority(property),
|
|
1321
|
+
appliedValue: '',
|
|
1322
|
+
appliedPriority: '',
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
ownsStyle(style, snapshot) {
|
|
1326
|
+
return (style.getPropertyValue(snapshot.property) === snapshot.appliedValue &&
|
|
1327
|
+
style.getPropertyPriority(snapshot.property) === snapshot.appliedPriority);
|
|
1328
|
+
}
|
|
1329
|
+
restoreStyles(style, snapshots) {
|
|
1330
|
+
for (const snapshot of snapshots) {
|
|
1331
|
+
if (!this.ownsStyle(style, snapshot)) {
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
if (snapshot.value) {
|
|
1335
|
+
style.setProperty(snapshot.property, snapshot.value, snapshot.priority);
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
style.removeProperty(snapshot.property);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
ensureTextSpan() {
|
|
1343
|
+
if (this.textSpan) {
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
const document = this.inputElement.ownerDocument;
|
|
1347
|
+
this.textSpan = document.createElement('span');
|
|
1348
|
+
document.body.appendChild(this.textSpan);
|
|
1349
|
+
this.textSpan.style.height = 'auto';
|
|
1350
|
+
this.textSpan.style.width = 'auto';
|
|
1351
|
+
this.textSpan.style.position = 'absolute';
|
|
1352
|
+
this.textSpan.style.top = '0';
|
|
1353
|
+
this.textSpan.style.whiteSpace = 'nowrap';
|
|
1354
|
+
this.textSpan.style.visibility = 'hidden';
|
|
1355
|
+
}
|
|
1356
|
+
removeUnitSpan() {
|
|
1357
|
+
this.resizeObserver?.disconnect();
|
|
1358
|
+
this.resizeObserver = undefined;
|
|
1359
|
+
this.restoreLabelStyles();
|
|
1360
|
+
this.restoreInputReservation();
|
|
1361
|
+
if (!this.unitSpan) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
this.unitSpan.remove();
|
|
1365
|
+
this.unitSpan = undefined;
|
|
1366
|
+
this.unitSpanPosition = undefined;
|
|
1367
|
+
}
|
|
1368
|
+
removeTextSpan() {
|
|
1369
|
+
if (!this.textSpan) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
this.textSpan.remove();
|
|
1373
|
+
this.textSpan = undefined;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
897
1377
|
/*
|
|
898
1378
|
* Copyright (c) 2018-2020 Porsche Informatik. All Rights Reserved.
|
|
899
1379
|
* This software is released under MIT license.
|
|
900
1380
|
* The full license information can be found in LICENSE in the root directory of this project.
|
|
901
1381
|
*/
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1382
|
+
const CONTROL_KEYS = new Set([
|
|
1383
|
+
'Backspace',
|
|
1384
|
+
'Delete',
|
|
1385
|
+
'Tab',
|
|
1386
|
+
'Escape',
|
|
1387
|
+
'Enter',
|
|
1388
|
+
'Home',
|
|
1389
|
+
'End',
|
|
1390
|
+
'ArrowLeft',
|
|
1391
|
+
'ArrowRight',
|
|
1392
|
+
'ArrowUp',
|
|
1393
|
+
'ArrowDown',
|
|
1394
|
+
]);
|
|
1395
|
+
const UNSET_NUMERIC_VALUE = Symbol('unset numeric value input');
|
|
907
1396
|
class NumericFieldDirective {
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
this.
|
|
919
|
-
this.
|
|
920
|
-
this.
|
|
921
|
-
this.
|
|
922
|
-
this.
|
|
923
|
-
this.
|
|
924
|
-
this.
|
|
925
|
-
this.
|
|
926
|
-
this.
|
|
927
|
-
this.
|
|
1397
|
+
constructor() {
|
|
1398
|
+
this.textAlign = input('right', /* @ts-ignore */
|
|
1399
|
+
...(ngDevMode ? [{ debugName: "textAlign" }] : /* istanbul ignore next */ []));
|
|
1400
|
+
this.decimalPlaces = input(NumberFormatService.DEFAULT_DECIMAL_PLACES, { ...(ngDevMode ? { debugName: "decimalPlaces" } : /* istanbul ignore next */ {}), transform: normalizeDecimalPlaces });
|
|
1401
|
+
this.roundValue = input(false, { ...(ngDevMode ? { debugName: "roundValue" } : /* istanbul ignore next */ {}), alias: 'roundDisplayValue', transform: booleanAttribute });
|
|
1402
|
+
this.autofillDecimals = input(false, { ...(ngDevMode ? { debugName: "autofillDecimals" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
1403
|
+
this.unit = input(null, /* @ts-ignore */
|
|
1404
|
+
...(ngDevMode ? [{ debugName: "unit" }] : /* istanbul ignore next */ []));
|
|
1405
|
+
this.unitPosition = input('right', /* @ts-ignore */
|
|
1406
|
+
...(ngDevMode ? [{ debugName: "unitPosition" }] : /* istanbul ignore next */ []));
|
|
1407
|
+
this.numericValue = input(UNSET_NUMERIC_VALUE, { ...(ngDevMode ? { debugName: "numericValue" } : /* istanbul ignore next */ {}), transform: (value) => value });
|
|
1408
|
+
this.numericValueChanged = output({ alias: 'numericValueChange' });
|
|
1409
|
+
this.changeDetectorRef = inject(ChangeDetectorRef);
|
|
1410
|
+
this.formField = inject(MatFormField, { optional: true });
|
|
1411
|
+
this.renderer = inject(Renderer2);
|
|
1412
|
+
this.inputEl = inject(ElementRef);
|
|
1413
|
+
this.numberFormatService = inject(NumberFormatService);
|
|
1414
|
+
this.injector = inject(Injector);
|
|
1415
|
+
this.unitPresentation = new NumericFieldUnitPresentation(this.inputElement, this.renderer, () => this.changeDetectorRef.markForCheck());
|
|
1416
|
+
this.changeFn = () => { };
|
|
1417
|
+
this.touchedFn = () => { };
|
|
928
1418
|
this.displayValue = '';
|
|
929
|
-
this.
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
1419
|
+
this.matInput = null;
|
|
1420
|
+
this.formatOptionsInitialized = false;
|
|
1421
|
+
this.numericValueEffect = effect(() => {
|
|
1422
|
+
const value = this.numericValue();
|
|
1423
|
+
// A two-way binding echo must preserve unfinished text and the user's caret.
|
|
1424
|
+
if (value !== UNSET_NUMERIC_VALUE && !Object.is(value, this.acceptedValue)) {
|
|
1425
|
+
untracked(() => this.applyExternalValue(value));
|
|
1426
|
+
}
|
|
1427
|
+
}, /* @ts-ignore */
|
|
1428
|
+
...(ngDevMode ? [{ debugName: "numericValueEffect" }] : /* istanbul ignore next */ []));
|
|
1429
|
+
this.formatOptionsEffect = effect(() => {
|
|
1430
|
+
this.decimalPlaces();
|
|
1431
|
+
this.autofillDecimals();
|
|
1432
|
+
this.roundValue();
|
|
1433
|
+
this.numberFormatService.decimalSeparator;
|
|
1434
|
+
this.numberFormatService.groupingSeparator;
|
|
1435
|
+
this.numberFormatService.allowedKeys;
|
|
1436
|
+
if (this.formatOptionsInitialized) {
|
|
1437
|
+
untracked(() => this.renderCurrentValue());
|
|
1438
|
+
}
|
|
1439
|
+
else {
|
|
1440
|
+
this.formatOptionsInitialized = true;
|
|
1441
|
+
}
|
|
1442
|
+
}, /* @ts-ignore */
|
|
1443
|
+
...(ngDevMode ? [{ debugName: "formatOptionsEffect" }] : /* istanbul ignore next */ []));
|
|
1444
|
+
// Unit layout restores consumer styles before measuring and then measures its
|
|
1445
|
+
// updated text. Keep that dependent transaction in one render, without delaying CVA.
|
|
1446
|
+
this.unitRendering = afterEveryRender({
|
|
1447
|
+
mixedReadWrite: () => this.unitPresentation.render({
|
|
1448
|
+
unit: this.unit(),
|
|
1449
|
+
unitPosition: this.unitPosition(),
|
|
1450
|
+
textAlign: this.textAlign(),
|
|
1451
|
+
text: this.displayValue,
|
|
1452
|
+
}, {
|
|
1453
|
+
id: this.formField?.getLabelId(),
|
|
1454
|
+
floating: this.formField?.floatLabel === 'always' || !!this.matInput?.shouldLabelFloat,
|
|
1455
|
+
}),
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
get inputElement() {
|
|
1459
|
+
return this.inputEl.nativeElement;
|
|
935
1460
|
}
|
|
936
1461
|
registerOnChange(fn) {
|
|
937
|
-
this.
|
|
1462
|
+
this.changeFn = fn;
|
|
938
1463
|
}
|
|
939
1464
|
registerOnTouched(fn) {
|
|
940
|
-
this.
|
|
1465
|
+
this.touchedFn = fn;
|
|
941
1466
|
}
|
|
942
|
-
setDisabledState() {
|
|
943
|
-
|
|
1467
|
+
setDisabledState(isDisabled) {
|
|
1468
|
+
this.renderer.setProperty(this.inputElement, 'disabled', isDisabled);
|
|
944
1469
|
}
|
|
945
1470
|
writeValue(value) {
|
|
946
|
-
this.
|
|
1471
|
+
untracked(() => this.applyExternalValue(value));
|
|
947
1472
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
this.
|
|
951
|
-
this.
|
|
952
|
-
this.formatInput(event.target, true);
|
|
953
|
-
});
|
|
954
|
-
this.keyupListener = this.renderer.listen(this.inputEl.nativeElement, 'keyup', (event) => {
|
|
955
|
-
if (event.keyCode === BACK_KEYCODE || (event.keyCode >= CONTROL_KEYCODES_UPPER_BORDER && !OTHER_CONTROL_KEYS.has(event.keyCode))) {
|
|
956
|
-
this.formatInput(event.target, false);
|
|
957
|
-
}
|
|
958
|
-
});
|
|
959
|
-
this.keydownListener = this.renderer.listen(this.inputEl.nativeElement, 'keydown', (event) => {
|
|
960
|
-
const value = event.target.value;
|
|
961
|
-
if (this.numberFormatService.allowedKeys.includes(event.key) ||
|
|
962
|
-
(event.keyCode <= CONTROL_KEYCODES_UPPER_BORDER && event.keyCode > 0 && event.keyCode !== SPACE_KEYCODE) ||
|
|
963
|
-
event.metaKey ||
|
|
964
|
-
event.ctrlKey ||
|
|
965
|
-
event.altKey) {
|
|
966
|
-
/* allow negative sign only as first character and none exists outside of text selection */
|
|
967
|
-
const indexNegativeSign = value.indexOf(NumberFormatService.NEGATIVE);
|
|
968
|
-
if (event.key === NumberFormatService.NEGATIVE &&
|
|
969
|
-
(event.target.selectionStart > 0 || indexNegativeSign > -1) &&
|
|
970
|
-
(event.target.selectionStart === event.target.selectionEnd ||
|
|
971
|
-
!(indexNegativeSign >= event.target.selectionStart && indexNegativeSign <= event.target.selectionEnd))) {
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
/* no duplicate decimal separators */
|
|
975
|
-
const indexDecimalSep = value.indexOf(this.numberFormatService.decimalSeparator);
|
|
976
|
-
if (event.key === this.numberFormatService.decimalSeparator &&
|
|
977
|
-
(indexDecimalSep > -1 || this.decimalPlaces === 0) &&
|
|
978
|
-
(event.target.selectionStart === event.target.selectionEnd ||
|
|
979
|
-
!(indexDecimalSep >= event.target.selectionStart && indexDecimalSep <= event.target.selectionEnd))) {
|
|
980
|
-
return false;
|
|
981
|
-
}
|
|
982
|
-
/* prevent too many decimal places */
|
|
983
|
-
if (NumberFormatService.NUMBERS.includes(event.key) &&
|
|
984
|
-
indexDecimalSep > -1 &&
|
|
985
|
-
indexDecimalSep < event.target.selectionStart &&
|
|
986
|
-
event.target.selectionStart === event.target.selectionEnd &&
|
|
987
|
-
value.length > indexDecimalSep + this.decimalPlaces) {
|
|
988
|
-
return false;
|
|
989
|
-
}
|
|
990
|
-
/* when deleting thousand separator, remove the digit before or after it */
|
|
991
|
-
const cursorStart = event.target.selectionStart;
|
|
992
|
-
if (cursorStart === event.target.selectionEnd) {
|
|
993
|
-
if (event.keyCode === BACK_KEYCODE && value.substr(cursorStart - 1, 1) === this.numberFormatService.groupingSeparator) {
|
|
994
|
-
event.target.value = value.substring(0, cursorStart - 2) + value.substring(cursorStart - 1, value.length);
|
|
995
|
-
event.target.selectionStart = event.target.selectionEnd = cursorStart - 1;
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
|
-
else if (event.keyCode === DEL_KEYCODE && value.substr(cursorStart, 1) === this.numberFormatService.groupingSeparator) {
|
|
999
|
-
event.target.value = value.substring(0, cursorStart + 1) + value.substring(cursorStart + 2, value.length);
|
|
1000
|
-
event.target.selectionStart = event.target.selectionEnd = cursorStart + 1;
|
|
1001
|
-
return false;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
this.originalValue = NaN;
|
|
1005
|
-
}
|
|
1006
|
-
else {
|
|
1007
|
-
return false;
|
|
1008
|
-
}
|
|
1009
|
-
return true;
|
|
1010
|
-
});
|
|
1473
|
+
ngAfterViewInit() {
|
|
1474
|
+
// Resolve after construction: MatInput also participates in forms injection.
|
|
1475
|
+
this.matInput = this.injector.get(MatInput, null, { self: true, optional: true });
|
|
1476
|
+
this.notifyMatInputStateChanged();
|
|
1011
1477
|
}
|
|
1012
1478
|
ngOnDestroy() {
|
|
1013
|
-
this.
|
|
1479
|
+
this.unitPresentation.destroy();
|
|
1014
1480
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
this.injectUnitSymbol();
|
|
1481
|
+
handleChangeEvent() {
|
|
1482
|
+
if (!this.inputElement.readOnly && !this.inputElement.disabled) {
|
|
1483
|
+
this.changeFn(this.getValueForFormControl());
|
|
1019
1484
|
}
|
|
1020
1485
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1486
|
+
handleInputEvent() {
|
|
1487
|
+
this.handleChangeEvent();
|
|
1488
|
+
}
|
|
1489
|
+
handleBlurEvent() {
|
|
1490
|
+
if (this.inputElement.disabled) {
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
this.formatInput(this.inputElement, true);
|
|
1494
|
+
this.touchedFn();
|
|
1495
|
+
}
|
|
1496
|
+
handleKeyDown(event) {
|
|
1497
|
+
const element = this.getEventInput(event);
|
|
1498
|
+
const value = element.value;
|
|
1499
|
+
if (element.readOnly || element.disabled) {
|
|
1500
|
+
return true;
|
|
1501
|
+
}
|
|
1502
|
+
if (event.metaKey || event.ctrlKey || event.altKey || CONTROL_KEYS.has(event.key)) {
|
|
1503
|
+
return this.handleControlKeyDown(event, element, value);
|
|
1504
|
+
}
|
|
1505
|
+
if (!this.numberFormatService.allowedKeys.includes(event.key)) {
|
|
1506
|
+
return this.preventDefault(event);
|
|
1507
|
+
}
|
|
1508
|
+
if (!this.isValidNegativeSign(event, element, value)) {
|
|
1509
|
+
return this.preventDefault(event);
|
|
1510
|
+
}
|
|
1511
|
+
if (!this.isValidDecimalSeparator(event, element, value)) {
|
|
1512
|
+
return this.preventDefault(event);
|
|
1513
|
+
}
|
|
1514
|
+
if (!this.isValidDecimalPlace(event, element, value)) {
|
|
1515
|
+
return this.preventDefault(event);
|
|
1516
|
+
}
|
|
1517
|
+
return true;
|
|
1518
|
+
}
|
|
1519
|
+
handleKeyUp(event) {
|
|
1520
|
+
if (event.metaKey || event.ctrlKey || event.altKey) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
if (event.key === 'Backspace' || event.key === 'Delete' || this.numberFormatService.allowedKeys.includes(event.key)) {
|
|
1524
|
+
this.formatInput(this.getEventInput(event), false);
|
|
1525
|
+
}
|
|
1031
1526
|
}
|
|
1032
1527
|
formatInput(element, finalFormatting) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1528
|
+
if (element.readOnly || element.disabled) {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
const acceptValue = this.formatInputValue(element, finalFormatting, this.displayValue !== element.value);
|
|
1532
|
+
if (acceptValue) {
|
|
1533
|
+
this.changeFn(this.acceptedFormValue());
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
updateInput(value) {
|
|
1537
|
+
this.writeDisplayValue(value);
|
|
1538
|
+
this.updateNumericValue(value);
|
|
1539
|
+
}
|
|
1540
|
+
getValueForFormControl() {
|
|
1541
|
+
this.formatInputValue(this.inputElement, false, true);
|
|
1542
|
+
return this.acceptedFormValue();
|
|
1543
|
+
}
|
|
1544
|
+
acceptedFormValue() {
|
|
1545
|
+
return typeof this.acceptedValue === 'number' && Number.isFinite(this.acceptedValue) ? this.acceptedValue : undefined;
|
|
1546
|
+
}
|
|
1547
|
+
formatInputValue(element, finalFormatting, acceptValue) {
|
|
1548
|
+
const rawValue = element.value;
|
|
1549
|
+
const { start, end } = this.getSelection(element);
|
|
1550
|
+
const direction = element.selectionDirection;
|
|
1551
|
+
const textFormatted = this.numberFormatService.formatNumber(rawValue, {
|
|
1552
|
+
decimalPlaces: this.decimalPlaces(),
|
|
1038
1553
|
finalFormatting,
|
|
1039
|
-
autofillDecimals: this.autofillDecimals,
|
|
1554
|
+
autofillDecimals: this.autofillDecimals(),
|
|
1040
1555
|
});
|
|
1041
|
-
//
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
this.
|
|
1045
|
-
|
|
1046
|
-
this.
|
|
1047
|
-
this.
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
this.textSpan.style.width = 'auto';
|
|
1055
|
-
this.textSpan.style.position = 'absolute';
|
|
1056
|
-
this.textSpan.style.top = '0';
|
|
1057
|
-
this.textSpan.style.whiteSpace = 'no-wrap';
|
|
1058
|
-
this.textSpan.style.visibility = 'hidden';
|
|
1059
|
-
}
|
|
1060
|
-
this.textSpan.innerHTML = textFormatted;
|
|
1061
|
-
const width = Math.min(this.inputEl.nativeElement.clientWidth - this.unitSpan.clientWidth, Math.ceil(this.textSpan.clientWidth));
|
|
1062
|
-
this.unitSpan.style.left = width + 'px';
|
|
1556
|
+
// Final formatting can resolve an accepted invalid partial edit (e.g. ".")
|
|
1557
|
+
// to zero. Presentation-only changes to finite external values stay silent.
|
|
1558
|
+
const resolvesPartialEdit = finalFormatting &&
|
|
1559
|
+
Number.isNaN(this.acceptedValue) &&
|
|
1560
|
+
rawValue !== '' &&
|
|
1561
|
+
!Number.isFinite(this.parseNumericValue(rawValue)) &&
|
|
1562
|
+
Number.isFinite(this.parseNumericValue(textFormatted));
|
|
1563
|
+
const acceptsEdit = acceptValue || resolvesPartialEdit;
|
|
1564
|
+
if (acceptsEdit) {
|
|
1565
|
+
this.updateInput(textFormatted);
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
this.writeDisplayValue(textFormatted);
|
|
1063
1569
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1570
|
+
if (rawValue !== textFormatted) {
|
|
1571
|
+
const mapped = mapNormalizedSelection({ start, end }, {
|
|
1572
|
+
rawValue,
|
|
1573
|
+
normalizedValue: this.numberFormatService.strip(rawValue, {
|
|
1574
|
+
decimalPlaces: this.decimalPlaces(),
|
|
1575
|
+
removeLeadingZeros: finalFormatting,
|
|
1576
|
+
}),
|
|
1577
|
+
formattedValue: textFormatted,
|
|
1578
|
+
groupingSeparator: this.numberFormatService.groupingSeparator,
|
|
1579
|
+
decimalSeparator: this.numberFormatService.decimalSeparator,
|
|
1580
|
+
});
|
|
1581
|
+
element.setSelectionRange(mapped.start, mapped.end, direction);
|
|
1067
1582
|
}
|
|
1583
|
+
return acceptsEdit;
|
|
1068
1584
|
}
|
|
1069
|
-
|
|
1585
|
+
writeDisplayValue(value) {
|
|
1070
1586
|
this.displayValue = value;
|
|
1071
|
-
this.
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1587
|
+
this.unitPresentation.invalidateLayout();
|
|
1588
|
+
if (this.inputElement.value !== value) {
|
|
1589
|
+
this.inputElement.value = value;
|
|
1590
|
+
}
|
|
1591
|
+
this.notifyMatInputStateChanged();
|
|
1592
|
+
this.changeDetectorRef.markForCheck();
|
|
1593
|
+
}
|
|
1594
|
+
updateNumericValue(value) {
|
|
1595
|
+
const previousValue = this.acceptedValue;
|
|
1596
|
+
const parsedValue = this.parseNumericValue(value);
|
|
1597
|
+
this.acceptedValue = parsedValue;
|
|
1598
|
+
if (parsedValue !== previousValue) {
|
|
1599
|
+
this.numericValueChanged.emit(parsedValue);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
renderCurrentValue() {
|
|
1603
|
+
const value = this.acceptedValue;
|
|
1604
|
+
const displayNumber = typeof value === 'number' && Number.isFinite(value)
|
|
1605
|
+
? roundOrTruncateNumber(value, this.decimalPlaces(), this.roundValue())
|
|
1606
|
+
: undefined;
|
|
1607
|
+
this.writeDisplayValue(this.numberFormatService.format(displayNumber, {
|
|
1608
|
+
decimalPlaces: this.decimalPlaces(),
|
|
1609
|
+
finalFormatting: true,
|
|
1610
|
+
autofillDecimals: this.autofillDecimals(),
|
|
1611
|
+
}));
|
|
1077
1612
|
}
|
|
1078
|
-
|
|
1079
|
-
this.
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
injectUnitSymbol() {
|
|
1087
|
-
// Need to inject the unit symbol when the input element width is set to its actual value,
|
|
1088
|
-
// otherwise the icon wont show in the correct position
|
|
1089
|
-
if (!!this.unit && !this.unitSpan && this.inputEl.nativeElement.offsetWidth !== 0) {
|
|
1090
|
-
// Get the input wrapper and apply necessary styles
|
|
1091
|
-
const inputWrapper = this.inputEl.nativeElement.parentNode.parentNode;
|
|
1092
|
-
// Create the span with unit symbol and apply necessary styles
|
|
1093
|
-
this.unitSpan = this.renderer.createElement('span');
|
|
1094
|
-
if (this.unitPosition === 'left') {
|
|
1095
|
-
this.renderer.setAttribute(this.unitSpan, 'matPrefix', '');
|
|
1096
|
-
this.renderer.setStyle(this.unitSpan, 'padding-right', '5px');
|
|
1097
|
-
this.renderer.insertBefore(inputWrapper, this.unitSpan, inputWrapper.children[0]);
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
this.renderer.setAttribute(this.unitSpan, 'matSuffix', '');
|
|
1101
|
-
this.renderer.setStyle(this.unitSpan, 'padding-left', '5px');
|
|
1102
|
-
this.renderer.appendChild(inputWrapper, this.unitSpan);
|
|
1103
|
-
}
|
|
1613
|
+
applyExternalValue(value) {
|
|
1614
|
+
this.acceptedValue = value;
|
|
1615
|
+
this.renderCurrentValue();
|
|
1616
|
+
}
|
|
1617
|
+
handleControlKeyDown(event, element, value) {
|
|
1618
|
+
if (event.key !== 'Backspace' && event.key !== 'Delete') {
|
|
1619
|
+
return true;
|
|
1104
1620
|
}
|
|
1105
|
-
|
|
1106
|
-
if (
|
|
1107
|
-
|
|
1108
|
-
this.unitSpan.style.display = 'unset';
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
this.unitSpan.style.display = 'none';
|
|
1112
|
-
}
|
|
1621
|
+
const { start: cursorStart, end: cursorEnd } = this.getSelection(element);
|
|
1622
|
+
if (cursorStart !== cursorEnd) {
|
|
1623
|
+
return true;
|
|
1113
1624
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
this.
|
|
1625
|
+
if (event.key === 'Backspace' && value.charAt(cursorStart - 1) === this.numberFormatService.groupingSeparator) {
|
|
1626
|
+
element.value = value.substring(0, Math.max(cursorStart - 2, 0)) + value.substring(cursorStart - 1, value.length);
|
|
1627
|
+
this.updateInput(element.value);
|
|
1628
|
+
this.changeFn(this.acceptedFormValue());
|
|
1629
|
+
this.setCursorPosition(element, Math.max(cursorStart - 1, 0));
|
|
1630
|
+
return this.preventDefault(event);
|
|
1117
1631
|
}
|
|
1632
|
+
if (event.key === 'Delete' && value.charAt(cursorStart) === this.numberFormatService.groupingSeparator) {
|
|
1633
|
+
element.value = value.substring(0, cursorStart + 1) + value.substring(cursorStart + 2, value.length);
|
|
1634
|
+
this.updateInput(element.value);
|
|
1635
|
+
this.changeFn(this.acceptedFormValue());
|
|
1636
|
+
this.setCursorPosition(element, cursorStart + 1);
|
|
1637
|
+
return this.preventDefault(event);
|
|
1638
|
+
}
|
|
1639
|
+
return true;
|
|
1118
1640
|
}
|
|
1119
|
-
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
delete this.inputChangeListener;
|
|
1641
|
+
isValidNegativeSign(event, element, value) {
|
|
1642
|
+
if (event.key !== NumberFormatService.NEGATIVE) {
|
|
1643
|
+
return true;
|
|
1123
1644
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1645
|
+
const { start: selectionStart, end: selectionEnd } = this.getSelection(element);
|
|
1646
|
+
const indexNegativeSign = value.indexOf(NumberFormatService.NEGATIVE);
|
|
1647
|
+
return (selectionStart === 0 &&
|
|
1648
|
+
(indexNegativeSign === -1 ||
|
|
1649
|
+
(selectionStart !== selectionEnd && indexNegativeSign >= selectionStart && indexNegativeSign < selectionEnd)));
|
|
1650
|
+
}
|
|
1651
|
+
isValidDecimalSeparator(event, element, value) {
|
|
1652
|
+
if (event.key !== this.numberFormatService.decimalSeparator) {
|
|
1653
|
+
return true;
|
|
1127
1654
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1655
|
+
const { start: selectionStart, end: selectionEnd } = this.getSelection(element);
|
|
1656
|
+
const indexDecimalSep = value.indexOf(this.numberFormatService.decimalSeparator);
|
|
1657
|
+
if (this.decimalPlaces() === 0) {
|
|
1658
|
+
return false;
|
|
1131
1659
|
}
|
|
1660
|
+
return (indexDecimalSep === -1 ||
|
|
1661
|
+
(this.decimalPlaces() > 0 && selectionStart !== selectionEnd && indexDecimalSep >= selectionStart && indexDecimalSep < selectionEnd));
|
|
1132
1662
|
}
|
|
1133
|
-
|
|
1134
|
-
if (
|
|
1135
|
-
return
|
|
1663
|
+
isValidDecimalPlace(event, element, value) {
|
|
1664
|
+
if (!NumberFormatService.NUMBERS.includes(event.key)) {
|
|
1665
|
+
return true;
|
|
1136
1666
|
}
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1667
|
+
const { start: selectionStart, end: selectionEnd } = this.getSelection(element);
|
|
1668
|
+
const indexDecimalSep = value.indexOf(this.numberFormatService.decimalSeparator);
|
|
1669
|
+
return (indexDecimalSep === -1 ||
|
|
1670
|
+
indexDecimalSep >= selectionStart ||
|
|
1671
|
+
selectionStart !== selectionEnd ||
|
|
1672
|
+
value.length <= indexDecimalSep + this.decimalPlaces());
|
|
1673
|
+
}
|
|
1674
|
+
getSelection(element) {
|
|
1675
|
+
const start = element.selectionStart ?? 0;
|
|
1676
|
+
return { start, end: element.selectionEnd ?? start };
|
|
1677
|
+
}
|
|
1678
|
+
getEventInput(event) {
|
|
1679
|
+
return event.target instanceof HTMLInputElement ? event.target : this.inputElement;
|
|
1680
|
+
}
|
|
1681
|
+
preventDefault(event) {
|
|
1682
|
+
event.preventDefault();
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
notifyMatInputStateChanged() {
|
|
1686
|
+
this.matInput?.stateChanges.next();
|
|
1687
|
+
}
|
|
1688
|
+
parseNumericValue(value) {
|
|
1689
|
+
const parsedValue = Number.parseFloat(this.numberFormatService
|
|
1690
|
+
.strip(value, { decimalPlaces: this.decimalPlaces() })
|
|
1691
|
+
.replace(this.numberFormatService.decimalSeparator, '.'));
|
|
1692
|
+
return Number.isFinite(parsedValue) ? parsedValue : NaN;
|
|
1139
1693
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1694
|
+
setCursorPosition(element, position) {
|
|
1695
|
+
element.setSelectionRange(position, position);
|
|
1696
|
+
}
|
|
1697
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: NumericFieldDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1698
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.4", type: NumericFieldDirective, isStandalone: true, selector: "[madNumericField]", inputs: { textAlign: { classPropertyName: "textAlign", publicName: "textAlign", isSignal: true, isRequired: false, transformFunction: null }, decimalPlaces: { classPropertyName: "decimalPlaces", publicName: "decimalPlaces", isSignal: true, isRequired: false, transformFunction: null }, roundValue: { classPropertyName: "roundValue", publicName: "roundDisplayValue", isSignal: true, isRequired: false, transformFunction: null }, autofillDecimals: { classPropertyName: "autofillDecimals", publicName: "autofillDecimals", isSignal: true, isRequired: false, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, unitPosition: { classPropertyName: "unitPosition", publicName: "unitPosition", isSignal: true, isRequired: false, transformFunction: null }, numericValue: { classPropertyName: "numericValue", publicName: "numericValue", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { numericValueChanged: "numericValueChange" }, host: { listeners: { "change": "handleChangeEvent()", "input": "handleInputEvent()", "blur": "handleBlurEvent()", "keydown": "handleKeyDown($event)", "keyup": "handleKeyUp($event)" }, properties: { "class.text-right": "textAlign() === \"right\"" } }, providers: [
|
|
1142
1699
|
{
|
|
1143
1700
|
provide: NG_VALUE_ACCESSOR,
|
|
1144
1701
|
useExisting: forwardRef(() => NumericFieldDirective),
|
|
@@ -1151,10 +1708,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
1151
1708
|
args: [{
|
|
1152
1709
|
selector: '[madNumericField]',
|
|
1153
1710
|
host: {
|
|
1154
|
-
'[class.text-right]': 'textAlign === "right"',
|
|
1155
|
-
'(change)': '
|
|
1156
|
-
'(input)': '
|
|
1157
|
-
'(blur)': '
|
|
1711
|
+
'[class.text-right]': 'textAlign() === "right"',
|
|
1712
|
+
'(change)': 'handleChangeEvent()',
|
|
1713
|
+
'(input)': 'handleInputEvent()',
|
|
1714
|
+
'(blur)': 'handleBlurEvent()',
|
|
1715
|
+
'(keydown)': 'handleKeyDown($event)',
|
|
1716
|
+
'(keyup)': 'handleKeyUp($event)',
|
|
1158
1717
|
},
|
|
1159
1718
|
providers: [
|
|
1160
1719
|
{
|
|
@@ -1163,33 +1722,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
1163
1722
|
multi: true,
|
|
1164
1723
|
},
|
|
1165
1724
|
],
|
|
1166
|
-
standalone: true,
|
|
1167
1725
|
}]
|
|
1168
|
-
}],
|
|
1169
|
-
type: Input,
|
|
1170
|
-
args: ['textAlign']
|
|
1171
|
-
}], decimalPlaces: [{
|
|
1172
|
-
type: Input,
|
|
1173
|
-
args: ['decimalPlaces']
|
|
1174
|
-
}], roundValue: [{
|
|
1175
|
-
type: Input,
|
|
1176
|
-
args: ['roundDisplayValue']
|
|
1177
|
-
}], autofillDecimals: [{
|
|
1178
|
-
type: Input,
|
|
1179
|
-
args: ['autofillDecimals']
|
|
1180
|
-
}], unit: [{
|
|
1181
|
-
type: Input,
|
|
1182
|
-
args: ['unit']
|
|
1183
|
-
}], unitPosition: [{
|
|
1184
|
-
type: Input,
|
|
1185
|
-
args: ['unitPosition']
|
|
1186
|
-
}], numericValueChanged: [{
|
|
1187
|
-
type: Output,
|
|
1188
|
-
args: ['numericValueChange']
|
|
1189
|
-
}], numericValue: [{
|
|
1190
|
-
type: Input,
|
|
1191
|
-
args: ['numericValue']
|
|
1192
|
-
}] } });
|
|
1726
|
+
}], propDecorators: { textAlign: [{ type: i0.Input, args: [{ isSignal: true, alias: "textAlign", required: false }] }], decimalPlaces: [{ type: i0.Input, args: [{ isSignal: true, alias: "decimalPlaces", required: false }] }], roundValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "roundDisplayValue", required: false }] }], autofillDecimals: [{ type: i0.Input, args: [{ isSignal: true, alias: "autofillDecimals", required: false }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], unitPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "unitPosition", required: false }] }], numericValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "numericValue", required: false }] }], numericValueChanged: [{ type: i0.Output, args: ["numericValueChange"] }] } });
|
|
1193
1727
|
|
|
1194
1728
|
class NumericFieldModule {
|
|
1195
1729
|
static forRoot() {
|
|
@@ -4507,7 +5041,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
4507
5041
|
args: [{ selector: 'mad-breadcrumb', imports: [RouterLink, IconButtonComponent, MatIcon, MatTooltip], template: "@if (breadcrumbs().length) {\n <div class=\"breadcrumb\">\n <nav data-cy=\"breadcrumb-nav\" class=\"breadcrumb__nav\">\n @for (crumb of breadcrumbs(); track crumb.label; let last = $last) {\n @if (crumb.route?.length) {\n <a data-cy=\"breadcrumb-link\" [routerLink]=\"crumb.route\" class=\"breadcrumb__link\">{{ crumb.label }}</a>\n } @else if (crumb.href?.length) {\n <a data-cy=\"breadcrumb-link\" [href]=\"crumb.href\" target=\"_blank\" class=\"breadcrumb__link\">{{ crumb.label }}</a>\n } @else {\n <span data-cy=\"breadcrumb-current\" class=\"breadcrumb__current\">{{ crumb.label }}</span>\n }\n @if (!last) {\n <span data-cy=\"breadcrumb-separator\" class=\"breadcrumb__separator\">/</span>\n }\n }\n </nav>\n @if (showCopy()) {\n <mad-icon-button\n data-cy=\"breadcrumb-copy\"\n class=\"breadcrumb__copy\"\n (click)=\"copy.emit()\"\n [matTooltip]=\"title()\"\n matTooltipPosition=\"above\"\n >\n <mat-icon>content_copy</mat-icon>\n </mad-icon-button>\n }\n </div>\n}\n", styles: [".breadcrumb{display:flex;align-items:center;gap:.5rem}.breadcrumb__nav{display:flex;align-items:center;gap:.625rem;min-height:3.5rem;padding-block:.25rem;font-size:.875rem;line-height:1.25rem}.breadcrumb__link{color:var(--main-primary);text-decoration:none}.breadcrumb__link:hover{text-decoration:underline}.breadcrumb__current,.breadcrumb__separator{color:var(--breadcrumb-separator-color)}.breadcrumb__copy{flex-shrink:0}\n"] }]
|
|
4508
5042
|
}], propDecorators: { breadcrumbs: [{ type: i0.Input, args: [{ isSignal: true, alias: "breadcrumbs", required: true }] }], showCopy: [{ type: i0.Input, args: [{ isSignal: true, alias: "showCopy", required: false }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], copy: [{ type: i0.Output, args: ["copy"] }] } });
|
|
4509
5043
|
|
|
4510
|
-
const VERSION = '22.
|
|
5044
|
+
const VERSION = '22.5.0';
|
|
4511
5045
|
|
|
4512
5046
|
const MAD_ALERT_DEFAULT_CONFIGURATION = new InjectionToken('mad-alert-configuration', {
|
|
4513
5047
|
providedIn: 'root',
|
|
@@ -4533,6 +5067,8 @@ class AlertComponent {
|
|
|
4533
5067
|
...(ngDevMode ? [{ debugName: "actionText" }] : /* istanbul ignore next */ []));
|
|
4534
5068
|
this.closeable = input(true, /* @ts-ignore */
|
|
4535
5069
|
...(ngDevMode ? [{ debugName: "closeable" }] : /* istanbul ignore next */ []));
|
|
5070
|
+
this.useProjectedContent = input(false, /* @ts-ignore */
|
|
5071
|
+
...(ngDevMode ? [{ debugName: "useProjectedContent" }] : /* istanbul ignore next */ []));
|
|
4536
5072
|
this.close = output();
|
|
4537
5073
|
this.action = output();
|
|
4538
5074
|
this.classes = computed(() => `${this.type()} ${this.size()}`, /* @ts-ignore */
|
|
@@ -4552,15 +5088,15 @@ class AlertComponent {
|
|
|
4552
5088
|
...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
4553
5089
|
}
|
|
4554
5090
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: AlertComponent, deps: [{ token: MAD_ALERT_DEFAULT_CONFIGURATION }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4555
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.4", type: AlertComponent, isStandalone: true, selector: "mad-alert", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, message: { classPropertyName: "message", publicName: "message", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, actionText: { classPropertyName: "actionText", publicName: "actionText", isSignal: true, isRequired: false, transformFunction: null }, closeable: { classPropertyName: "closeable", publicName: "closeable", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { close: "close", action: "action" }, ngImport: i0, template: "<div data-cy=\"alert\" class=\"alert\" [class]=\"classes()\">\n <span data-cy=\"alert-icon\" class=\"icon\">\n <mat-icon>{{ icon() }}</mat-icon>\n </span>\n <span data-cy=\"alert-message\" class=\"message\">{{ message() }}</span>\n @if (actionText()) {\n <span data-cy=\"alert-action-btn\" class=\"action-btn\" (click)=\"action.emit()\">\n {{ actionText() }}\n </span>\n }\n @if (closeable()) {\n <button mat-icon-button data-cy=\"alert-close-btn\" class=\"close-btn\" (click)=\"close.emit()\">\n <mat-icon>close</mat-icon>\n </button>\n }\n</div>\n", styles: [".alert{display:flex;align-items:center;padding:16px;border-radius:4px;margin:8px 0;font-size:14px;position:relative;border:1px solid transparent}.alert.small{padding:0 8px;font-size:14px}.alert.medium{padding:8px;font-size:16px}.alert.large{padding:12px 8px;font-size:18px}.alert .icon{margin-right:8px;display:flex;align-items:center}.alert .message{flex:1}.alert .action-btn,.alert .close-btn{color:inherit;margin-left:auto;padding:0}.alert .action-btn{text-decoration:underline;cursor:pointer}.alert .close-btn{display:flex;align-items:center;justify-content:center}.alert.success{background-color:var(--alert-success-background-color);border-color:var(--alert-success-border-color);color:var(--alert-success-text-color)}.alert.info{background-color:var(--alert-info-background-color);border-color:var(--alert-info-border-color);color:var(--alert-info-text-color)}.alert.warning{background-color:var(--alert-warning-background-color);border-color:var(--alert-warning-border-color);color:var(--alert-warning-text-color)}.alert.error{background-color:var(--alert-error-background-color);border-color:var(--alert-error-border-color);color:var(--alert-error-text-color)}\n"], dependencies: [{ kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }] }); }
|
|
5091
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.4", type: AlertComponent, isStandalone: true, selector: "mad-alert", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, message: { classPropertyName: "message", publicName: "message", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, actionText: { classPropertyName: "actionText", publicName: "actionText", isSignal: true, isRequired: false, transformFunction: null }, closeable: { classPropertyName: "closeable", publicName: "closeable", isSignal: true, isRequired: false, transformFunction: null }, useProjectedContent: { classPropertyName: "useProjectedContent", publicName: "useProjectedContent", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { close: "close", action: "action" }, ngImport: i0, template: "<div data-cy=\"alert\" class=\"alert\" [class]=\"classes()\">\n <span data-cy=\"alert-icon\" class=\"icon\">\n <mat-icon>{{ icon() }}</mat-icon>\n </span>\n @if (useProjectedContent()) {\n <ng-content />\n } @else {\n <span data-cy=\"alert-message\" class=\"message\">{{ message() }}</span>\n }\n\n @if (actionText()) {\n <span data-cy=\"alert-action-btn\" class=\"action-btn\" (click)=\"action.emit()\">\n {{ actionText() }}\n </span>\n }\n @if (closeable()) {\n <button mat-icon-button data-cy=\"alert-close-btn\" class=\"close-btn\" (click)=\"close.emit()\">\n <mat-icon>close</mat-icon>\n </button>\n }\n</div>\n", styles: [".alert{display:flex;align-items:center;padding:16px;border-radius:4px;margin:8px 0;font-size:14px;position:relative;border:1px solid transparent}.alert.small{padding:0 8px;font-size:14px}.alert.medium{padding:8px;font-size:16px}.alert.large{padding:12px 8px;font-size:18px}.alert .icon{margin-right:8px;display:flex;align-items:center}.alert .message{flex:1}.alert .action-btn,.alert .close-btn{color:inherit;margin-left:auto;padding:0}.alert .action-btn{text-decoration:underline;cursor:pointer}.alert .close-btn{display:flex;align-items:center;justify-content:center}.alert.success{background-color:var(--alert-success-background-color);border-color:var(--alert-success-border-color);color:var(--alert-success-text-color)}.alert.info{background-color:var(--alert-info-background-color);border-color:var(--alert-info-border-color);color:var(--alert-info-text-color)}.alert.warning{background-color:var(--alert-warning-background-color);border-color:var(--alert-warning-border-color);color:var(--alert-warning-text-color)}.alert.error{background-color:var(--alert-error-background-color);border-color:var(--alert-error-border-color);color:var(--alert-error-text-color)}\n"], dependencies: [{ kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i1.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }] }); }
|
|
4556
5092
|
}
|
|
4557
5093
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: AlertComponent, decorators: [{
|
|
4558
5094
|
type: Component,
|
|
4559
|
-
args: [{ selector: 'mad-alert', imports: [MatIconModule, MatButtonModule], template: "<div data-cy=\"alert\" class=\"alert\" [class]=\"classes()\">\n <span data-cy=\"alert-icon\" class=\"icon\">\n <mat-icon>{{ icon() }}</mat-icon>\n </span>\n <span data-cy=\"alert-message\" class=\"message\">{{ message() }}</span>\n @if (actionText()) {\n <span data-cy=\"alert-action-btn\" class=\"action-btn\" (click)=\"action.emit()\">\n {{ actionText() }}\n </span>\n }\n @if (closeable()) {\n <button mat-icon-button data-cy=\"alert-close-btn\" class=\"close-btn\" (click)=\"close.emit()\">\n <mat-icon>close</mat-icon>\n </button>\n }\n</div>\n", styles: [".alert{display:flex;align-items:center;padding:16px;border-radius:4px;margin:8px 0;font-size:14px;position:relative;border:1px solid transparent}.alert.small{padding:0 8px;font-size:14px}.alert.medium{padding:8px;font-size:16px}.alert.large{padding:12px 8px;font-size:18px}.alert .icon{margin-right:8px;display:flex;align-items:center}.alert .message{flex:1}.alert .action-btn,.alert .close-btn{color:inherit;margin-left:auto;padding:0}.alert .action-btn{text-decoration:underline;cursor:pointer}.alert .close-btn{display:flex;align-items:center;justify-content:center}.alert.success{background-color:var(--alert-success-background-color);border-color:var(--alert-success-border-color);color:var(--alert-success-text-color)}.alert.info{background-color:var(--alert-info-background-color);border-color:var(--alert-info-border-color);color:var(--alert-info-text-color)}.alert.warning{background-color:var(--alert-warning-background-color);border-color:var(--alert-warning-border-color);color:var(--alert-warning-text-color)}.alert.error{background-color:var(--alert-error-background-color);border-color:var(--alert-error-border-color);color:var(--alert-error-text-color)}\n"] }]
|
|
5095
|
+
args: [{ selector: 'mad-alert', imports: [MatIconModule, MatButtonModule], template: "<div data-cy=\"alert\" class=\"alert\" [class]=\"classes()\">\n <span data-cy=\"alert-icon\" class=\"icon\">\n <mat-icon>{{ icon() }}</mat-icon>\n </span>\n @if (useProjectedContent()) {\n <ng-content />\n } @else {\n <span data-cy=\"alert-message\" class=\"message\">{{ message() }}</span>\n }\n\n @if (actionText()) {\n <span data-cy=\"alert-action-btn\" class=\"action-btn\" (click)=\"action.emit()\">\n {{ actionText() }}\n </span>\n }\n @if (closeable()) {\n <button mat-icon-button data-cy=\"alert-close-btn\" class=\"close-btn\" (click)=\"close.emit()\">\n <mat-icon>close</mat-icon>\n </button>\n }\n</div>\n", styles: [".alert{display:flex;align-items:center;padding:16px;border-radius:4px;margin:8px 0;font-size:14px;position:relative;border:1px solid transparent}.alert.small{padding:0 8px;font-size:14px}.alert.medium{padding:8px;font-size:16px}.alert.large{padding:12px 8px;font-size:18px}.alert .icon{margin-right:8px;display:flex;align-items:center}.alert .message{flex:1}.alert .action-btn,.alert .close-btn{color:inherit;margin-left:auto;padding:0}.alert .action-btn{text-decoration:underline;cursor:pointer}.alert .close-btn{display:flex;align-items:center;justify-content:center}.alert.success{background-color:var(--alert-success-background-color);border-color:var(--alert-success-border-color);color:var(--alert-success-text-color)}.alert.info{background-color:var(--alert-info-background-color);border-color:var(--alert-info-border-color);color:var(--alert-info-text-color)}.alert.warning{background-color:var(--alert-warning-background-color);border-color:var(--alert-warning-border-color);color:var(--alert-warning-text-color)}.alert.error{background-color:var(--alert-error-background-color);border-color:var(--alert-error-border-color);color:var(--alert-error-text-color)}\n"] }]
|
|
4560
5096
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
4561
5097
|
type: Inject,
|
|
4562
5098
|
args: [MAD_ALERT_DEFAULT_CONFIGURATION]
|
|
4563
|
-
}] }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], message: [{ type: i0.Input, args: [{ isSignal: true, alias: "message", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], actionText: [{ type: i0.Input, args: [{ isSignal: true, alias: "actionText", required: false }] }], closeable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeable", required: false }] }], close: [{ type: i0.Output, args: ["close"] }], action: [{ type: i0.Output, args: ["action"] }] } });
|
|
5099
|
+
}] }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], message: [{ type: i0.Input, args: [{ isSignal: true, alias: "message", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], actionText: [{ type: i0.Input, args: [{ isSignal: true, alias: "actionText", required: false }] }], closeable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeable", required: false }] }], useProjectedContent: [{ type: i0.Input, args: [{ isSignal: true, alias: "useProjectedContent", required: false }] }], close: [{ type: i0.Output, args: ["close"] }], action: [{ type: i0.Output, args: ["action"] }] } });
|
|
4564
5100
|
|
|
4565
5101
|
const DEFAULT_FILE_PREVIEW_CONFIG = {
|
|
4566
5102
|
thumbnailSize: 'md',
|