@ngrdt/forms 0.0.44 → 0.0.46
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 +48 -6
- package/fesm2022/ngrdt-forms.mjs.map +1 -1
- package/index.d.ts +3 -1
- package/package.json +3 -3
package/fesm2022/ngrdt-forms.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { RdtInteractiveElementComponent } from '@ngrdt/core';
|
|
|
6
6
|
import { startWith, take, map, forkJoin, of, from, switchMap, debounceTime, distinctUntilChanged, 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
|
+
import { isEqual } from 'lodash-es';
|
|
9
10
|
|
|
10
11
|
function getFormControl(ngControl) {
|
|
11
12
|
if (ngControl instanceof FormControlName) {
|
|
@@ -586,7 +587,7 @@ const rdtSelectInitialState = {
|
|
|
586
587
|
datasource: null,
|
|
587
588
|
selectedMap: new Map(),
|
|
588
589
|
fetchError: null,
|
|
589
|
-
missingValuePlaceholder: '
|
|
590
|
+
missingValuePlaceholder: 'Načítání (ID = {id})...',
|
|
590
591
|
_fetchRequest: null,
|
|
591
592
|
_fetchMissingRequest: null,
|
|
592
593
|
_missingSelected: [],
|
|
@@ -620,7 +621,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
620
621
|
const query = state.query();
|
|
621
622
|
const selectedMap = state.selectedMap();
|
|
622
623
|
const missing = state._missingSelected();
|
|
623
|
-
if (query
|
|
624
|
+
if (query) {
|
|
624
625
|
return items.map((it) => ({
|
|
625
626
|
...it,
|
|
626
627
|
selected: selectedMap.has(it.id),
|
|
@@ -824,10 +825,13 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
824
825
|
_loadMissingSelected() {
|
|
825
826
|
const datasource = store.datasource();
|
|
826
827
|
const reallyMissing = this._setAndGetMissing();
|
|
827
|
-
if (!untracked(store.loading) &&
|
|
828
|
-
reallyMissing.length > 0
|
|
829
|
-
|
|
830
|
-
|
|
828
|
+
if (!untracked(store.loading) && datasource) {
|
|
829
|
+
if (reallyMissing.length > 0) {
|
|
830
|
+
this._fetchMissing(reallyMissing, datasource);
|
|
831
|
+
}
|
|
832
|
+
else {
|
|
833
|
+
patchState(store, { initialized: true });
|
|
834
|
+
}
|
|
831
835
|
}
|
|
832
836
|
},
|
|
833
837
|
_cancelFetchMissingIfNeeded() {
|
|
@@ -1083,6 +1087,44 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
|
|
|
1083
1087
|
handleInput(value) {
|
|
1084
1088
|
this.store.setQuery(value);
|
|
1085
1089
|
}
|
|
1090
|
+
storeValueChangeEffect = effect(() => {
|
|
1091
|
+
const selectedMap = this.store.selectedMap();
|
|
1092
|
+
const values = Array.from(selectedMap.keys());
|
|
1093
|
+
const internalValue = untracked(this.internalValue);
|
|
1094
|
+
if (!untracked(this.store.datasource) ||
|
|
1095
|
+
!untracked(this.store.initialized)) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (values.length > 0) {
|
|
1099
|
+
const arrayInternalValue = Array.isArray(internalValue)
|
|
1100
|
+
? internalValue
|
|
1101
|
+
: internalValue !== null
|
|
1102
|
+
? [internalValue]
|
|
1103
|
+
: [];
|
|
1104
|
+
if (!isEqual(arrayInternalValue, values)) {
|
|
1105
|
+
this.onInternalValueChange(values);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
this.onInternalValueChange(null);
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
externalValueEffect = effect(() => {
|
|
1113
|
+
const externalValue = this.externalValue();
|
|
1114
|
+
const selectedMap = untracked(this.store.selectedMap);
|
|
1115
|
+
const values = Array.from(selectedMap.keys());
|
|
1116
|
+
if (externalValue !== null) {
|
|
1117
|
+
const newExternalValue = Array.isArray(externalValue)
|
|
1118
|
+
? externalValue
|
|
1119
|
+
: [externalValue];
|
|
1120
|
+
if (!isEqual(newExternalValue, values)) {
|
|
1121
|
+
this.store.setSelected(newExternalValue);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
else {
|
|
1125
|
+
this.store.unselectAll();
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1086
1128
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtBaseSelectCommonComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
1087
1129
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.0", type: RdtBaseSelectCommonComponent, isStandalone: true, inputs: { datasourceInput: { classPropertyName: "datasourceInput", publicName: "datasourceInput", isSignal: true, isRequired: false, transformFunction: null }, queryValidatorFnInput: { classPropertyName: "queryValidatorFnInput", publicName: "inputValidator", isSignal: true, isRequired: false, transformFunction: null }, debounceTimeInput: { classPropertyName: "debounceTimeInput", publicName: "debounce", isSignal: true, isRequired: false, transformFunction: null }, pageSizeInput: { classPropertyName: "pageSizeInput", publicName: "pageSize", isSignal: true, isRequired: false, transformFunction: null } }, usesInheritance: true, ngImport: i0 });
|
|
1088
1130
|
}
|