@energycap/components 0.45.2-multi-select-component.20260303-0733 → 0.45.2-multi-select-component.20260303-0736

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.
@@ -3142,6 +3142,39 @@ class MenuComponent {
3142
3142
  * @param menuComponentId Used to prefix the generated ID. This should be the ID of the menu component the item is present in.
3143
3143
  * @memberof MenuComponent
3144
3144
  */
3145
+ /**
3146
+ * Filter an array of MenuItems by label or caption (contains match).
3147
+ * Supports grouped items under headings and divided-sections.
3148
+ *
3149
+ * @param options The full list of MenuItems to filter
3150
+ * @param filterText The search text to filter by
3151
+ * @returns The filtered list of MenuItems
3152
+ */
3153
+ static filterOptions(options, filterText) {
3154
+ const searchText = filterText.toLowerCase();
3155
+ if (filterText && filterText !== '') {
3156
+ const matchesSearch = (item) => item.label.toLowerCase().indexOf(searchText) >= 0 ||
3157
+ (item.caption && item.caption.toLowerCase().indexOf(searchText) >= 0);
3158
+ return options.reduce((filteredItems, item) => {
3159
+ // Match the item itself if it doesn't have any children
3160
+ if (!item.items?.length && matchesSearch(item)) {
3161
+ filteredItems.push(item);
3162
+ // If we have children, filter them and add the parent if it has any children that match
3163
+ }
3164
+ else if (item.items?.length && (item.display === 'heading' || item.display === 'divided-section')) {
3165
+ const filteredChildItems = item.items.filter(matchesSearch);
3166
+ if (filteredChildItems.length) {
3167
+ // Need to clone the parent item with the filtered children so we don't modify the original
3168
+ filteredItems.push({ ...item, items: filteredChildItems });
3169
+ }
3170
+ }
3171
+ return filteredItems;
3172
+ }, []);
3173
+ }
3174
+ else {
3175
+ return options;
3176
+ }
3177
+ }
3145
3178
  static getIndexedItemId(items, item, menuComponentId) {
3146
3179
  if (item) {
3147
3180
  for (let i = 0; i < items.length; i++) {
@@ -4480,38 +4513,6 @@ class ComboboxComponent extends FormControlBase {
4480
4513
  this.scrollMenu();
4481
4514
  }
4482
4515
  }
4483
- /**
4484
-
4485
- * Filter array of options by label or caption (contains)
4486
- *
4487
- * @param filterText The value of textbox that we will filter our options by
4488
- *
4489
- * @memberof ComboboxComponent
4490
- */
4491
- filterOptionsArray(filterText) {
4492
- let searchText = filterText.toLowerCase();
4493
- if (filterText && filterText !== '') {
4494
- const matchesSearch = (item) => item.label.toLowerCase().indexOf(searchText) >= 0 || (item.caption && item.caption.toLowerCase().indexOf(searchText) >= 0);
4495
- return this.options.reduce((filteredItems, item) => {
4496
- // Match the item itself if it doesn't have any children
4497
- if (!item.items?.length && matchesSearch(item)) {
4498
- filteredItems.push(item);
4499
- // If we have children, filter them and add the parent if it has any children that match
4500
- }
4501
- else if (item.items?.length && (item.display === 'heading' || item.display === 'divided-section')) {
4502
- const filteredChildItems = item.items.filter(matchesSearch);
4503
- if (filteredChildItems.length) {
4504
- // Need to clone the parent item with the filtered children so we don't modify the original
4505
- filteredItems.push({ ...item, items: filteredChildItems });
4506
- }
4507
- }
4508
- return filteredItems;
4509
- }, []);
4510
- }
4511
- else {
4512
- return this.options;
4513
- }
4514
- }
4515
4516
  /**
4516
4517
  * Find a given item's index in the filtered items array.
4517
4518
  *
@@ -4594,7 +4595,7 @@ class ComboboxComponent extends FormControlBase {
4594
4595
  this.search.emit(searchText);
4595
4596
  // do internal filtering if no one's subscribed to our search emitter
4596
4597
  if (this.search.observers.length === 0 && searchText !== undefined) {
4597
- this.resetOptions(this.filterOptionsArray(searchText));
4598
+ this.resetOptions(MenuComponent.filterOptions(this.options, searchText));
4598
4599
  if (this.addNewSelected && !this.addNewButton) {
4599
4600
  this.addNewSelected = false;
4600
4601
  }
@@ -8636,7 +8637,7 @@ class MultiselectComponent extends FormControlBase {
8636
8637
  const filterText = this.filterFormModel.value || '';
8637
8638
  this.search.emit(filterText);
8638
8639
  if (this.search.observers.length === 0) {
8639
- this.resetOptions(this.filterOptionsArray(filterText));
8640
+ this.resetOptions(MenuComponent.filterOptions(this.options, filterText));
8640
8641
  }
8641
8642
  if (this.popup) {
8642
8643
  this.popup.update();
@@ -8763,31 +8764,6 @@ class MultiselectComponent extends FormControlBase {
8763
8764
  }
8764
8765
  }
8765
8766
  }
8766
- /**
8767
- * Filter options by label (contains)
8768
- */
8769
- filterOptionsArray(filterText) {
8770
- const searchText = filterText.toLowerCase();
8771
- if (filterText && filterText !== '') {
8772
- const matchesSearch = (item) => item.label.toLowerCase().indexOf(searchText) >= 0 ||
8773
- (item.caption && item.caption.toLowerCase().indexOf(searchText) >= 0);
8774
- return this.options.reduce((filteredItems, item) => {
8775
- if (!item.items?.length && matchesSearch(item)) {
8776
- filteredItems.push(item);
8777
- }
8778
- else if (item.items?.length && (item.display === 'heading' || item.display === 'divided-section')) {
8779
- const filteredChildItems = item.items.filter(matchesSearch);
8780
- if (filteredChildItems.length) {
8781
- filteredItems.push({ ...item, items: filteredChildItems });
8782
- }
8783
- }
8784
- return filteredItems;
8785
- }, []);
8786
- }
8787
- else {
8788
- return this.options;
8789
- }
8790
- }
8791
8767
  /**
8792
8768
  * React to formModel changes from outside the component
8793
8769
  */