UNPKG

tabulator-tables

Version:

Interactive table generation JavaScript library

2 lines 13.9 kB
/* Tabulator v4.9.3 (c) Oliver Folkerd */ var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Format=function(e){this.table=e};Format.prototype.initializeColumn=function(e){e.modules.format=this.lookupFormatter(e,""),void 0!==e.definition.formatterPrint&&(e.modules.format.print=this.lookupFormatter(e,"Print")),void 0!==e.definition.formatterClipboard&&(e.modules.format.clipboard=this.lookupFormatter(e,"Clipboard")),void 0!==e.definition.formatterHtmlOutput&&(e.modules.format.htmlOutput=this.lookupFormatter(e,"HtmlOutput"))},Format.prototype.lookupFormatter=function(e,t){var o={params:e.definition["formatter"+t+"Params"]||{}},r=e.definition["formatter"+t];switch(void 0===r?"undefined":_typeof(r)){case"string":"tick"===r&&(r="tickCross",void 0===o.params.crossElement&&(o.params.crossElement=!1),console.warn("DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false")),this.formatters[r]?o.formatter=this.formatters[r]:(console.warn("Formatter Error - No such formatter found: ",r),o.formatter=this.formatters.plaintext);break;case"function":o.formatter=r;break;default:o.formatter=this.formatters.plaintext}return o},Format.prototype.cellRendered=function(e){e.modules.format&&e.modules.format.renderedCallback&&!e.modules.format.rendered&&(e.modules.format.renderedCallback(),e.modules.format.rendered=!0)},Format.prototype.formatValue=function(e){function t(t){e.modules.format||(e.modules.format={}),e.modules.format.renderedCallback=t,e.modules.format.rendered=!1}var o=e.getComponent(),r="function"==typeof e.column.modules.format.params?e.column.modules.format.params(o):e.column.modules.format.params;return e.column.modules.format.formatter.call(this,o,r,t)},Format.prototype.formatExportValue=function(e,t){var o,r=e.column.modules.format[t];if(r){var a=function(t){e.modules.format||(e.modules.format={}),e.modules.format.renderedCallback=t,e.modules.format.rendered=!1};return o="function"==typeof r.params?r.params(component):r.params,r.formatter.call(this,e.getComponent(),o,a)}return this.formatValue(e)},Format.prototype.sanitizeHTML=function(e){if(e){var t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};return String(e).replace(/[&<>"'`=\/]/g,function(e){return t[e]})}return e},Format.prototype.emptyToSpace=function(e){return null===e||void 0===e||""===e?"&nbsp;":e},Format.prototype.getFormatter=function(e){var e;switch(void 0===e?"undefined":_typeof(e)){case"string":this.formatters[e]?e=this.formatters[e]:(console.warn("Formatter Error - No such formatter found: ",e),e=this.formatters.plaintext);break;case"function":e=e;break;default:e=this.formatters.plaintext}return e},Format.prototype.formatters={plaintext:function(e,t,o){return this.emptyToSpace(this.sanitizeHTML(e.getValue()))},html:function(e,t,o){return e.getValue()},textarea:function(e,t,o){return e.getElement().style.whiteSpace="pre-wrap",this.emptyToSpace(this.sanitizeHTML(e.getValue()))},money:function(e,t,o){var r,a,n,l,i=parseFloat(e.getValue()),s=t.decimal||".",c=t.thousand||",",u=t.symbol||"",d=!!t.symbolAfter,m=void 0!==t.precision?t.precision:2;if(isNaN(i))return this.emptyToSpace(this.sanitizeHTML(e.getValue()));for(r=!1!==m?i.toFixed(m):i,r=String(r).split("."),a=r[0],n=r.length>1?s+r[1]:"",l=/(\d+)(\d{3})/;l.test(a);)a=a.replace(l,"$1"+c+"$2");return d?a+n+u:u+a+n},link:function(e,t,o){var r,a=e.getValue(),n=t.urlPrefix||"",l=t.download,i=a,s=document.createElement("a");if(t.labelField&&(r=e.getData(),i=r[t.labelField]),t.label)switch(_typeof(t.label)){case"string":i=t.label;break;case"function":i=t.label(e)}if(i){if(t.urlField&&(r=e.getData(),a=r[t.urlField]),t.url)switch(_typeof(t.url)){case"string":a=t.url;break;case"function":a=t.url(e)}return s.setAttribute("href",n+a),t.target&&s.setAttribute("target",t.target),t.download&&(l="function"==typeof l?l(e):!0===l?"":l,s.setAttribute("download",l)),s.innerHTML=this.emptyToSpace(this.sanitizeHTML(i)),s}return"&nbsp;"},image:function(e,t,o){var r=document.createElement("img"),a=e.getValue();switch(t.urlPrefix&&(a=t.urlPrefix+e.getValue()),t.urlSuffix&&(a+=t.urlSuffix),r.setAttribute("src",a),_typeof(t.height)){case"number":r.style.height=t.height+"px";break;case"string":r.style.height=t.height}switch(_typeof(t.width)){case"number":r.style.width=t.width+"px";break;case"string":r.style.width=t.width}return r.addEventListener("load",function(){e.getRow().normalizeHeight()}),r},tickCross:function(e,t,o){var r=e.getValue(),a=e.getElement(),n=t.allowEmpty,l=t.allowTruthy,i=void 0!==t.tickElement?t.tickElement:'<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>',s=void 0!==t.crossElement?t.crossElement:'<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>';return l&&r||!0===r||"true"===r||"True"===r||1===r||"1"===r?(a.setAttribute("aria-checked",!0),i||""):!n||"null"!==r&&""!==r&&null!==r&&void 0!==r?(a.setAttribute("aria-checked",!1),s||""):(a.setAttribute("aria-checked","mixed"),"")},datetime:function(e,t,o){var r=t.inputFormat||"YYYY-MM-DD hh:mm:ss",a=t.outputFormat||"DD/MM/YYYY hh:mm:ss",n=void 0!==t.invalidPlaceholder?t.invalidPlaceholder:"",l=e.getValue(),i=moment(l,r);return i.isValid()?t.timezone?i.tz(t.timezone).format(a):i.format(a):!0===n?l:"function"==typeof n?n(l):n},datetimediff:function(e,t,o){var r=t.inputFormat||"YYYY-MM-DD hh:mm:ss",a=void 0!==t.invalidPlaceholder?t.invalidPlaceholder:"",n=void 0!==t.suffix&&t.suffix,l=void 0!==t.unit?t.unit:void 0,i=void 0!==t.humanize&&t.humanize,s=void 0!==t.date?t.date:moment(),c=e.getValue(),u=moment(c,r);return u.isValid()?i?moment.duration(u.diff(s)).humanize(n):u.diff(s,l)+(n?" "+n:""):!0===a?c:"function"==typeof a?a(c):a},lookup:function(e,t,o){var r=e.getValue();return void 0===t[r]?(console.warn("Missing display value for "+r),r):t[r]},star:function(e,t,o){var r=e.getValue(),a=e.getElement(),n=t&&t.stars?t.stars:5,l=document.createElement("span"),i=document.createElementNS("http://www.w3.org/2000/svg","svg");l.style.verticalAlign="middle",i.setAttribute("width","14"),i.setAttribute("height","14"),i.setAttribute("viewBox","0 0 512 512"),i.setAttribute("xml:space","preserve"),i.style.padding="0 1px",r=r&&!isNaN(r)?parseInt(r):0,r=Math.max(0,Math.min(r,n));for(var s=1;s<=n;s++){var c=i.cloneNode(!0);c.innerHTML=s<=r?'<polygon fill="#FFEA00" stroke="#C1AB60" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>':'<polygon fill="#D2D2D2" stroke="#686868" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>',l.appendChild(c)}return a.style.whiteSpace="nowrap",a.style.overflow="hidden",a.style.textOverflow="ellipsis",a.setAttribute("aria-label",r),l},traffic:function(e,t,o){var r,a,n=this.sanitizeHTML(e.getValue())||0,l=document.createElement("span"),i=t&&t.max?t.max:100,s=t&&t.min?t.min:0,c=t&&void 0!==t.color?t.color:["red","orange","green"],u="#666666";if(!isNaN(n)&&void 0!==e.getValue()){switch(l.classList.add("tabulator-traffic-light"),a=parseFloat(n)<=i?parseFloat(n):i,a=parseFloat(a)>=s?parseFloat(a):s,r=(i-s)/100,a=Math.round((a-s)/r),void 0===c?"undefined":_typeof(c)){case"string":u=c;break;case"function":u=c(n);break;case"object":if(Array.isArray(c)){var d=100/c.length,m=Math.floor(a/d);m=Math.min(m,c.length-1),m=Math.max(m,0),u=c[m];break}}return l.style.backgroundColor=u,l}},progress:function(e,t,o){var r,a,n,l,i,s=this.sanitizeHTML(e.getValue())||0,c=e.getElement(),u=t&&t.max?t.max:100,d=t&&t.min?t.min:0,m=t&&t.legendAlign?t.legendAlign:"center";switch(a=parseFloat(s)<=u?parseFloat(s):u,a=parseFloat(a)>=d?parseFloat(a):d,r=(u-d)/100,a=Math.round((a-d)/r),_typeof(t.color)){case"string":n=t.color;break;case"function":n=t.color(s);break;case"object":if(Array.isArray(t.color)){var f=100/t.color.length,p=Math.floor(a/f);p=Math.min(p,t.color.length-1),p=Math.max(p,0),n=t.color[p];break}default:n="#2DC214"}switch(_typeof(t.legend)){case"string":l=t.legend;break;case"function":l=t.legend(s);break;case"boolean":l=s;break;default:l=!1}switch(_typeof(t.legendColor)){case"string":i=t.legendColor;break;case"function":i=t.legendColor(s);break;case"object":if(Array.isArray(t.legendColor)){var f=100/t.legendColor.length,p=Math.floor(a/f);p=Math.min(p,t.legendColor.length-1),p=Math.max(p,0),i=t.legendColor[p]}break;default:i="#000"}c.style.minWidth="30px",c.style.position="relative",c.setAttribute("aria-label",a);var h=document.createElement("div");if(h.style.display="inline-block",h.style.position="relative",h.style.width=a+"%",h.style.backgroundColor=n,h.style.height="100%",h.setAttribute("data-max",u),h.setAttribute("data-min",d),l){var g=document.createElement("div");g.style.position="absolute",g.style.top="4px",g.style.left=0,g.style.textAlign=m,g.style.width="100%",g.style.color=i,g.innerHTML=l}return o(function(){if(!(e instanceof CellComponent)){var t=document.createElement("div");t.style.position="absolute",t.style.top="4px",t.style.bottom="4px",t.style.left="4px",t.style.right="4px",c.appendChild(t),c=t}c.appendChild(h),l&&c.appendChild(g)}),""},color:function(e,t,o){return e.getElement().style.backgroundColor=this.sanitizeHTML(e.getValue()),""},buttonTick:function(e,t,o){return'<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>'},buttonCross:function(e,t,o){return'<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>'},rownum:function(e,t,o){return this.table.rowManager.activeRows.indexOf(e.getRow()._getSelf())+1},handle:function(e,t,o){return e.getElement().classList.add("tabulator-row-handle"),"<div class='tabulator-row-handle-box'><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div></div>"},responsiveCollapse:function(e,t,o){function r(e){var t=n.element;n.open=e,t&&(n.open?(a.classList.add("open"),t.style.display=""):(a.classList.remove("open"),t.style.display="none"))}var a=document.createElement("div"),n=e.getRow()._row.modules.responsiveLayout;return a.classList.add("tabulator-responsive-collapse-toggle"),a.innerHTML="<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>",e.getElement().classList.add("tabulator-row-handle"),a.addEventListener("click",function(e){e.stopImmediatePropagation(),r(!n.open)}),r(n.open),a},rowSelection:function(e,t,o){var r=this,a=document.createElement("input");if(a.type="checkbox",this.table.modExists("selectRow",!0))if(a.addEventListener("click",function(e){e.stopPropagation()}),"function"==typeof e.getRow){var n=e.getRow();n instanceof RowComponent?(a.addEventListener("change",function(e){n.toggleSelect()}),a.checked=n.isSelected&&n.isSelected(),this.table.modules.selectRow.registerRowSelectCheckbox(n,a)):a=""}else a.addEventListener("change",function(e){r.table.modules.selectRow.selectedRows.length?r.table.deselectRow():r.table.selectRow(t.rowRange)}),this.table.modules.selectRow.registerHeaderSelectCheckbox(a);return a}},Tabulator.prototype.registerModule("format",Format);