@ardium-ui/ui 3.3.0-alpha.9 → 3.3.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.
- package/esm2022/lib/_internal/selectable-list-component.mjs +2 -2
- package/esm2022/lib/inputs/digit-input/digit-input.component.mjs +12 -8
- package/esm2022/lib/inputs/digit-input/digit-input.model.mjs +33 -22
- package/esm2022/lib/inputs/digit-input/digit-input.types.mjs +1 -1
- package/esm2022/lib/select/select.component.mjs +2 -2
- package/fesm2022/ardium-ui-ui.mjs +45 -30
- package/fesm2022/ardium-ui-ui.mjs.map +1 -1
- package/lib/inputs/digit-input/digit-input.model.d.ts +0 -1
- package/lib/inputs/digit-input/digit-input.types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -359,8 +359,7 @@ class DigitInputModel {
|
|
|
359
359
|
this._ardHost = _ardHost;
|
|
360
360
|
this._configArray = signal([]);
|
|
361
361
|
this.configArrayData = computed(() => {
|
|
362
|
-
|
|
363
|
-
return this._configArray().map(v => {
|
|
362
|
+
return this._configArray().map((v, i) => {
|
|
364
363
|
if ('static' in v) {
|
|
365
364
|
return {
|
|
366
365
|
type: DigitInputConfigDataType.Static,
|
|
@@ -369,29 +368,32 @@ class DigitInputModel {
|
|
|
369
368
|
}
|
|
370
369
|
return {
|
|
371
370
|
type: DigitInputConfigDataType.Input,
|
|
372
|
-
index:
|
|
371
|
+
index: i,
|
|
373
372
|
readonly: v.readonly,
|
|
374
373
|
placeholder: v.placeholder ?? '',
|
|
375
374
|
};
|
|
376
375
|
});
|
|
377
376
|
});
|
|
378
|
-
this._configArrayNoStatics = computed(() => this._configArray().filter(v => !('static' in v)));
|
|
379
377
|
this.isConfigDefined = computed(() => this._configArray().length > 0);
|
|
380
378
|
this.value = signal(null);
|
|
381
379
|
this.stringValue = computed(() => this.value()
|
|
382
380
|
?.map(v => v ?? ' ')
|
|
383
|
-
.join('')
|
|
384
|
-
|
|
385
|
-
this.isValueFull = computed(() => this.value()?.filter(v => v).length === this._configArrayNoStatics().length);
|
|
381
|
+
.join('') ?? '');
|
|
382
|
+
this.isValueFull = computed(() => this.value()?.filter(v => v).length === this._configArray().length);
|
|
386
383
|
//set the value array to be the same length
|
|
387
384
|
effect(() => {
|
|
388
|
-
const
|
|
385
|
+
const configArr = this.configArrayData();
|
|
386
|
+
const length = configArr.length;
|
|
389
387
|
this.value.update(arr => {
|
|
390
388
|
if (!arr)
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
389
|
+
arr = [];
|
|
390
|
+
const newArr = [];
|
|
391
|
+
for (let i = 0; i < length; i++) {
|
|
392
|
+
const curr = arr[i];
|
|
393
|
+
const config = configArr[i];
|
|
394
|
+
newArr.push(config.type === DigitInputConfigDataType.Static ? config.char : curr ?? null);
|
|
395
|
+
}
|
|
396
|
+
return newArr;
|
|
395
397
|
});
|
|
396
398
|
}, { allowSignalWrites: true });
|
|
397
399
|
}
|
|
@@ -404,8 +406,8 @@ class DigitInputModel {
|
|
|
404
406
|
throw new Error(`ARD-FT0040b: Trying to set <ard-digit-input>'s value to "${v}" (of type ${typeof v}), but the input uses [outputAsString]="true", and thus expects string or null.`);
|
|
405
407
|
}
|
|
406
408
|
const vArray = v?.split('') ?? [];
|
|
407
|
-
if (vArray.length > this.
|
|
408
|
-
console.warn(`ARD-WA0041: Value provided to <ard-digit-input> is too long. Got ${vArray.length} characters, but expected a maximum of ${this.
|
|
409
|
+
if (vArray.length > this._configArray().length) {
|
|
410
|
+
console.warn(`ARD-WA0041: Value provided to <ard-digit-input> is too long. Got ${vArray.length} characters, but expected a maximum of ${this._configArray().length} characters.`);
|
|
409
411
|
}
|
|
410
412
|
return this._writeValue(vArray);
|
|
411
413
|
}
|
|
@@ -413,8 +415,8 @@ class DigitInputModel {
|
|
|
413
415
|
throw new Error(`ARD-FT0041: Trying to set <ard-digit-input>'s value to "${v}" (of type ${typeof v}), expected string or array of characters.`);
|
|
414
416
|
}
|
|
415
417
|
const vArray = coerceArrayProperty(v);
|
|
416
|
-
if (vArray.length > this.
|
|
417
|
-
console.warn(`ARD-WA0041: Value provided to <ard-digit-input> is too long. Got ${vArray.length} characters, but expected a maximum of ${this.
|
|
418
|
+
if (vArray.length > this._configArray().length) {
|
|
419
|
+
console.warn(`ARD-WA0041: Value provided to <ard-digit-input> is too long. Got ${vArray.length} characters, but expected a maximum of ${this._configArray().length} characters.`);
|
|
418
420
|
}
|
|
419
421
|
const problemIndex = vArray.findIndex(el => !isAnyString(el) || el.length > 1);
|
|
420
422
|
if (problemIndex !== -1) {
|
|
@@ -488,7 +490,7 @@ class DigitInputModel {
|
|
|
488
490
|
}
|
|
489
491
|
//! validate against the config
|
|
490
492
|
validateInputAndSetValue(input, index) {
|
|
491
|
-
if (index < 0 || index > this.
|
|
493
|
+
if (index < 0 || index > this._configArray().length)
|
|
492
494
|
return null;
|
|
493
495
|
let v = this.value();
|
|
494
496
|
//prepare the value array if does not exist
|
|
@@ -507,7 +509,7 @@ class DigitInputModel {
|
|
|
507
509
|
const lastChar = input.charAt(input.length - 1);
|
|
508
510
|
input = firstChar === before ? lastChar : firstChar;
|
|
509
511
|
//validate and transform, if necessary
|
|
510
|
-
const inputChar = this._validateSingleChar(input, before, this.
|
|
512
|
+
const inputChar = this._validateSingleChar(input, before, this._configArray()[index]);
|
|
511
513
|
//get the corresponding HTML input element
|
|
512
514
|
const inputEl = this._ardHost.inputs()[index];
|
|
513
515
|
if (!inputEl) {
|
|
@@ -532,32 +534,38 @@ class DigitInputModel {
|
|
|
532
534
|
return;
|
|
533
535
|
let before = '';
|
|
534
536
|
const newValue = [];
|
|
535
|
-
for (let i = 0; i < Math.min(this.
|
|
537
|
+
for (let i = 0; i < Math.min(this._configArray().length, v.length); i++) {
|
|
536
538
|
const char = v[i];
|
|
537
539
|
before += char ?? ' ';
|
|
538
540
|
if (!char) {
|
|
539
541
|
newValue.push(char);
|
|
540
542
|
continue;
|
|
541
543
|
}
|
|
542
|
-
const
|
|
543
|
-
const newChar = this._validateSingleChar(char, before, config);
|
|
544
|
+
const newChar = this._validateSingleChar(char, before, this._configArray()[i]);
|
|
544
545
|
newValue.push(newChar);
|
|
545
546
|
}
|
|
546
547
|
this.value.set(newValue);
|
|
547
548
|
}
|
|
548
549
|
_validateSingleChar(char, before, config) {
|
|
550
|
+
// return the character if it is static
|
|
551
|
+
if ('static' in config)
|
|
552
|
+
return config.static;
|
|
553
|
+
// for peace of mind protect against modifying read-only fields
|
|
549
554
|
if (config.readonly) {
|
|
550
555
|
throw new Error(`ARD-IS0049R: trying to set value of a <ard-digit-input>'s readonly field. This is error is fatal to the functioning of Ardium UI. Please report this issue to the creators.`);
|
|
551
556
|
}
|
|
557
|
+
// process regex or convert string into regex
|
|
552
558
|
if (!isFunction(config.accept)) {
|
|
553
559
|
const regExp = isRegExp(config.accept) ? config.accept : new RegExp(`[${_sanitizeRegExpString(config.accept)}]`);
|
|
554
560
|
config.accept = str => regExp.test(str);
|
|
555
561
|
}
|
|
556
562
|
if (!char)
|
|
557
563
|
return char;
|
|
564
|
+
// check if input fits the criteria
|
|
558
565
|
const canAccept = config.accept(char, before);
|
|
559
566
|
if (!canAccept)
|
|
560
567
|
return null;
|
|
568
|
+
// transform if needed
|
|
561
569
|
if (config.transform) {
|
|
562
570
|
if (config.transform === TransformType.Lowercase) {
|
|
563
571
|
return char.toLowerCase();
|
|
@@ -565,6 +573,9 @@ class DigitInputModel {
|
|
|
565
573
|
if (config.transform === TransformType.Uppercase) {
|
|
566
574
|
return char.toUpperCase();
|
|
567
575
|
}
|
|
576
|
+
if (isFunction(config.transform)) {
|
|
577
|
+
return config.transform(char).charAt(0);
|
|
578
|
+
}
|
|
568
579
|
console.warn(`ARD-IS0049T: <ard-digit-input>'s value validator encountered an unexpected value of the config's "transform" property. Ardium UI was able to handle this issue, but please report it to the creators.`);
|
|
569
580
|
}
|
|
570
581
|
return char;
|
|
@@ -658,19 +669,20 @@ class ArdiumDigitInputComponent extends _FormFieldComponentBase {
|
|
|
658
669
|
this.model.validateInputAndSetValue(char, index + i);
|
|
659
670
|
});
|
|
660
671
|
this.focusByIndex(index - 1 + Math.min(value.length, maxLength));
|
|
672
|
+
this._emitChange();
|
|
661
673
|
}
|
|
662
674
|
onInput(event, index) {
|
|
663
|
-
this._updateSingleInputValue(event.target.value, index);
|
|
675
|
+
const changeSuccessful = this._updateSingleInputValue(event.target.value, index);
|
|
676
|
+
if (!changeSuccessful)
|
|
677
|
+
return;
|
|
664
678
|
this.focusByIndex(index + 1);
|
|
665
679
|
}
|
|
666
680
|
_updateSingleInputValue(value, index) {
|
|
667
681
|
const changeResult = this.model.validateInputAndSetValue(value, index);
|
|
668
682
|
if (!changeResult?.wasChanged)
|
|
669
|
-
return;
|
|
683
|
+
return false;
|
|
670
684
|
this._emitChange();
|
|
671
|
-
|
|
672
|
-
this.blur();
|
|
673
|
-
}
|
|
685
|
+
return true;
|
|
674
686
|
}
|
|
675
687
|
focusByIndex(index, tryFocusingNext, direction) {
|
|
676
688
|
if (index < 0 || index >= this.inputs().length)
|
|
@@ -678,6 +690,9 @@ class ArdiumDigitInputComponent extends _FormFieldComponentBase {
|
|
|
678
690
|
const nextEl = this.inputs()[index]?.nativeElement;
|
|
679
691
|
if (!nextEl)
|
|
680
692
|
return false;
|
|
693
|
+
if (nextEl.getAttribute('data-ard-static') !== null) {
|
|
694
|
+
return this.focusByIndex(index + (direction ?? 1));
|
|
695
|
+
}
|
|
681
696
|
nextEl.focus();
|
|
682
697
|
if (tryFocusingNext && direction && document.activeElement !== nextEl) {
|
|
683
698
|
return this.focusByIndex(index + direction);
|
|
@@ -735,7 +750,7 @@ class ArdiumDigitInputComponent extends _FormFieldComponentBase {
|
|
|
735
750
|
provide: _FormFieldComponentBase,
|
|
736
751
|
useExisting: ArdiumDigitInputComponent,
|
|
737
752
|
},
|
|
738
|
-
], viewQueries: [{ propertyName: "inputs", predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "<div\r\n class=\"ard-digit-input\"\r\n [ngClass]=\"ngClasses()\"\r\n [class.ard-has-error]=\"hasError()\"\r\n [class.ard-is-success]=\"isSuccess()\"\r\n>\r\n @for (data of configArrayData(); track $index) {\r\n <div\r\n class=\"ard-digit-input__item\"\r\n [class.ard-digit-input__item-with-input]=\"data.type === 'input'\"\r\n >\r\n @if (data.type === 'input') {\r\n <input\r\n #input\r\n #focusableElement\r\n class=\"ard-digit-input__input\"\r\n type=\"text\"\r\n autocomplete=\"off\"\r\n [readonly]=\"data.readonly\"\r\n [placeholder]=\"data.placeholder\"\r\n [attr.tabindex]=\"tabIndex()\"\r\n [class.ard-digit-input__input-readonly]=\"data.readonly\"\r\n [class.ard-digit-input__input-empty]=\"isInputEmpty(data.index!)\"\r\n (paste)=\"onPaste($event, data.index!)\"\r\n (input)=\"onInput($event, data.index!)\"\r\n (focus)=\"onFocusMaster($event, data.index!)\"\r\n (blur)=\"onBlurMaster($event, data.index!)\"\r\n (keydown)=\"onKeydown($event, data.index!)\"\r\n />\r\n } @else {\r\n <div class=\"ard-digit-input__static\">\r\n {{ data.char }}\r\n </div>\r\n }\r\n </div>\r\n }\r\n</div>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
753
|
+
], viewQueries: [{ propertyName: "inputs", predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "<div\r\n class=\"ard-digit-input\"\r\n [ngClass]=\"ngClasses()\"\r\n [class.ard-has-error]=\"hasError()\"\r\n [class.ard-is-success]=\"isSuccess()\"\r\n>\r\n @for (data of configArrayData(); track $index) {\r\n <div\r\n class=\"ard-digit-input__item\"\r\n [class.ard-digit-input__item-with-input]=\"data.type === 'input'\"\r\n >\r\n @if (data.type === 'input') {\r\n <input\r\n #input\r\n #focusableElement\r\n class=\"ard-digit-input__input\"\r\n type=\"text\"\r\n autocomplete=\"off\"\r\n [readonly]=\"data.readonly\"\r\n [placeholder]=\"data.placeholder\"\r\n [attr.tabindex]=\"tabIndex()\"\r\n [class.ard-digit-input__input-readonly]=\"data.readonly\"\r\n [class.ard-digit-input__input-empty]=\"isInputEmpty(data.index!)\"\r\n (paste)=\"onPaste($event, data.index!)\"\r\n (input)=\"onInput($event, data.index!)\"\r\n (focus)=\"onFocusMaster($event, data.index!)\"\r\n (blur)=\"onBlurMaster($event, data.index!)\"\r\n (keydown)=\"onKeydown($event, data.index!)\"\r\n />\r\n } @else {\r\n <div class=\"ard-digit-input__static\">\r\n {{ data.char }}\r\n </div>\r\n <input\r\n #input\r\n type=\"text\"\r\n class=\"ard-digit-input__static-input\"\r\n data-ard-static\r\n autocomplete=\"off\"\r\n tabindex=\"-1\"\r\n aria-hidden=\"true\"\r\n [value]=\"data.char\"\r\n />\r\n }\r\n </div>\r\n }\r\n</div>\r\n", styles: [".ard-digit-input__static-input{position:absolute;opacity:0;appearance:none;pointer-events:none;width:0;height:0}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
739
754
|
}
|
|
740
755
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ArdiumDigitInputComponent, decorators: [{
|
|
741
756
|
type: Component,
|
|
@@ -749,7 +764,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
749
764
|
provide: _FormFieldComponentBase,
|
|
750
765
|
useExisting: ArdiumDigitInputComponent,
|
|
751
766
|
},
|
|
752
|
-
], template: "<div\r\n class=\"ard-digit-input\"\r\n [ngClass]=\"ngClasses()\"\r\n [class.ard-has-error]=\"hasError()\"\r\n [class.ard-is-success]=\"isSuccess()\"\r\n>\r\n @for (data of configArrayData(); track $index) {\r\n <div\r\n class=\"ard-digit-input__item\"\r\n [class.ard-digit-input__item-with-input]=\"data.type === 'input'\"\r\n >\r\n @if (data.type === 'input') {\r\n <input\r\n #input\r\n #focusableElement\r\n class=\"ard-digit-input__input\"\r\n type=\"text\"\r\n autocomplete=\"off\"\r\n [readonly]=\"data.readonly\"\r\n [placeholder]=\"data.placeholder\"\r\n [attr.tabindex]=\"tabIndex()\"\r\n [class.ard-digit-input__input-readonly]=\"data.readonly\"\r\n [class.ard-digit-input__input-empty]=\"isInputEmpty(data.index!)\"\r\n (paste)=\"onPaste($event, data.index!)\"\r\n (input)=\"onInput($event, data.index!)\"\r\n (focus)=\"onFocusMaster($event, data.index!)\"\r\n (blur)=\"onBlurMaster($event, data.index!)\"\r\n (keydown)=\"onKeydown($event, data.index!)\"\r\n />\r\n } @else {\r\n <div class=\"ard-digit-input__static\">\r\n {{ data.char }}\r\n </div>\r\n }\r\n </div>\r\n }\r\n</div>\r\n" }]
|
|
767
|
+
], template: "<div\r\n class=\"ard-digit-input\"\r\n [ngClass]=\"ngClasses()\"\r\n [class.ard-has-error]=\"hasError()\"\r\n [class.ard-is-success]=\"isSuccess()\"\r\n>\r\n @for (data of configArrayData(); track $index) {\r\n <div\r\n class=\"ard-digit-input__item\"\r\n [class.ard-digit-input__item-with-input]=\"data.type === 'input'\"\r\n >\r\n @if (data.type === 'input') {\r\n <input\r\n #input\r\n #focusableElement\r\n class=\"ard-digit-input__input\"\r\n type=\"text\"\r\n autocomplete=\"off\"\r\n [readonly]=\"data.readonly\"\r\n [placeholder]=\"data.placeholder\"\r\n [attr.tabindex]=\"tabIndex()\"\r\n [class.ard-digit-input__input-readonly]=\"data.readonly\"\r\n [class.ard-digit-input__input-empty]=\"isInputEmpty(data.index!)\"\r\n (paste)=\"onPaste($event, data.index!)\"\r\n (input)=\"onInput($event, data.index!)\"\r\n (focus)=\"onFocusMaster($event, data.index!)\"\r\n (blur)=\"onBlurMaster($event, data.index!)\"\r\n (keydown)=\"onKeydown($event, data.index!)\"\r\n />\r\n } @else {\r\n <div class=\"ard-digit-input__static\">\r\n {{ data.char }}\r\n </div>\r\n <input\r\n #input\r\n type=\"text\"\r\n class=\"ard-digit-input__static-input\"\r\n data-ard-static\r\n autocomplete=\"off\"\r\n tabindex=\"-1\"\r\n aria-hidden=\"true\"\r\n [value]=\"data.char\"\r\n />\r\n }\r\n </div>\r\n }\r\n</div>\r\n", styles: [".ard-digit-input__static-input{position:absolute;opacity:0;appearance:none;pointer-events:none;width:0;height:0}\n"] }]
|
|
753
768
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
754
769
|
type: Inject,
|
|
755
770
|
args: [ARD_DIGIT_INPUT_DEFAULTS]
|
|
@@ -3668,7 +3683,7 @@ class ArdiumSelectComponent extends _FormFieldComponentBase {
|
|
|
3668
3683
|
}
|
|
3669
3684
|
//! change & touch event emitters
|
|
3670
3685
|
_emitChange() {
|
|
3671
|
-
const value = this.itemStorage.value();
|
|
3686
|
+
const value = this.multiselectable() ? this.itemStorage.value() : this.itemStorage.value()[0];
|
|
3672
3687
|
this._onChangeRegistered?.(value);
|
|
3673
3688
|
this.changeEvent.emit(value);
|
|
3674
3689
|
this.valueChange.emit(value);
|
|
@@ -6738,7 +6753,7 @@ class _SelectableListComponentBase extends _FormFieldComponentBase {
|
|
|
6738
6753
|
return this.touched();
|
|
6739
6754
|
}
|
|
6740
6755
|
_emitChange() {
|
|
6741
|
-
const value = this.itemStorage.value();
|
|
6756
|
+
const value = this.singleselectable() ? this.itemStorage.value()[0] : this.itemStorage.value();
|
|
6742
6757
|
this._onChangeRegistered?.(value);
|
|
6743
6758
|
this.changeEvent.emit(value);
|
|
6744
6759
|
this.valueChange.emit(value);
|