@marcura/marcura-combobox 4.7.1 → 4.7.2

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.
@@ -1550,6 +1550,14 @@
1550
1550
  _this.defaultValue = [];
1551
1551
  _this.hasCssClass = true;
1552
1552
  _this.allowCustom = false;
1553
+ /**
1554
+ * This field contains factory method which takes a custom text input and returns an Observable<TItem>.
1555
+ * The observable sends the text to a remote service, which processes it and returns a generated TItem.
1556
+ * Works when allowCustom is true.
1557
+ *
1558
+ * @memberof MultiselectComponent
1559
+ */
1560
+ _this.itemFactory$ = undefined;
1553
1561
  _this.changed = new core.EventEmitter();
1554
1562
  _this.isReadOnlyTag = null;
1555
1563
  _this.isActivatedTag = function () { return false; };
@@ -1563,11 +1571,10 @@
1563
1571
  var _c;
1564
1572
  return _c = {}, _c[_this.valueField] = null, _c[_this.textField] = text, _c;
1565
1573
  };
1566
- _this.valueNormalizer = function (text$) { return text$.pipe(operators.map(function () {
1574
+ _this.valueNormalizer = function (text$) { return text$.pipe(operators.switchMap(function () {
1567
1575
  var _a, _b;
1568
- var value = null;
1569
1576
  if (!_this.component) {
1570
- return value;
1577
+ return rxjs.of(null);
1571
1578
  }
1572
1579
  // Can't use this._searchText.value here as it might be empty, consider:
1573
1580
  // 1) type custom text, 2) focus out and back in 3) there's a text in searchbar,
@@ -1575,41 +1582,35 @@
1575
1582
  // So this.component.searchbar.value is to be used.
1576
1583
  var text = (_this.component.searchbar.value || '').trim();
1577
1584
  if (!text) {
1578
- return value;
1585
+ return rxjs.of(null);
1579
1586
  }
1580
1587
  var matchingValue = (_b = (_a = _this.component.value) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item[_this.textField].toLowerCase() === text.toLowerCase(); })) !== null && _b !== void 0 ? _b : null;
1581
1588
  // Handle case when value already contains items that match the search text.
1582
1589
  if (matchingValue) {
1583
- value = matchingValue;
1590
+ return rxjs.of(matchingValue);
1584
1591
  }
1585
1592
  // If no matches found in the selected values, check if item is in cache.
1586
- else if (_this.getItem(_this._valueNormalizerItems, text)) {
1587
- // If areItemsCached is off, then this.data will be lost by this moment,
1588
- // so we use a cache this.valueNormalizerItems.
1589
- // This is relevant especially in IE/Edge where this.component.value is null,
1590
- // so the code falls back to this condition section.
1591
- value = _this.getItem(_this._valueNormalizerItems, text);
1593
+ var cachedValue = matchingValue ? null : _this.getItem(_this._valueNormalizerItems, text);
1594
+ // If areItemsCached is off, then this.data will be lost by this moment,
1595
+ // so we use a cache this.valueNormalizerItems.
1596
+ // This is relevant especially in IE/Edge where this.component.value is null,
1597
+ // so the code falls back to this condition section.
1598
+ if (cachedValue) {
1599
+ return rxjs.of(cachedValue);
1592
1600
  }
1593
1601
  // If no match is found and custom values are allowed, create a new custom item
1594
- else if (_this.allowCustom) {
1595
- value = _this.itemFactory(text);
1596
- if (_this._isSync) {
1597
- // Restore original items after selection, otherwise when opening the list
1598
- // next time, only the selected item will appear.
1599
- _this.loadItems();
1600
- }
1601
- }
1602
- else {
1603
- // Clears search text if suggestion hasn't been selected.
1604
- // Steps to reproduce.
1605
- // 1. Use Dymanic Empty sample.
1606
- // 2. Type 'to', wait for the list to load, but don't select 'Tokai'. Instead hit Esc key.
1607
- // 3. See that the search bar still contains 'to' text, while the value is null,
1608
- // which is wrong - search bar text should be removed.
1609
- // this.component.searchbar.suggestedText = ''; // This doesn't work.
1610
- // As the above line doesn't work, so workaround it by setting form control value to null.
1611
- _this.valueFormControl.setValue(value);
1602
+ if (_this.allowCustom) {
1603
+ return (_this.itemFactory$ ? _this.itemFactory$(text) : rxjs.of(_this.itemFactory(text))).pipe(function (newValue) {
1604
+ if (_this._isSync) {
1605
+ // Restore original items after selection, otherwise when opening the list
1606
+ // next time, only the selected item will appear.
1607
+ _this.loadItems();
1608
+ }
1609
+ return newValue;
1610
+ });
1612
1611
  }
1612
+ return rxjs.of(null);
1613
+ }), operators.map(function (value) {
1613
1614
  _this._valueNormalizerItems = [];
1614
1615
  return value;
1615
1616
  })); };
@@ -1770,6 +1771,14 @@
1770
1771
  }
1771
1772
  });
1772
1773
  this._observer.listen(this._isOpen.pipe(operators.filter(function (event) { return event.isOpen; })), function () { return _this.opened.emit(); });
1774
+ // Blurred: Manually clear the filter text, as it will persist by default when allowCustom=true.
1775
+ if (this.allowCustom) {
1776
+ this._observer.listen(this._isFocused.pipe(operators.skip(1), operators.debounceTime(100)), function (isFocused) {
1777
+ if (!isFocused) {
1778
+ _this.component.clearFilter();
1779
+ }
1780
+ });
1781
+ }
1773
1782
  };
1774
1783
  return MultiselectComponent;
1775
1784
  }(AbstractComboboxComponent));
@@ -1828,6 +1837,7 @@
1828
1837
  noItemsText: [{ type: core.Input }],
1829
1838
  minSearchText: [{ type: core.Input }],
1830
1839
  allowCustom: [{ type: core.Input }],
1840
+ itemFactory$: [{ type: core.Input }],
1831
1841
  changed: [{ type: core.Output }],
1832
1842
  isReadOnlyTag: [{ type: core.Input }],
1833
1843
  isActivatedTag: [{ type: core.Input }],