@ngrdt/forms 0.0.89 → 0.0.91
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/fesm2022/ngrdt-forms.mjs +271 -3
- package/fesm2022/ngrdt-forms.mjs.map +1 -1
- package/index.d.ts +81 -6
- package/package.json +3 -3
package/fesm2022/ngrdt-forms.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, Injector, signal, model, linkedSignal, input, booleanAttribute, computed, effect, untracked, Directive, InjectionToken, forwardRef, numberAttribute, ElementRef, Pipe } from '@angular/core';
|
|
2
|
+
import { inject, Injector, signal, model, linkedSignal, input, booleanAttribute, computed, effect, untracked, Directive, InjectionToken, forwardRef, numberAttribute, ElementRef, output, ViewChild, Pipe } from '@angular/core';
|
|
3
3
|
import { takeUntilDestroyed, toSignal, toObservable } from '@angular/core/rxjs-interop';
|
|
4
4
|
import { FormControlName, FormControlDirective, NgModel, NgControl, Validators, NG_VALUE_ACCESSOR, FormControl, FormGroup } from '@angular/forms';
|
|
5
5
|
import { RdtInteractiveElementComponent, RdtComponentOutletDirective, RdtTranslateService } from '@ngrdt/core';
|
|
6
|
-
import { startWith, take, map, forkJoin, of, from, switchMap, debounceTime, distinctUntilChanged, merge, takeUntil } from 'rxjs';
|
|
6
|
+
import { startWith, take, map, forkJoin, of, from, switchMap, debounceTime, distinctUntilChanged, filter, tap, merge, takeUntil } from 'rxjs';
|
|
7
7
|
import { RdtFileUtils, RdtObjectUtils, RdtDateUtils } from '@ngrdt/utils';
|
|
8
8
|
import { signalStore, withState, withHooks, withComputed, withMethods, patchState } from '@ngrx/signals';
|
|
9
9
|
import { isEqual } from 'lodash-es';
|
|
@@ -566,6 +566,39 @@ class VnshFileReaderText extends RdtFileReader {
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
+
const RDT_NUMERIC_INPUT_BASE_PROVIDER = new InjectionToken('RdtNumericInput');
|
|
570
|
+
|
|
571
|
+
class RdtNumericInputOutletDirective extends RdtFormInputOutletDirective {
|
|
572
|
+
componentClass = inject(RDT_NUMERIC_INPUT_BASE_PROVIDER);
|
|
573
|
+
constructor() {
|
|
574
|
+
super();
|
|
575
|
+
this.initComponentRef();
|
|
576
|
+
}
|
|
577
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtNumericInputOutletDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
578
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", type: RdtNumericInputOutletDirective, isStandalone: true, selector: "[rdtNumericInputOutlet]", providers: [
|
|
579
|
+
{
|
|
580
|
+
provide: NG_VALUE_ACCESSOR,
|
|
581
|
+
useExisting: forwardRef(() => RdtNumericInputOutletDirective),
|
|
582
|
+
multi: true,
|
|
583
|
+
},
|
|
584
|
+
], exportAs: ["rdtNumericInputOutlet"], usesInheritance: true, ngImport: i0 });
|
|
585
|
+
}
|
|
586
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtNumericInputOutletDirective, decorators: [{
|
|
587
|
+
type: Directive,
|
|
588
|
+
args: [{
|
|
589
|
+
selector: '[rdtNumericInputOutlet]',
|
|
590
|
+
standalone: true,
|
|
591
|
+
exportAs: 'rdtNumericInputOutlet',
|
|
592
|
+
providers: [
|
|
593
|
+
{
|
|
594
|
+
provide: NG_VALUE_ACCESSOR,
|
|
595
|
+
useExisting: forwardRef(() => RdtNumericInputOutletDirective),
|
|
596
|
+
multi: true,
|
|
597
|
+
},
|
|
598
|
+
],
|
|
599
|
+
}]
|
|
600
|
+
}], ctorParameters: () => [] });
|
|
601
|
+
|
|
569
602
|
class RdtNumericInputComponent extends RdtBaseFormInputComponent {
|
|
570
603
|
min = input(undefined, {
|
|
571
604
|
transform: nullToUndefinedNumeric,
|
|
@@ -1164,6 +1197,53 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
|
|
|
1164
1197
|
}]
|
|
1165
1198
|
}] });
|
|
1166
1199
|
|
|
1200
|
+
const RDT_SELECT_BASE_PROVIDER = new InjectionToken('RdtSelect');
|
|
1201
|
+
|
|
1202
|
+
class RdtSelectOutletDirective extends RdtFormInputOutletDirective {
|
|
1203
|
+
componentClass = inject(RDT_SELECT_BASE_PROVIDER);
|
|
1204
|
+
constructor() {
|
|
1205
|
+
super();
|
|
1206
|
+
this.initComponentRef();
|
|
1207
|
+
effect(() => {
|
|
1208
|
+
const inputs = this.inputs();
|
|
1209
|
+
if (inputs?.options && this.componentRef) {
|
|
1210
|
+
const instance = this.componentRef.instance;
|
|
1211
|
+
const store = instance?.store;
|
|
1212
|
+
if (store) {
|
|
1213
|
+
const datasource = new RdtOfflineSelectDatasource(inputs.options);
|
|
1214
|
+
store.setDatasource(datasource);
|
|
1215
|
+
if (!store.initialized()) {
|
|
1216
|
+
store.init(null);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtSelectOutletDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1223
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", type: RdtSelectOutletDirective, isStandalone: true, selector: "[rdtSelectOutlet]", providers: [
|
|
1224
|
+
{
|
|
1225
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1226
|
+
useExisting: forwardRef(() => RdtSelectOutletDirective),
|
|
1227
|
+
multi: true,
|
|
1228
|
+
},
|
|
1229
|
+
], exportAs: ["rdtSelectOutlet"], usesInheritance: true, ngImport: i0 });
|
|
1230
|
+
}
|
|
1231
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtSelectOutletDirective, decorators: [{
|
|
1232
|
+
type: Directive,
|
|
1233
|
+
args: [{
|
|
1234
|
+
selector: '[rdtSelectOutlet]',
|
|
1235
|
+
standalone: true,
|
|
1236
|
+
exportAs: 'rdtSelectOutlet',
|
|
1237
|
+
providers: [
|
|
1238
|
+
{
|
|
1239
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1240
|
+
useExisting: forwardRef(() => RdtSelectOutletDirective),
|
|
1241
|
+
multi: true,
|
|
1242
|
+
},
|
|
1243
|
+
],
|
|
1244
|
+
}]
|
|
1245
|
+
}], ctorParameters: () => [] });
|
|
1246
|
+
|
|
1167
1247
|
class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
|
|
1168
1248
|
manualInitInput = input(false, {
|
|
1169
1249
|
alias: 'manualInit',
|
|
@@ -1365,6 +1445,192 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
|
|
|
1365
1445
|
type: Directive
|
|
1366
1446
|
}] });
|
|
1367
1447
|
|
|
1448
|
+
class RdtTextInputSearchDatasource extends RdtSelectDatasource {
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
class RdtTextSearchInputComponent extends RdtBaseFormInputComponent {
|
|
1452
|
+
hideErrors = input(false, { transform: booleanAttribute });
|
|
1453
|
+
textInput = signal(undefined);
|
|
1454
|
+
_input;
|
|
1455
|
+
isEmpty(value) {
|
|
1456
|
+
return value === null || value === undefined;
|
|
1457
|
+
}
|
|
1458
|
+
focus() {
|
|
1459
|
+
this.textInput()?.focus();
|
|
1460
|
+
}
|
|
1461
|
+
canFocus() {
|
|
1462
|
+
return this.textInput()?.canFocus() ?? false;
|
|
1463
|
+
}
|
|
1464
|
+
datasource = input(null);
|
|
1465
|
+
itemResolved = output();
|
|
1466
|
+
store = inject(RdtSelectStore);
|
|
1467
|
+
ctrl = new FormControl(null);
|
|
1468
|
+
lastResult = [];
|
|
1469
|
+
initializing = true;
|
|
1470
|
+
errorEffect = effect(() => {
|
|
1471
|
+
this.ctrl.setErrors(this.visibleErrors());
|
|
1472
|
+
});
|
|
1473
|
+
touchedEffect = effect(() => {
|
|
1474
|
+
if (this.ngControl?.control?.touched) {
|
|
1475
|
+
this.ctrl.markAsTouched();
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
anyDatasource = computed(() => this.store.datasource() || this.datasource());
|
|
1479
|
+
ngOnInit() {
|
|
1480
|
+
super.ngOnInit();
|
|
1481
|
+
this.ctrl.valueChanges
|
|
1482
|
+
.pipe(debounceTime(250), distinctUntilChanged(), filter(() => !this.initializing), takeUntilDestroyed(this.destroyRef), switchMap((inputValue) => this.handleSearchInput$(inputValue)), filter(RdtObjectUtils.notNullGuard))
|
|
1483
|
+
.subscribe((res) => {
|
|
1484
|
+
this.handleSearchResults(this.ctrl.value ?? '', res);
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
ngAfterViewInit() {
|
|
1488
|
+
this.textInput.set(this._input);
|
|
1489
|
+
this.ngControl?.control?.addValidators(this.resultCountValidator(this.datasource()));
|
|
1490
|
+
const initialValue = this.ctrl.value;
|
|
1491
|
+
if (initialValue) {
|
|
1492
|
+
this.resolveInitialValue(initialValue);
|
|
1493
|
+
}
|
|
1494
|
+
else {
|
|
1495
|
+
this.initializing = false;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
ngOnDestroy() {
|
|
1499
|
+
super.ngOnDestroy();
|
|
1500
|
+
this.ngControl?.control?.removeValidators(this.resultCountValidator(this.datasource()));
|
|
1501
|
+
}
|
|
1502
|
+
resolveInitialValue(id) {
|
|
1503
|
+
const datasource = untracked(this.anyDatasource);
|
|
1504
|
+
if (!datasource)
|
|
1505
|
+
return;
|
|
1506
|
+
datasource
|
|
1507
|
+
.getItemsByIds([id])
|
|
1508
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
1509
|
+
.subscribe((items) => {
|
|
1510
|
+
if (!items || items.size === 0) {
|
|
1511
|
+
this.emitResolvedEvent(null, null, null);
|
|
1512
|
+
this.initializing = false;
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
const [resolvedId, item] = items.entries().next().value;
|
|
1516
|
+
const label = datasource.getLabelForInputSearch(item);
|
|
1517
|
+
const inputElement = this.textInput()?.elementRef?.nativeElement;
|
|
1518
|
+
if (inputElement) {
|
|
1519
|
+
const childInput = inputElement.querySelector('input');
|
|
1520
|
+
if (childInput) {
|
|
1521
|
+
childInput.value = label;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
this.onChange(resolvedId);
|
|
1525
|
+
this.emitResolvedEvent(resolvedId, label, item);
|
|
1526
|
+
this.lastResult = [item];
|
|
1527
|
+
this.ngControl?.control?.updateValueAndValidity({ emitEvent: false });
|
|
1528
|
+
this.initializing = false;
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
handleSearchInput$(inputValue) {
|
|
1532
|
+
const value = (inputValue ?? '').toString().trim();
|
|
1533
|
+
if (!value) {
|
|
1534
|
+
return of(null).pipe(tap(() => {
|
|
1535
|
+
this.onChange(null);
|
|
1536
|
+
this.emitResolvedEvent(null, null, null);
|
|
1537
|
+
this.lastResult.length = 0;
|
|
1538
|
+
this.ngControl?.control?.updateValueAndValidity({ emitEvent: false });
|
|
1539
|
+
}));
|
|
1540
|
+
}
|
|
1541
|
+
const datasource = untracked(this.anyDatasource);
|
|
1542
|
+
if (!datasource) {
|
|
1543
|
+
return of(null).pipe(tap(() => {
|
|
1544
|
+
const id = value;
|
|
1545
|
+
this.onChange(id);
|
|
1546
|
+
this.emitResolvedEvent(id, null, null); //todo here?
|
|
1547
|
+
}));
|
|
1548
|
+
}
|
|
1549
|
+
return datasource
|
|
1550
|
+
.getDataForTextInputSearch({ query: value, pageIndex: 0, pageSize: 20 })
|
|
1551
|
+
.pipe(takeUntilDestroyed(this.destroyRef));
|
|
1552
|
+
}
|
|
1553
|
+
handleSearchResults(query, page) {
|
|
1554
|
+
const datasource = untracked(this.anyDatasource);
|
|
1555
|
+
const items = page.data ?? [];
|
|
1556
|
+
this.lastResult = [...items];
|
|
1557
|
+
this.ngControl?.control?.updateValueAndValidity({ emitEvent: false });
|
|
1558
|
+
if (this.lastResult.length === 1) {
|
|
1559
|
+
const item = items[0];
|
|
1560
|
+
const id = datasource.getId(item);
|
|
1561
|
+
const label = datasource.getLabelForInputSearch(item);
|
|
1562
|
+
this.onChange(id);
|
|
1563
|
+
this.emitResolvedEvent(id, label, item);
|
|
1564
|
+
}
|
|
1565
|
+
else if (this.lastResult.length === 0) {
|
|
1566
|
+
this.emitResolvedEvent(null, null, null);
|
|
1567
|
+
if (!this.ctrl.touched) {
|
|
1568
|
+
this.ctrl.markAsTouched();
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
else {
|
|
1572
|
+
this.emitResolvedEvent(null, null, null);
|
|
1573
|
+
if (!this.ctrl.touched) {
|
|
1574
|
+
this.ctrl.markAsTouched();
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
emitResolvedEvent(id, label, item) {
|
|
1579
|
+
this.itemResolved.emit({ id, label, item });
|
|
1580
|
+
}
|
|
1581
|
+
writeValue(value) {
|
|
1582
|
+
super.writeValue(value);
|
|
1583
|
+
if (value === null || value === undefined) {
|
|
1584
|
+
this.ctrl.setValue(null, { emitEvent: false });
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
this.ctrl.setValue(String(value));
|
|
1588
|
+
}
|
|
1589
|
+
setDisabledState(isDisabled) {
|
|
1590
|
+
super.setDisabledState(isDisabled);
|
|
1591
|
+
if (untracked(this.disabled)) {
|
|
1592
|
+
if (this.ctrl.enabled) {
|
|
1593
|
+
this.ctrl.disable({ emitEvent: false });
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
else if (this.ctrl.disabled) {
|
|
1597
|
+
this.ctrl.enable({ emitEvent: false });
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
resultCountValidator = (datasource) => {
|
|
1601
|
+
return (ctrl) => {
|
|
1602
|
+
const query = this.ctrl.value?.toString().trim();
|
|
1603
|
+
if (!query) {
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1606
|
+
if (this.lastResult.length === 0) {
|
|
1607
|
+
return { notFound: true };
|
|
1608
|
+
}
|
|
1609
|
+
if (this.lastResult.length === 1) {
|
|
1610
|
+
const usedLabel = datasource?.getLabelForInputSearch(this.lastResult[0]);
|
|
1611
|
+
const usedId = datasource?.getId(this.lastResult[0]);
|
|
1612
|
+
if (usedLabel?.toString() === query?.toString() ||
|
|
1613
|
+
usedId?.toString() === query?.toString()) {
|
|
1614
|
+
return null;
|
|
1615
|
+
}
|
|
1616
|
+
return { incomplete: true };
|
|
1617
|
+
}
|
|
1618
|
+
if (this.lastResult.length > 1) {
|
|
1619
|
+
return { multipleFound: true };
|
|
1620
|
+
}
|
|
1621
|
+
return null;
|
|
1622
|
+
};
|
|
1623
|
+
};
|
|
1624
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtTextSearchInputComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
1625
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.0", type: RdtTextSearchInputComponent, isStandalone: true, inputs: { hideErrors: { classPropertyName: "hideErrors", publicName: "hideErrors", isSignal: true, isRequired: false, transformFunction: null }, datasource: { classPropertyName: "datasource", publicName: "datasource", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemResolved: "itemResolved" }, viewQueries: [{ propertyName: "_input", first: true, predicate: ["input"], descendants: true }], usesInheritance: true, ngImport: i0 });
|
|
1626
|
+
}
|
|
1627
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtTextSearchInputComponent, decorators: [{
|
|
1628
|
+
type: Directive
|
|
1629
|
+
}], propDecorators: { _input: [{
|
|
1630
|
+
type: ViewChild,
|
|
1631
|
+
args: ['input', { static: false }]
|
|
1632
|
+
}] } });
|
|
1633
|
+
|
|
1368
1634
|
const RDT_FORM_ERROR_CODES_PROVIDER = new InjectionToken('RdtFormErrors');
|
|
1369
1635
|
|
|
1370
1636
|
function getFirstError(errors) {
|
|
@@ -1382,6 +1648,8 @@ const defaultRdtFormErrorCodes = {
|
|
|
1382
1648
|
maxlength: (value) => ['RDT_ERROR_MAX_LENGTH', value.requiredLength],
|
|
1383
1649
|
notFound: () => 'RDT_ERROR_NOT_FOUND',
|
|
1384
1650
|
multipleFound: () => 'RDT_ERROR_MULTIPLE_FOUND',
|
|
1651
|
+
incomplete: () => 'RDT_ERROR_CODE_INCOMPLETE',
|
|
1652
|
+
minValue: (value) => ['RDT_ERROR_MIN_VALUE', value.min],
|
|
1385
1653
|
};
|
|
1386
1654
|
class RdtFormErrorPipe {
|
|
1387
1655
|
translateService = inject(RdtTranslateService);
|
|
@@ -1677,5 +1945,5 @@ class RdtCommonValidators {
|
|
|
1677
1945
|
* Generated bundle index. Do not edit.
|
|
1678
1946
|
*/
|
|
1679
1947
|
|
|
1680
|
-
export { NO_OP_FILE_READER, NoOpFileReader, RDT_CHECKBOX_BASE_PROVIDER, RDT_DEFAULT_FILE_LABEL_FN, RDT_DEFAULT_FILE_READER, RDT_DEFAULT_MAX_FILE_SIZE, RDT_EMPTY_TIME_DATE, RDT_FORM_CONTROL_DATETIME_FORMAT, RDT_FORM_CONTROL_DATE_FORMAT, RDT_FORM_CONTROL_TIME_FORMAT, RDT_FORM_ERROR_CODES_PROVIDER, RdtBaseFormInputComponent, RdtBaseSelectCommonComponent, RdtCheckboxComponent, RdtCheckboxOutletDirective, RdtCommonValidators, RdtDateComponent, RdtDateValidators, RdtFileInputComponent, RdtFileReader, RdtFileReaderArrayBuffer, RdtFileReaderBase64, RdtFormErrorPipe, RdtFormInputOutletDirective, RdtMultiSelectComponent, RdtNumericInputComponent, RdtOfflineSelectDatasource, RdtSelectDatasource, RdtSelectOfflineDatasourceProviderDirective, RdtSelectOptionDirective, RdtSelectStore, RdtSingleSelectComponent, RdtTextAreaComponent, RdtTextInputComponent, VnshFileReaderText, defaultRdtFormErrorCodes, fileLabelTranslate, getFirstError, getRdtSelectPage, rdtSelectInitialState };
|
|
1948
|
+
export { NO_OP_FILE_READER, NoOpFileReader, RDT_CHECKBOX_BASE_PROVIDER, RDT_DEFAULT_FILE_LABEL_FN, RDT_DEFAULT_FILE_READER, RDT_DEFAULT_MAX_FILE_SIZE, RDT_EMPTY_TIME_DATE, RDT_FORM_CONTROL_DATETIME_FORMAT, RDT_FORM_CONTROL_DATE_FORMAT, RDT_FORM_CONTROL_TIME_FORMAT, RDT_FORM_ERROR_CODES_PROVIDER, RDT_NUMERIC_INPUT_BASE_PROVIDER, RDT_SELECT_BASE_PROVIDER, RdtBaseFormInputComponent, RdtBaseSelectCommonComponent, RdtCheckboxComponent, RdtCheckboxOutletDirective, RdtCommonValidators, RdtDateComponent, RdtDateValidators, RdtFileInputComponent, RdtFileReader, RdtFileReaderArrayBuffer, RdtFileReaderBase64, RdtFormErrorPipe, RdtFormInputOutletDirective, RdtMultiSelectComponent, RdtNumericInputComponent, RdtNumericInputOutletDirective, RdtOfflineSelectDatasource, RdtSelectDatasource, RdtSelectOfflineDatasourceProviderDirective, RdtSelectOptionDirective, RdtSelectOutletDirective, RdtSelectStore, RdtSingleSelectComponent, RdtTextAreaComponent, RdtTextInputComponent, RdtTextInputSearchDatasource, RdtTextSearchInputComponent, VnshFileReaderText, defaultRdtFormErrorCodes, fileLabelTranslate, getFirstError, getRdtSelectPage, rdtSelectInitialState };
|
|
1681
1949
|
//# sourceMappingURL=ngrdt-forms.mjs.map
|