@ngrdt/forms 0.0.74 → 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.
@@ -502,7 +502,6 @@ class RdtFileInputComponent extends RdtBaseFormInputComponent {
502
502
  .readAll(Array.from(target.files))
503
503
  .pipe(takeUntilDestroyed(this.destroyRef))
504
504
  .subscribe((files) => {
505
- console.log(files);
506
505
  this.onChange(files);
507
506
  this.writeValue(files);
508
507
  });
@@ -686,10 +685,12 @@ const rdtSelectInitialState = {
686
685
  datasource: null,
687
686
  selectedMap: new Map(),
688
687
  fetchError: null,
689
- missingValuePlaceholder: 'Načítání (ID = {id})...',
688
+ loadingValuePlaceholder: 'Načítání (ID = {id})...',
689
+ missingValuePlaceholder: 'Neznámá hodnota (ID = {id})',
690
690
  _fetchRequest: null,
691
691
  _fetchMissingRequest: null,
692
692
  _missingSelected: [],
693
+ _unfetchableIds: [],
693
694
  };
694
695
 
695
696
  function compareSelectRequestParams(a, b) {
@@ -720,6 +721,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
720
721
  const query = state.query();
721
722
  const selectedMap = state.selectedMap();
722
723
  const missing = state._missingSelected();
724
+ const unfetchable = state._unfetchableIds();
723
725
  if (query) {
724
726
  return items.map((it) => ({
725
727
  ...it,
@@ -728,13 +730,21 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
728
730
  }
729
731
  const selected = [];
730
732
  const missingPlaceholder = state.missingValuePlaceholder();
731
- const placeholders = missing.map((id) => ({
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) => ({
732
741
  id,
733
742
  label: missingPlaceholder.replace('{id}', String(id)),
734
743
  value: null,
735
744
  selected: true,
736
745
  }));
737
- placeholders.forEach((pl) => selected.push(pl));
746
+ selected.push(...loadingPlaceholders);
747
+ selected.push(...missingPlaceholders);
738
748
  items.forEach((item) => {
739
749
  selected.push({ ...item, selected: selectedMap.has(item.id) });
740
750
  });
@@ -868,6 +878,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
868
878
  },
869
879
  setSelected(ids) {
870
880
  patchState(store, {
881
+ _unfetchableIds: [],
871
882
  _missingSelected: ids,
872
883
  selectedMap: new Map(),
873
884
  });
@@ -895,6 +906,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
895
906
  });
896
907
  },
897
908
  _setAndGetMissing() {
909
+ const unfetchable = untracked(store._unfetchableIds);
898
910
  const allMissing = untracked(store._missingSelected);
899
911
  const items = untracked(store.options);
900
912
  const selectedMap = new Map(untracked(store.selectedMap));
@@ -906,7 +918,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
906
918
  selectedMap.set(id, item);
907
919
  selectedChanged = true;
908
920
  }
909
- else {
921
+ else if (!unfetchable.includes(id)) {
910
922
  newMissing.push(id);
911
923
  }
912
924
  }
@@ -934,12 +946,16 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
934
946
  _cancelFetchMissingIfNeeded() {
935
947
  const fetchMissingReq = untracked(store._fetchMissingRequest);
936
948
  const items = untracked(store.options);
937
- if (fetchMissingReq?.ids.every((id) => items.some((it) => it.id === id))) {
938
- fetchMissingReq.subscription.unsubscribe();
939
- patchState(store, {
940
- _fetchMissingRequest: null,
941
- _missingSelected: [],
942
- });
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
+ }
943
959
  }
944
960
  },
945
961
  _fetchMissing(ids, datasource) {
@@ -949,12 +965,17 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
949
965
  const sub = datasource.getItemsByIds(ids).subscribe((map) => {
950
966
  const newMissing = [];
951
967
  const newSelected = new Map(untracked(store.selectedMap));
968
+ const unfetchable = [...untracked(store._unfetchableIds)];
952
969
  for (const id of untracked(store._missingSelected)) {
953
970
  if (map.has(id)) {
954
971
  const value = map.get(id);
955
972
  const label = datasource.getLabel(value);
956
973
  newSelected.set(id, { label, value, id });
957
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
+ }
958
979
  else {
959
980
  newMissing.push(id);
960
981
  }
@@ -963,6 +984,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
963
984
  _fetchMissingRequest: null,
964
985
  _missingSelected: newMissing,
965
986
  selectedMap: newSelected,
987
+ _unfetchableIds: [...unfetchable],
966
988
  initialized: true,
967
989
  });
968
990
  this._loadMissingSelected();
@@ -982,7 +1004,20 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
982
1004
  if (!datasource) {
983
1005
  throw new Error('Datasource is undefined');
984
1006
  }
985
- if (oldMap.has(id)) {
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)) {
986
1021
  const newMap = new Map(oldMap);
987
1022
  newMap.delete(id);
988
1023
  patchState(store, { selectedMap: newMap });
@@ -1129,7 +1164,9 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
1129
1164
  alias: 'manualInit',
1130
1165
  });
1131
1166
  manualInit = linkedSignal(() => this.manualInitInput());
1132
- datasourceInput = input(null);
1167
+ datasourceInput = input(null, {
1168
+ alias: 'datasource',
1169
+ });
1133
1170
  store = inject(RdtSelectStore);
1134
1171
  visibleOptions = this.store.visibleOptions;
1135
1172
  queryValidatorFnInput = input(null, {
@@ -1173,6 +1210,12 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
1173
1210
  this.loadingInput() ||
1174
1211
  RdtObjectUtils.someValuesTrue(this.loadingMap()));
1175
1212
  });
1213
+ datasourceEffect = effect(() => {
1214
+ const datasource = this.datasourceInput();
1215
+ if (datasource) {
1216
+ this.store.setDatasource(datasource);
1217
+ }
1218
+ });
1176
1219
  ngOnInit() {
1177
1220
  super.ngOnInit();
1178
1221
  const control = this.control();
@@ -1231,7 +1274,7 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
1231
1274
  }
1232
1275
  });
1233
1276
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtBaseSelectCommonComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
1234
- 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: "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 });
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 });
1235
1278
  }
1236
1279
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: RdtBaseSelectCommonComponent, decorators: [{
1237
1280
  type: Directive