Current File : /home/inlingua/www/crm/ninexb/wp-content/plugins/tablesome/src/table/src/plugins/text/text.js |
import TextCellComponent from"./text.svelte";class TextPlugin{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:"text",class:"tablesome__option--basic tablesome__option--basic-text",icon:"editor-alignleft",text:"Text"}),e}getCellComponent(e){return"text"==e.cellType&&(e.component=TextCellComponent),e}getSearchRecords(e){if("text"==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"text"==e.cellType&&(e.valueA="value"in e.rowA&&e.rowA.value?e.rowA.value.toLowerCase():"",e.valueB="value"in e.rowB&&e.rowB.value?e.rowB.value.toLowerCase():"",e.sortType="text"),e}getFilterRecords(e){if("text"==e.filter.format){let t=e.filter.value.toLowerCase(),o="value"in e.cell&&e.cell.value?e.cell.value:"";o=o.toLowerCase(),e.isContentMatch=filterText(e.filter.operator.value,o,t)}return e}}export default TextPlugin;const filterText=(e,t,o)=>"is"==e?t==o:"is_not"==e?t!=o:"contains"==e?t.includes(o):"does_not_contain"==e?!t.includes(o):"starts_with"==e?t.startsWith(o):"ends_with"==e?t.endsWith(o):"empty"==e||"not_empty"==e?t<=o:void 0;