@indigina/ui-kit 1.1.670 → 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
  }
@@ -10829,6 +10836,7 @@ const kitTranslateFilterTitle = (translateService, title, useTranslation, transl
10829
10836
  };
10830
10837
 
10831
10838
  const nonIndexableCharacters = /[^A-Za-z0-9\-.:_,\\/]+/;
10839
+ const nonPhraseCharacters = /[^\p{L}\p{N}\-.:_,\\/]+/u;
10832
10840
  const kitFormatStringForSearch = (inputString, addWildcard = true) => {
10833
10841
  return inputString
10834
10842
  .split(nonIndexableCharacters)
@@ -10836,6 +10844,16 @@ const kitFormatStringForSearch = (inputString, addWildcard = true) => {
10836
10844
  .map(text => addWildcard ? text + '*' : text)
10837
10845
  .join(' ');
10838
10846
  };
10847
+ const kitFormatStringForPhraseSearch = (inputString) => {
10848
+ const words = inputString
10849
+ .split(nonPhraseCharacters)
10850
+ .filter(text => !!text);
10851
+ if (!words.length) {
10852
+ return '';
10853
+ }
10854
+ const wildcardClause = words.map(text => `${text}*`).join(' ');
10855
+ return `"${words.join(' ')}" | (${wildcardClause})`;
10856
+ };
10839
10857
 
10840
10858
  const kitBuildGridColumn = (field, title, type, sortable = true, hidden = false, width, filterType, excelFormat, apiField, hiddenInGrid, customFieldHandler, customRangeHandler, dateFilterConstraint) => ({
10841
10859
  field,
@@ -10868,7 +10886,8 @@ const kitBuildSortString = (sort, columns) => {
10868
10886
  }).join(', ');
10869
10887
  return sortString !== '' && sortString || undefined;
10870
10888
  };
10871
- const kitFetchGridData = ({ store, destroyRef, isLoading, fetchAction, fetchFromIndexAction, hasArchiveToggle, addSearchWildcard = true, error, }) => {
10889
+ const buildSearchTerm = (search, addSearchWildcard, phraseSearch) => phraseSearch ? kitFormatStringForPhraseSearch(search) : kitFormatStringForSearch(search, addSearchWildcard);
10890
+ const kitFetchGridData = ({ store, destroyRef, isLoading, fetchAction, fetchFromIndexAction, hasArchiveToggle, addSearchWildcard = true, phraseSearch = false, error, }) => {
10872
10891
  isLoading.set(true);
10873
10892
  const { skip, take, sort, filter, search, archive, columns } = store.selectSnapshot(KIT_GRID_STATE_TOKEN);
10874
10893
  const gridState = {
@@ -10880,17 +10899,17 @@ const kitFetchGridData = ({ store, destroyRef, isLoading, fetchAction, fetchFrom
10880
10899
  };
10881
10900
  const isArchive = hasArchiveToggle && archive || false;
10882
10901
  const isSearchMode = hasArchiveToggle && !isArchive || !!search;
10883
- const searchTerm = search && kitFormatStringForSearch(search, addSearchWildcard) || undefined;
10902
+ const searchTerm = search && buildSearchTerm(search, addSearchWildcard, phraseSearch) || undefined;
10884
10903
  const action = (isSearchMode && fetchFromIndexAction) ? fetchFromIndexAction({ ...gridState, searchTerm }) : fetchAction(gridState);
10885
10904
  store.dispatch(action).pipe(takeUntilDestroyed(destroyRef), finalize(() => isLoading.set(false))).subscribe({ error });
10886
10905
  };
10887
- const kitFetchExportGridData = ({ fetchAction, fetchIndexAction, sort, filter, search, columns, total, hasArchiveToggle = false, archiveModeEnabled = false, addSearchWildcard = true, }) => {
10906
+ const kitFetchExportGridData = ({ fetchAction, fetchIndexAction, sort, filter, search, columns, total, hasArchiveToggle = false, archiveModeEnabled = false, addSearchWildcard = true, phraseSearch = false, }) => {
10888
10907
  const isArchive = hasArchiveToggle && archiveModeEnabled || false;
10889
10908
  const isSearchMode = hasArchiveToggle && !isArchive || !!search;
10890
10909
  const sortString = kitBuildSortString(sort, columns);
10891
10910
  const filterString = kitBuildOdataFilter(kitBuildFilters(filter));
10892
10911
  if (isSearchMode) {
10893
- const searchTerm = search && kitFormatStringForSearch(search, addSearchWildcard) || undefined;
10912
+ const searchTerm = search && buildSearchTerm(search, addSearchWildcard, phraseSearch) || undefined;
10894
10913
  return fetchIndexAction(0, total, sortString, filterString, searchTerm);
10895
10914
  }
10896
10915
  return fetchAction(0, total, sortString, filterString);