/*! * Fuzzy Search for DataTables * 2021 SpryMedia Ltd - datatables.net/license MIT license * * Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein * BSD 2-Clause License * Copyright (c) 2018, Tadeusz Łazurski * All rights reserved. */ import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;function levenshtein(e,t,r){var a=e.length,o=t.length,n=[];r=(r||(a(r||100))return d(r||100);if(0===a)return d(o);if(0===o)return d(a);for(f=1;f<=a;++f)for(i=e[f-1],s=1;s<=o;++s){if(f===s&&4u.score&&(u.score=h)}(n[s].scorea,score:u.score})}}for(i=0;ie+t.score,0)/n.length*100)+"%"};return{pass:!0,score:Math.round(n.reduce((e,t)=>e+t.score,0)/n.length*100)+"%"}}DataTable.ext.search.push(function(e,t,r){var a,o=e.oInit.fuzzySearch;if(o){if(void 0!==e.aoData[r]._fuzzySearch)return a=e.aoData[r]._fuzzySearch.score,void 0!==o.rankColumn&&(e.aoData[r].anCells[o.rankColumn].innerHTML=a,e.aoData[r]._aSortData[o.rankColumn]=+a.substring(0,a.length-1)),e.aoData[r]._fuzzySearch.pass;void 0!==o.rankColumn&&(e.aoData[r].anCells[o.rankColumn].innerHTML="",e.aoData[r]._aSortData[o.rankColumn]="")}return!0}),$(document).on("init.dt",function(e,t){var r,a,o,n,s,i,c,l,u,h,f,d,p=new DataTable.Api(t),g=p.init(),v=g.fuzzySearch;function b(e){(s.attr("blurred")?(s.css({filter:"blur(0px)"}).removeAttr("blurred"),l.removeAttr("highlighted").css(n),c):(s.css({filter:"blur(1px)"}).attr("blurred",!0),c.removeAttr("highlighted").css(n),l)).attr("highlighted",!0).css(o),f(e)}function z(e,t){e.attr("highlighted")||b(t)}function m(){i.remove()}v&&(r=!1,a=$("div.dataTables_filter input",p.table().container()),o={"font-weight":"600","background-color":"rgba(255,255,255,0.1)"},n={"font-weight":"500","background-color":"transparent"},d={border:"none",background:"none","font-size":"100%",width:"50%",display:"inline-block",color:"white",cursor:"pointer",padding:"0.5em"},"object"==typeof v&&v.toggleSmart&&(s=$('').insertAfter(a).css({border:"none",background:"none",position:"relative",right:"33px",top:"0px",cursor:"pointer",color:"#3b5e99","margin-top":"1px"}),c=$('').insertAfter(a).css(d).css(o).attr("highlighted","true"),l=$('').insertAfter(a).css(d),a.css({"padding-right":"30px"}),$(a.parent()).css("right","-33px").css("position","relative"),d=$("
Search Type
").css({"padding-bottom":"0.5em","font-size":"0.8em"}),i=$('
').css({position:"absolute",top:"2em",background:"white","border-radius":"4px","text-align":"center",padding:"0.5em","background-color":"#16232a","box-shadow":"4px 4px 4px rgba(0, 0, 0, 0.5)",color:"white",transition:"opacity 0.25s","z-index":"30001",width:a.outerWidth()-3}).append(d).append(c).append(l)),$(t.nTable).off("search.dt.DT"),f=function(e){("input"!==e.type||void 0!==g.search&&g.search.return)&&"Enter"!==e.key&&"click"!==e.type||(s&&!s.attr("blurred")?(p.rows().iterator("row",function(e,t){e.aoData[t]._fuzzySearch=void 0},!1),h=a.val(),u=h,r=!0,p.search(h),r=!1,h=""):(u=a.val(),h="",void 0!==u&&0!==u.length&&(u=u.toLowerCase()),p.rows().iterator("row",function(e,t){e.aoData[t]._fuzzySearch=fuzzySearch(u,e.aoData[t]._aFilterData,v)},!1),r=!0,p.search(""),a.val(u),r=!1),r=!0,p.draw(),r=!1)},(h=u="",DataTable.Api.register)("search.fuzzy()",function(e){return void 0===e?u:(u=e.toLowerCase(),h=p.search(),a.val(u),p.rows().iterator("row",function(e,t){e.aoData[t]._fuzzySearch=fuzzySearch(u,e.aoData[t]._aFilterData,v)},!1),this)}),a.off(),s&&(s.on("click",b).on("mouseenter",function(){i.insertAfter(s).on("mouseleave",m),i.css("left",a.position().left+3),c.on("click",e=>z(c,e)),l.on("click",e=>z(l,e))}).on("mouseleave",m),a.on("mouseenter",function(){i.insertAfter(s).on("mouseleave",m),i.css("left",a.position().left+3),c.on("click",e=>z(c,e)),l.on("click",e=>z(l,e))}).on("mouseleave",function(){var e=!1;i.on("mouseenter",()=>e=!0),s.on("mouseenter",()=>e=!0),setTimeout(function(){e||m()},250)}),d=p.state.loaded(),p.on("stateSaveParams",function(e,t,r){r._fuzzySearch={active:s.attr("blurred"),val:a.val()}}),null!==d)&&void 0!==d._fuzzySearch&&(a.val(d._fuzzySearch.val),"true"===d._fuzzySearch.active)&&(s.click(),p.page(d.start/d.length).draw("page")),p.on("search",function(){r||a.val(p.search()!==h?p.search():u)}),a.on("input keydown",f))});export default DataTable;