@meshmakers/shared-ui 3.5.210 → 3.5.240

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.
@@ -5444,6 +5444,7 @@ class EntitySelectInputComponent {
5444
5444
  entityMap = new Map();
5445
5445
  // Private members
5446
5446
  searchSubject = new Subject();
5447
+ typedText = '';
5447
5448
  destroy$ = new Subject();
5448
5449
  onChange = () => { };
5449
5450
  onTouched = () => { };
@@ -5501,25 +5502,30 @@ class EntitySelectInputComponent {
5501
5502
  // Event handlers
5502
5503
  onFilterChange(event) {
5503
5504
  const filter = event;
5504
- if (!filter || filter.length < this.minSearchLength) {
5505
+ this.typedText = filter ?? '';
5506
+ if (this.typedText.length < this.minSearchLength) {
5505
5507
  this.filteredEntities = [];
5506
- return;
5507
5508
  }
5508
- this.searchSubject.next(filter);
5509
+ this.searchSubject.next(this.typedText);
5509
5510
  }
5510
5511
  onSelectionChange(value) {
5511
- if (value && typeof value === 'string') {
5512
- // Find the entity that matches the selected display text
5513
- const entity = this.entityMap.get(value);
5514
- if (entity) {
5515
- this.selectEntity(entity);
5512
+ if (!value) {
5513
+ if (this.selectedEntity) {
5514
+ this.clearSelection();
5516
5515
  }
5516
+ return;
5517
+ }
5518
+ // Find the entity that matches the selected display text
5519
+ const entity = this.entityMap.get(value);
5520
+ if (entity) {
5521
+ this.selectEntity(entity);
5517
5522
  }
5518
5523
  }
5519
5524
  onFocus() {
5520
5525
  // Optional: Trigger search on focus if there's already text
5521
5526
  const currentValue = this.searchFormControl.value;
5522
5527
  if (currentValue && currentValue.length >= this.minSearchLength && this.filteredEntities.length === 0) {
5528
+ this.typedText = currentValue;
5523
5529
  this.searchSubject.next(currentValue);
5524
5530
  }
5525
5531
  }
@@ -5536,12 +5542,10 @@ class EntitySelectInputComponent {
5536
5542
  }
5537
5543
  // Public methods
5538
5544
  clear() {
5539
- this.selectedEntity = null;
5540
5545
  this.filteredEntities = [];
5541
5546
  this.entityMap.clear();
5542
5547
  this.searchFormControl.setValue('', { emitEvent: false });
5543
- this.onChange(null);
5544
- this.entityCleared.emit();
5548
+ this.clearSelection();
5545
5549
  this.autocomplete.focus();
5546
5550
  }
5547
5551
  focus() {
@@ -5553,18 +5557,23 @@ class EntitySelectInputComponent {
5553
5557
  this.clear();
5554
5558
  }
5555
5559
  // Private methods
5560
+ clearSelection() {
5561
+ this.selectedEntity = null;
5562
+ this.onChange(null);
5563
+ this.entityCleared.emit();
5564
+ }
5556
5565
  setupSearch() {
5557
- this.searchSubject.pipe(debounceTime(this.debounceMs), distinctUntilChanged(), tap(() => {
5566
+ this.searchSubject.pipe(debounceTime(this.debounceMs), distinctUntilChanged(), filter(text => text.length >= this.minSearchLength), tap(() => {
5558
5567
  this.isLoading = true;
5559
5568
  this.filteredEntities = [];
5560
- }), switchMap(filter => {
5569
+ }), switchMap(searchText => {
5561
5570
  if (!this.dataSource) {
5562
5571
  return of({ totalCount: 0, items: [] });
5563
5572
  }
5564
- if (filter.startsWith(this.prefix)) {
5565
- if (typeof filter === 'string') {
5566
- filter = filter.replace(this.prefix, '').trim();
5567
- return this.dataSource.onFilter(filter, this.maxResults).catch(error => {
5573
+ if (searchText.startsWith(this.prefix)) {
5574
+ if (typeof searchText === 'string') {
5575
+ searchText = searchText.replace(this.prefix, '').trim();
5576
+ return this.dataSource.onFilter(searchText, this.maxResults).catch(error => {
5568
5577
  console.error('Entity search error:', error);
5569
5578
  return { totalCount: 0, items: [] };
5570
5579
  });
@@ -5574,7 +5583,7 @@ class EntitySelectInputComponent {
5574
5583
  }
5575
5584
  }
5576
5585
  else {
5577
- return this.dataSource.onFilter(filter, this.maxResults).catch(error => {
5586
+ return this.dataSource.onFilter(searchText, this.maxResults).catch(error => {
5578
5587
  console.error('Entity search error:', error);
5579
5588
  return { totalCount: 0, items: [] };
5580
5589
  });
@@ -5584,6 +5593,9 @@ class EntitySelectInputComponent {
5584
5593
  return of({ totalCount: 0, items: [] });
5585
5594
  })).subscribe(result => {
5586
5595
  this.isLoading = false;
5596
+ if (this.typedText.length < this.minSearchLength) {
5597
+ return;
5598
+ }
5587
5599
  if (this.prefix && result.items.length === 1) {
5588
5600
  // Auto-select if exactly one match in prefix mode
5589
5601
  this.selectEntity(result.items[0]);