Current File : /home/inlingua/www/crm/ninexb/wp-content/plugins/tablesome/src/table/src/plugins/image/image.js |
import ImageCellComponent from"./image.svelte";class ImagePlugin{constructor(e){this.hooks=e,this.namespace="tablesome",this.init()}init(){this.hooks.addFilter("getColumnFormats",this.namespace,this.getColumnFormats),this.hooks.addFilter("getCellComponent",this.namespace,this.getCellComponent),this.hooks.addFilter("getSearchRecords",this.namespace,this.getSearchRecords),this.hooks.addFilter("getSortRecords",this.namespace,this.getSortRecords),this.hooks.addFilter("getFilterRecords",this.namespace,this.getFilterRecords)}getColumnFormats(e){return e.push({format:"file",class:"tablesome__option--basic tablesome__option--basic-file",icon:"format-image",text:"Media"}),e}getCellComponent(e){return"file"==e.cellType&&(e.component=ImageCellComponent),e}getSearchRecords(e){if("file"==e.cellType&&!e.isContentMatch){let t=e.cell.value?e.cell.value.toString().toLowerCase():"";e.isContentMatch=t.indexOf(e.searchQuery)>=0}return e}getSortRecords(e){return"file"==e.cellType&&(e.valueA="value"in e.rowA&&e.rowA.value?e.rowA.value:"",e.valueB="value"in e.rowB&&e.rowB.value?e.rowB.value:"",e.sortType="number"),e}getFilterRecords(e){if("file"==e.filter.format){let t=e.filter.value?parseFloat(e.filter.value):"",l="value"in e.cell&&e.cell.value?parseFloat(e.cell.value):"";e.isContentMatch=filterNumber(e.filter.operator.value,l,t)}return e}}export default ImagePlugin;const filterNumber=(e,t,l)=>"="==e?t==l:"!="==e?t!=l:">"==e?t>l:"<"==e?t<l:">="==e?t>=l:"<="==e?t<=l:void 0;