@indigina/ui-kit 1.1.671 → 1.1.672

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.
@@ -9762,30 +9762,37 @@ const findMatches = (obj, translatePrefix, searchableKeys, search, translateValu
9762
9762
  if (!search || !searchableKeys.length || !obj || typeof obj !== 'object' || Array.isArray(obj)) {
9763
9763
  return [];
9764
9764
  }
9765
- const isStringArray = (value) => Array.isArray(value) && value.every(item => typeof item === 'string');
9766
9765
  const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
9767
9766
  const getPathKey = (path) => path.split('.').pop() || path;
9768
9767
  const normalizedSearch = search.toLowerCase();
9769
- const getValueByPath = (value, path) => {
9770
- return path.split('.').reduce((current, segment) => isRecord(current) ? current[segment] : undefined, value);
9771
- };
9772
- const getMatchValue = (value) => {
9773
- if (typeof value === 'string') {
9774
- return value.toLowerCase().includes(normalizedSearch)
9775
- ? { matchedValue: value, resolverValue: value }
9776
- : null;
9777
- }
9778
- if (isStringArray(value)) {
9779
- const matchedItems = value.filter(item => item.toLowerCase().includes(normalizedSearch));
9780
- if (!matchedItems.length) {
9781
- return null;
9768
+ // Arrays met along the path (including arrays of objects) are traversed element by element.
9769
+ const getStringsByPath = (value, path) => {
9770
+ let isCollection = false;
9771
+ const collect = (current, segments) => {
9772
+ if (Array.isArray(current)) {
9773
+ isCollection = true;
9774
+ return current.flatMap(item => collect(item, segments));
9775
+ }
9776
+ if (!segments.length) {
9777
+ return typeof current === 'string' ? [current] : [];
9782
9778
  }
9783
- return { matchedValue: matchedItems.join(', '), resolverValue: matchedItems };
9779
+ return isRecord(current) ? collect(current[segments[0]], segments.slice(1)) : [];
9780
+ };
9781
+ return { strings: collect(value, path.split('.')), isCollection };
9782
+ };
9783
+ const getMatchValue = (value, path) => {
9784
+ const { strings, isCollection } = getStringsByPath(value, path);
9785
+ const matchedItems = strings.filter(item => item.toLowerCase().includes(normalizedSearch));
9786
+ if (!matchedItems.length) {
9787
+ return null;
9784
9788
  }
9785
- return null;
9789
+ return {
9790
+ matchedValue: matchedItems.join(', '),
9791
+ resolverValue: isCollection ? matchedItems : matchedItems[0],
9792
+ };
9786
9793
  };
9787
9794
  return Array.from(new Set(searchableKeys)).reduce((matches, path) => {
9788
- const matchValue = getMatchValue(getValueByPath(obj, path));
9795
+ const matchValue = getMatchValue(obj, path);
9789
9796
  if (!matchValue) {
9790
9797
  return matches;
9791
9798
  }