@ngrdt/forms 0.0.78 → 0.0.80
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 +57 -13
- package/fesm2022/ngrdt-forms.mjs.map +1 -1
- package/index.d.ts +10 -1
- package/package.json +3 -3
package/fesm2022/ngrdt-forms.mjs
CHANGED
|
@@ -685,10 +685,12 @@ const rdtSelectInitialState = {
|
|
|
685
685
|
datasource: null,
|
|
686
686
|
selectedMap: new Map(),
|
|
687
687
|
fetchError: null,
|
|
688
|
-
|
|
688
|
+
loadingValuePlaceholder: 'Načítání (ID = {id})...',
|
|
689
|
+
missingValuePlaceholder: 'Neznámá hodnota (ID = {id})',
|
|
689
690
|
_fetchRequest: null,
|
|
690
691
|
_fetchMissingRequest: null,
|
|
691
692
|
_missingSelected: [],
|
|
693
|
+
_unfetchableIds: [],
|
|
692
694
|
};
|
|
693
695
|
|
|
694
696
|
function compareSelectRequestParams(a, b) {
|
|
@@ -719,6 +721,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
719
721
|
const query = state.query();
|
|
720
722
|
const selectedMap = state.selectedMap();
|
|
721
723
|
const missing = state._missingSelected();
|
|
724
|
+
const unfetchable = state._unfetchableIds();
|
|
722
725
|
if (query) {
|
|
723
726
|
return items.map((it) => ({
|
|
724
727
|
...it,
|
|
@@ -727,13 +730,21 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
727
730
|
}
|
|
728
731
|
const selected = [];
|
|
729
732
|
const missingPlaceholder = state.missingValuePlaceholder();
|
|
730
|
-
const
|
|
733
|
+
const loadingPlaceholder = state.loadingValuePlaceholder();
|
|
734
|
+
const loadingPlaceholders = missing.map((id) => ({
|
|
735
|
+
id,
|
|
736
|
+
label: loadingPlaceholder.replace('{id}', String(id)),
|
|
737
|
+
value: null,
|
|
738
|
+
selected: true,
|
|
739
|
+
}));
|
|
740
|
+
const missingPlaceholders = unfetchable.map((id) => ({
|
|
731
741
|
id,
|
|
732
742
|
label: missingPlaceholder.replace('{id}', String(id)),
|
|
733
743
|
value: null,
|
|
734
744
|
selected: true,
|
|
735
745
|
}));
|
|
736
|
-
|
|
746
|
+
selected.push(...loadingPlaceholders);
|
|
747
|
+
selected.push(...missingPlaceholders);
|
|
737
748
|
items.forEach((item) => {
|
|
738
749
|
selected.push({ ...item, selected: selectedMap.has(item.id) });
|
|
739
750
|
});
|
|
@@ -867,6 +878,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
867
878
|
},
|
|
868
879
|
setSelected(ids) {
|
|
869
880
|
patchState(store, {
|
|
881
|
+
_unfetchableIds: [],
|
|
870
882
|
_missingSelected: ids,
|
|
871
883
|
selectedMap: new Map(),
|
|
872
884
|
});
|
|
@@ -894,6 +906,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
894
906
|
});
|
|
895
907
|
},
|
|
896
908
|
_setAndGetMissing() {
|
|
909
|
+
const unfetchable = untracked(store._unfetchableIds);
|
|
897
910
|
const allMissing = untracked(store._missingSelected);
|
|
898
911
|
const items = untracked(store.options);
|
|
899
912
|
const selectedMap = new Map(untracked(store.selectedMap));
|
|
@@ -905,7 +918,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
905
918
|
selectedMap.set(id, item);
|
|
906
919
|
selectedChanged = true;
|
|
907
920
|
}
|
|
908
|
-
else {
|
|
921
|
+
else if (!unfetchable.includes(id)) {
|
|
909
922
|
newMissing.push(id);
|
|
910
923
|
}
|
|
911
924
|
}
|
|
@@ -933,12 +946,16 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
933
946
|
_cancelFetchMissingIfNeeded() {
|
|
934
947
|
const fetchMissingReq = untracked(store._fetchMissingRequest);
|
|
935
948
|
const items = untracked(store.options);
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
949
|
+
const missingEmpty = untracked(store._missingSelected).length === 0;
|
|
950
|
+
if (fetchMissingReq) {
|
|
951
|
+
if (fetchMissingReq.ids.every((id) => items.some((it) => it.id === id)) ||
|
|
952
|
+
missingEmpty) {
|
|
953
|
+
fetchMissingReq.subscription.unsubscribe();
|
|
954
|
+
patchState(store, {
|
|
955
|
+
_fetchMissingRequest: null,
|
|
956
|
+
_missingSelected: [],
|
|
957
|
+
});
|
|
958
|
+
}
|
|
942
959
|
}
|
|
943
960
|
},
|
|
944
961
|
_fetchMissing(ids, datasource) {
|
|
@@ -948,12 +965,17 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
948
965
|
const sub = datasource.getItemsByIds(ids).subscribe((map) => {
|
|
949
966
|
const newMissing = [];
|
|
950
967
|
const newSelected = new Map(untracked(store.selectedMap));
|
|
968
|
+
const unfetchable = [...untracked(store._unfetchableIds)];
|
|
951
969
|
for (const id of untracked(store._missingSelected)) {
|
|
952
970
|
if (map.has(id)) {
|
|
953
971
|
const value = map.get(id);
|
|
954
972
|
const label = datasource.getLabel(value);
|
|
955
973
|
newSelected.set(id, { label, value, id });
|
|
956
974
|
}
|
|
975
|
+
else if (ids.includes(id)) {
|
|
976
|
+
console.error(`Item with id ${JSON.stringify(id)} not found by getItemsByIds().`, datasource);
|
|
977
|
+
unfetchable.push(id);
|
|
978
|
+
}
|
|
957
979
|
else {
|
|
958
980
|
newMissing.push(id);
|
|
959
981
|
}
|
|
@@ -962,6 +984,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
962
984
|
_fetchMissingRequest: null,
|
|
963
985
|
_missingSelected: newMissing,
|
|
964
986
|
selectedMap: newSelected,
|
|
987
|
+
_unfetchableIds: [...unfetchable],
|
|
965
988
|
initialized: true,
|
|
966
989
|
});
|
|
967
990
|
this._loadMissingSelected();
|
|
@@ -981,7 +1004,20 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
|
|
|
981
1004
|
if (!datasource) {
|
|
982
1005
|
throw new Error('Datasource is undefined');
|
|
983
1006
|
}
|
|
984
|
-
|
|
1007
|
+
const unfetchableIds = untracked(store._unfetchableIds);
|
|
1008
|
+
const missingSelectedIds = untracked(store._missingSelected);
|
|
1009
|
+
if (unfetchableIds.includes(id) || missingSelectedIds.includes(id)) {
|
|
1010
|
+
const newUnfetchableIds = unfetchableIds.filter((unfetchableId) => unfetchableId !== id);
|
|
1011
|
+
const newMissingSelected = missingSelectedIds.filter((missingId) => missingId !== id);
|
|
1012
|
+
patchState(store, {
|
|
1013
|
+
_unfetchableIds: newUnfetchableIds,
|
|
1014
|
+
_missingSelected: newMissingSelected,
|
|
1015
|
+
});
|
|
1016
|
+
if (newMissingSelected.length === 0) {
|
|
1017
|
+
this._cancelFetchMissingIfNeeded();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
else if (oldMap.has(id)) {
|
|
985
1021
|
const newMap = new Map(oldMap);
|
|
986
1022
|
newMap.delete(id);
|
|
987
1023
|
patchState(store, { selectedMap: newMap });
|
|
@@ -1128,7 +1164,9 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
|
|
|
1128
1164
|
alias: 'manualInit',
|
|
1129
1165
|
});
|
|
1130
1166
|
manualInit = linkedSignal(() => this.manualInitInput());
|
|
1131
|
-
datasourceInput = input(null
|
|
1167
|
+
datasourceInput = input(null, {
|
|
1168
|
+
alias: 'datasource',
|
|
1169
|
+
});
|
|
1132
1170
|
store = inject(RdtSelectStore);
|
|
1133
1171
|
visibleOptions = this.store.visibleOptions;
|
|
1134
1172
|
queryValidatorFnInput = input(null, {
|
|
@@ -1172,6 +1210,12 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
|
|
|
1172
1210
|
this.loadingInput() ||
|
|
1173
1211
|
RdtObjectUtils.someValuesTrue(this.loadingMap()));
|
|
1174
1212
|
});
|
|
1213
|
+
datasourceEffect = effect(() => {
|
|
1214
|
+
const datasource = this.datasourceInput();
|
|
1215
|
+
if (datasource) {
|
|
1216
|
+
this.store.setDatasource(datasource);
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1175
1219
|
ngOnInit() {
|
|
1176
1220
|
super.ngOnInit();
|
|
1177
1221
|
const control = this.control();
|
|
@@ -1230,7 +1274,7 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
|
|
|
1230
1274
|
}
|
|
1231
1275
|
});
|
|
1232
1276
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtBaseSelectCommonComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
1233
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.0", type: RdtBaseSelectCommonComponent, isStandalone: true, inputs: { manualInitInput: { classPropertyName: "manualInitInput", publicName: "manualInit", isSignal: true, isRequired: false, transformFunction: null }, datasourceInput: { classPropertyName: "datasourceInput", publicName: "
|
|
1277
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.0", type: RdtBaseSelectCommonComponent, isStandalone: true, inputs: { manualInitInput: { classPropertyName: "manualInitInput", publicName: "manualInit", isSignal: true, isRequired: false, transformFunction: null }, datasourceInput: { classPropertyName: "datasourceInput", publicName: "datasource", 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 });
|
|
1234
1278
|
}
|
|
1235
1279
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtBaseSelectCommonComponent, decorators: [{
|
|
1236
1280
|
type: Directive
|