@recursyve/nice-ui-kit.v2 14.0.0-beta.129 → 14.0.0-beta.131

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.
@@ -2735,13 +2735,13 @@ class NiceAsyncTypeaheadService {
2735
2735
  var _a;
2736
2736
  (_a = this.requestsSubscription$) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2737
2737
  }
2738
- initialize(resource, options) {
2738
+ initialize(resource) {
2739
2739
  return __awaiter(this, void 0, void 0, function* () {
2740
2740
  const { initialized } = this.state$.getValue();
2741
2741
  if (initialized) {
2742
2742
  return;
2743
2743
  }
2744
- return this.search(resource, "", options);
2744
+ return this.search(resource, "");
2745
2745
  });
2746
2746
  }
2747
2747
  sendRequest(request) {
@@ -2773,15 +2773,15 @@ class NiceAsyncTypeaheadService {
2773
2773
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false, loadingPage: false }));
2774
2774
  }));
2775
2775
  }
2776
- search(resource, searchQuery, options) {
2776
+ search(resource, searchQuery) {
2777
2777
  this.requests$.next({
2778
2778
  resource,
2779
2779
  searchQuery,
2780
- searchOptions: options,
2780
+ searchOptions: this.getSearchOptions(),
2781
2781
  page: 0
2782
2782
  });
2783
2783
  }
2784
- loadMore(resource, options) {
2784
+ loadMore(resource) {
2785
2785
  const { loadingPage, isLastPage } = this.state$.getValue();
2786
2786
  if (loadingPage || isLastPage) {
2787
2787
  return;
@@ -2791,7 +2791,7 @@ class NiceAsyncTypeaheadService {
2791
2791
  resource,
2792
2792
  page,
2793
2793
  searchQuery,
2794
- searchOptions: options,
2794
+ searchOptions: this.getSearchOptions(),
2795
2795
  });
2796
2796
  }
2797
2797
  getActive() {
@@ -2800,10 +2800,16 @@ class NiceAsyncTypeaheadService {
2800
2800
  getInitialized() {
2801
2801
  return this.state$.value.initialized;
2802
2802
  }
2803
+ getSearchOptions() {
2804
+ return this.state$.value.searchOptions;
2805
+ }
2806
+ setSearchOptions(searchOptions) {
2807
+ this.state$.next(Object.assign(Object.assign({}, this.state$.value), { searchOptions }));
2808
+ }
2803
2809
  setActive(entity) {
2804
2810
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { active: entity !== null && entity !== void 0 ? entity : null }));
2805
2811
  }
2806
- setActiveId(resource, id, options) {
2812
+ setActiveId(resource, id) {
2807
2813
  return __awaiter(this, void 0, void 0, function* () {
2808
2814
  if (!id) {
2809
2815
  return;
@@ -2819,21 +2825,22 @@ class NiceAsyncTypeaheadService {
2819
2825
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { items: [localItem], active: localItem, page: 0, isLastPage: false }));
2820
2826
  return;
2821
2827
  }
2822
- const entity = yield api.getById(id, options);
2828
+ const entity = yield api.getById(id, this.getSearchOptions());
2823
2829
  if (!entity) {
2824
2830
  return;
2825
2831
  }
2826
2832
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { items: [entity], active: entity, page: 0, isLastPage: false }));
2827
2833
  }
2828
- catch (_a) { }
2834
+ catch (_a) {
2835
+ }
2829
2836
  finally {
2830
2837
  this.state$.next(Object.assign(Object.assign({}, this.state$.value), { loading: false }));
2831
2838
  }
2832
2839
  });
2833
2840
  }
2834
- reloadActive(resource, options) {
2841
+ reloadActive(resource) {
2835
2842
  var _a;
2836
- return this.setActiveId(resource, (_a = this.state$.value.active) === null || _a === void 0 ? void 0 : _a.id, options);
2843
+ return this.setActiveId(resource, (_a = this.state$.value.active) === null || _a === void 0 ? void 0 : _a.id);
2837
2844
  }
2838
2845
  reloadFilteredItems() {
2839
2846
  // TODO: Use a better way to trigger the items$ observable
@@ -2915,6 +2922,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2915
2922
  this._disabled = false;
2916
2923
  this.id = uuid.v4();
2917
2924
  this.describedBy = "";
2925
+ this.componentInitialized = false;
2918
2926
  this.propagate = () => { };
2919
2927
  if (this.ngControl) {
2920
2928
  this.ngControl.valueAccessor = this;
@@ -2985,35 +2993,41 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
2985
2993
  return this.service.getInitialized();
2986
2994
  }
2987
2995
  ngOnInit() {
2988
- this.service.listenForRequest();
2989
- if (this.ngControl) {
2990
- if (this.ngControl.disabled) {
2991
- this.searchControl.disable({ emitEvent: false });
2992
- }
2993
- this.ngControl.statusChanges.subscribe((status) => {
2994
- this.disabled = status === "DISABLED";
2995
- if (this._disabled) {
2996
+ return __awaiter(this, void 0, void 0, function* () {
2997
+ this.service.listenForRequest();
2998
+ if (this.ngControl) {
2999
+ if (this.ngControl.disabled) {
2996
3000
  this.searchControl.disable({ emitEvent: false });
2997
3001
  }
2998
- else {
2999
- this.searchControl.enable({ emitEvent: false });
3000
- }
3001
- });
3002
- }
3003
- if (this.filterFn) {
3004
- this.service.setFilterFn(this.filterFn);
3005
- }
3006
- if (this.searchControl) {
3007
- this.valueChangesSub$ = this.searchControl.valueChanges.pipe(debounceTime(500), distinctUntilChanged()).subscribe(text => {
3008
- if (typeof text !== "string") {
3009
- return;
3010
- }
3011
- this.service.search(this.resource, text, this.searchOptions);
3012
- });
3013
- }
3014
- if (this.preloadResource) {
3015
- this.service.search(this.resource, "", this.searchOptions);
3016
- }
3002
+ this.ngControl.statusChanges.subscribe((status) => {
3003
+ this.disabled = status === "DISABLED";
3004
+ if (this._disabled) {
3005
+ this.searchControl.disable({ emitEvent: false });
3006
+ }
3007
+ else {
3008
+ this.searchControl.enable({ emitEvent: false });
3009
+ }
3010
+ });
3011
+ }
3012
+ if (this.filterFn) {
3013
+ this.service.setFilterFn(this.filterFn);
3014
+ }
3015
+ if (this.searchControl) {
3016
+ this.valueChangesSub$ = this.searchControl.valueChanges.pipe(debounceTime(500), distinctUntilChanged()).subscribe(text => {
3017
+ if (typeof text !== "string") {
3018
+ return;
3019
+ }
3020
+ this.service.search(this.resource, text);
3021
+ });
3022
+ }
3023
+ if (this.preloadResource) {
3024
+ this.service.search(this.resource, "");
3025
+ }
3026
+ this.componentInitialized = true;
3027
+ if (this.initialWriteValue !== undefined) {
3028
+ yield this.writeValue(this.initialWriteValue);
3029
+ }
3030
+ });
3017
3031
  }
3018
3032
  ngOnDestroy() {
3019
3033
  this.service.closeRequestSubscription();
@@ -3022,8 +3036,9 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3022
3036
  ngOnChanges(changes) {
3023
3037
  if ("searchOptions" in changes) {
3024
3038
  const change = changes.searchOptions;
3039
+ this.service.setSearchOptions(change.currentValue);
3025
3040
  if (!change.isFirstChange() && change.currentValue !== change.previousValue && this.autoReload) {
3026
- this.service.search(this.resource, "", change.currentValue);
3041
+ this.service.search(this.resource, "");
3027
3042
  this.service.items$.pipe(take(1)).subscribe(() => this.checkIfValueStillExist());
3028
3043
  }
3029
3044
  }
@@ -3042,6 +3057,10 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3042
3057
  }
3043
3058
  writeValue(value) {
3044
3059
  return __awaiter(this, void 0, void 0, function* () {
3060
+ if (!this.componentInitialized) {
3061
+ this.initialWriteValue = value;
3062
+ return;
3063
+ }
3045
3064
  if (this._value === value || (isNullOrUndefined(this._value) && isNullOrUndefined(value))) {
3046
3065
  return;
3047
3066
  }
@@ -3054,7 +3073,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3054
3073
  return;
3055
3074
  }
3056
3075
  else {
3057
- yield this.service.setActiveId(this.resource, value, this.searchOptions).then(() => this.updateSearchInput());
3076
+ yield this.service.setActiveId(this.resource, value).then(() => this.updateSearchInput());
3058
3077
  }
3059
3078
  this.value = value;
3060
3079
  });
@@ -3097,7 +3116,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3097
3116
  });
3098
3117
  }
3099
3118
  if (this.open && !this.initialized) {
3100
- this.service.initialize(this.resource, this.searchOptions);
3119
+ this.service.initialize(this.resource);
3101
3120
  }
3102
3121
  if (!this.open && this.ngControl) {
3103
3122
  this.ngControl.control.markAsTouched();
@@ -3126,7 +3145,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3126
3145
  this.stateChanges.next();
3127
3146
  this.entityRemoved.emit();
3128
3147
  if (reload) {
3129
- this.service.search(this.resource, "", this.searchOptions);
3148
+ this.service.search(this.resource, "");
3130
3149
  }
3131
3150
  }
3132
3151
  formatLabel(item) {
@@ -3142,7 +3161,7 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3142
3161
  return item;
3143
3162
  }
3144
3163
  onEndScroll() {
3145
- this.service.loadMore(this.resource, this.searchOptions);
3164
+ this.service.loadMore(this.resource);
3146
3165
  }
3147
3166
  focusChanged(isFocused) {
3148
3167
  if (isFocused !== this.focused) {
@@ -3155,20 +3174,19 @@ class NiceAsyncTypeaheadComponent extends _BaseAsyncTypeaheadComponent {
3155
3174
  }
3156
3175
  reload() {
3157
3176
  var _a, _b;
3158
- return __awaiter(this, void 0, void 0, function* () {
3159
- yield ((_a = this.service) === null || _a === void 0 ? void 0 : _a.search(this.resource, (_b = this.searchControl.value) !== null && _b !== void 0 ? _b : "", this.searchOptions));
3160
- });
3177
+ (_a = this.service) === null || _a === void 0 ? void 0 : _a.search(this.resource, (_b = this.searchControl.value) !== null && _b !== void 0 ? _b : "");
3161
3178
  }
3162
3179
  reloadActive() {
3163
3180
  var _a, _b;
3164
3181
  return __awaiter(this, void 0, void 0, function* () {
3165
- yield ((_a = this.service) === null || _a === void 0 ? void 0 : _a.reloadActive(this.resource, this.searchOptions));
3182
+ yield ((_a = this.service) === null || _a === void 0 ? void 0 : _a.reloadActive(this.resource));
3166
3183
  const active = (_b = this.service) === null || _b === void 0 ? void 0 : _b.getActive();
3167
3184
  this.updateLabel(active);
3168
3185
  });
3169
3186
  }
3170
3187
  setSearchOptions(options) {
3171
3188
  this.searchOptions = options;
3189
+ this.service.setSearchOptions(options);
3172
3190
  }
3173
3191
  updateLabel(item) {
3174
3192
  if (!item) {
@@ -10605,12 +10623,7 @@ class TranslationFormComponent {
10605
10623
  }
10606
10624
  set disabled(value) {
10607
10625
  this._disabled = coerceBooleanProperty(value);
10608
- if (this._disabled) {
10609
- this.currentControl.disable({ emitEvent: false });
10610
- }
10611
- else {
10612
- this.currentControl.enable({ emitEvent: false });
10613
- }
10626
+ this.handleDisabledState();
10614
10627
  this.stateChanges.next();
10615
10628
  }
10616
10629
  set placeholder(placeholder) {
@@ -10675,6 +10688,7 @@ class TranslationFormComponent {
10675
10688
  }
10676
10689
  setLanguage(language) {
10677
10690
  this.currentControl = this.formGroup.get(language);
10691
+ this.handleDisabledState();
10678
10692
  this.changeDetectorRef.markForCheck();
10679
10693
  }
10680
10694
  setupFormControls(languages) {
@@ -10688,6 +10702,16 @@ class TranslationFormComponent {
10688
10702
  this.formGroup.removeControl(key);
10689
10703
  }
10690
10704
  this.currentControl = this.formGroup.get(languages[0]);
10705
+ this.handleDisabledState();
10706
+ }
10707
+ handleDisabledState() {
10708
+ var _a, _b;
10709
+ if (this._disabled) {
10710
+ (_a = this.currentControl) === null || _a === void 0 ? void 0 : _a.disable({ emitEvent: false });
10711
+ }
10712
+ else {
10713
+ (_b = this.currentControl) === null || _b === void 0 ? void 0 : _b.enable({ emitEvent: false });
10714
+ }
10691
10715
  }
10692
10716
  }
10693
10717
  TranslationFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.3", ngImport: i0, type: TranslationFormComponent, deps: [{ token: i1$3.ControlContainer }, { token: TranslationContextDirective }, { token: NiceTranslationFormService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });