@ngrdt/forms 0.0.39 → 0.0.42

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.
@@ -497,6 +497,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
497
497
  type: Directive
498
498
  }] });
499
499
 
500
+ function getRdtSelectPage(data, pageIndex, pageSize) {
501
+ if (pageSize < 1) {
502
+ throw new Error('Invalid page size');
503
+ }
504
+ if (pageIndex < 0) {
505
+ throw new Error('Invalid page index');
506
+ }
507
+ if (pageIndex * pageSize > data.length) {
508
+ return {
509
+ data: [],
510
+ totalCount: data.length,
511
+ pageIndex: pageIndex,
512
+ };
513
+ }
514
+ const start = pageIndex * pageSize;
515
+ const end = start + pageSize;
516
+ const items = data.slice(start, end);
517
+ return {
518
+ data: items,
519
+ totalCount: data.length,
520
+ pageIndex: pageIndex,
521
+ };
522
+ }
523
+
500
524
  class RdtSelectDatasource {
501
525
  }
502
526
 
@@ -511,7 +535,7 @@ class RdtOfflineSelectDatasource extends RdtSelectDatasource {
511
535
  this.preprocessedData = this.preprocessData(data);
512
536
  }
513
537
  getData(params) {
514
- const page = this.getPage(this.filterData(params.query), params.pageIndex, params.pageSize);
538
+ const page = getRdtSelectPage(this.filterData(params.query), params.pageIndex, params.pageSize);
515
539
  return of(page);
516
540
  }
517
541
  getLabel(item) {
@@ -549,32 +573,10 @@ class RdtOfflineSelectDatasource extends RdtSelectDatasource {
549
573
  }
550
574
  return this.preprocessedData.filter((item) => item.label.includes(prepQuery));
551
575
  }
552
- getPage(data, pageIndex, pageSize) {
553
- if (pageSize < 1) {
554
- throw new Error('Invalid page size');
555
- }
556
- if (pageIndex < 0) {
557
- throw new Error('Invalid page index');
558
- }
559
- if (pageIndex * pageSize > data.length) {
560
- return {
561
- data: [],
562
- totalCount: data.length,
563
- pageIndex: pageIndex,
564
- };
565
- }
566
- const start = pageIndex * pageSize;
567
- const end = start + pageSize;
568
- const items = data.slice(start, end);
569
- return {
570
- data: items,
571
- totalCount: data.length,
572
- pageIndex: pageIndex,
573
- };
574
- }
575
576
  }
576
577
 
577
578
  const rdtSelectInitialState = {
579
+ initialized: false,
578
580
  query: null,
579
581
  nextPageIndex: 0,
580
582
  pageSize: 20,
@@ -641,6 +643,10 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
641
643
  return selected;
642
644
  }),
643
645
  })), withMethods((store) => ({
646
+ init(initialValue) {
647
+ this.setSelected(initialValue ?? []);
648
+ patchState(store, { initialized: true });
649
+ },
644
650
  fetch() {
645
651
  const datasource = untracked(store.datasource);
646
652
  const index = untracked(store.nextPageIndex);
@@ -812,9 +818,12 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
812
818
  return newMissing;
813
819
  },
814
820
  _loadMissingSelected() {
821
+ const datasource = store.datasource();
815
822
  const reallyMissing = this._setAndGetMissing();
816
- if (!untracked(store.loading) && reallyMissing.length > 0) {
817
- this._fetchMissing(reallyMissing);
823
+ if (!untracked(store.loading) &&
824
+ reallyMissing.length > 0 &&
825
+ datasource) {
826
+ this._fetchMissing(reallyMissing, datasource);
818
827
  }
819
828
  },
820
829
  _cancelFetchMissingIfNeeded() {
@@ -828,9 +837,8 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
828
837
  });
829
838
  }
830
839
  },
831
- _fetchMissing(ids) {
832
- const datasource = untracked(store.datasource);
833
- if (!datasource || ids.length === 0) {
840
+ _fetchMissing(ids, datasource) {
841
+ if (ids.length === 0) {
834
842
  return;
835
843
  }
836
844
  const sub = datasource.getItemsByIds(ids).subscribe((map) => {
@@ -1053,6 +1061,16 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
1053
1061
  });
1054
1062
  ngOnInit() {
1055
1063
  super.ngOnInit();
1064
+ const control = this.control();
1065
+ if (control && control.value !== null) {
1066
+ const arr = Array.isArray(control.value)
1067
+ ? control.value
1068
+ : [control.value];
1069
+ this.store.init(arr);
1070
+ }
1071
+ else {
1072
+ this.store.init(null);
1073
+ }
1056
1074
  this.debouncedInput$
1057
1075
  .pipe(takeUntilDestroyed(this.destroyRef))
1058
1076
  .subscribe((value) => this.handleInput(value));
@@ -1378,5 +1396,5 @@ class RdtCommonValidators {
1378
1396
  * Generated bundle index. Do not edit.
1379
1397
  */
1380
1398
 
1381
- export { NO_OP_FILE_READER, NoOpFileReader, RDT_DEFAULT_FILE_LABEL_FN, RDT_DEFAULT_FILE_READER, RDT_DEFAULT_MAX_FILE_SIZE, RdtBaseFormInputComponent, RdtBaseSelectCommonComponent, RdtCheckboxComponent, RdtCommonValidators, RdtDateComponent, RdtDateValidators, RdtFileInputComponent, RdtFileReader, RdtFileReaderArrayBuffer, RdtFileReaderBase64, RdtMultiSelectComponent, RdtNumericInputComponent, RdtOfflineSelectDatasource, RdtSelectDatasource, RdtSelectOfflineDatasourceProviderDirective, RdtSelectOptionDirective, RdtSelectStore, RdtSingleSelectComponent, RdtTextInputComponent, VnshFileReaderText, czechFileLabelFn, rdtSelectInitialState };
1399
+ export { NO_OP_FILE_READER, NoOpFileReader, RDT_DEFAULT_FILE_LABEL_FN, RDT_DEFAULT_FILE_READER, RDT_DEFAULT_MAX_FILE_SIZE, RdtBaseFormInputComponent, RdtBaseSelectCommonComponent, RdtCheckboxComponent, RdtCommonValidators, RdtDateComponent, RdtDateValidators, RdtFileInputComponent, RdtFileReader, RdtFileReaderArrayBuffer, RdtFileReaderBase64, RdtMultiSelectComponent, RdtNumericInputComponent, RdtOfflineSelectDatasource, RdtSelectDatasource, RdtSelectOfflineDatasourceProviderDirective, RdtSelectOptionDirective, RdtSelectStore, RdtSingleSelectComponent, RdtTextInputComponent, VnshFileReaderText, czechFileLabelFn, getRdtSelectPage, rdtSelectInitialState };
1382
1400
  //# sourceMappingURL=ngrdt-forms.mjs.map