inviton-powerduck 0.0.106 → 0.0.107

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.
@@ -829,6 +829,43 @@ class DropdownListComponent extends TsxComponent<DropdownListArgs> implements Dr
829
829
  };
830
830
 
831
831
  if (!this.useMultiCheckboxes()) {
832
+ const DIACRITICS = ($ as any).fn.select2.amd.require('select2/diacritics');
833
+ const normalizeForSearch = (text: string) => {
834
+ if (text == null) {
835
+ return null;
836
+ }
837
+
838
+ return stripDiacritics(text).toUpperCase();
839
+ };
840
+ const stripDiacritics = (text: string) => {
841
+ function match(a) {
842
+ return DIACRITICS[a] || a;
843
+ }
844
+
845
+ return text.replace(/[^\u0000-\u007E]/g, match);
846
+ };
847
+ const getMatchingChildren = (term: string, dataSet: any) => {
848
+ const retVal: any[] = [];
849
+ for (const item of dataSet) {
850
+ if (item.children?.length > 0) {
851
+ const subData = getMatchingChildren(term, item.children);
852
+ if (subData.length > 0) {
853
+ retVal.push({
854
+ ...item,
855
+ children: subData
856
+ })
857
+ }
858
+ } else {
859
+ const normalized = normalizeForSearch(item.text);
860
+ if (normalized.indexOf(term) > -1) {
861
+ retVal.push(item);
862
+ }
863
+ }
864
+ }
865
+
866
+ return retVal;
867
+ };
868
+
832
869
  s2Args.data = null
833
870
  s2Args.ajax = {
834
871
  transport: function (params, success, failure) {
@@ -840,7 +877,15 @@ class DropdownListComponent extends TsxComponent<DropdownListArgs> implements Dr
840
877
  resData = opts;
841
878
  }
842
879
 
843
- success({ results: resData });
880
+ const data = (params?.data || {});
881
+ const query = normalizeForSearch(data.q ?? data.term)?.trim();
882
+
883
+ if (query == null || query.length == 0) {
884
+ success({ results: resData });
885
+ return;
886
+ }
887
+
888
+ success({ results: getMatchingChildren(query, resData) });
844
889
  }
845
890
  };
846
891
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inviton-powerduck",
3
- "version": "0.0.106",
3
+ "version": "0.0.107",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": " vite build && vue-tsc --declaration --emitDeclarationOnly",