UNPKG

tabulator-tables

Version:

Interactive table generation JavaScript library

2 lines 11.9 kB
/* Tabulator v4.3.0 (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){var t=this,r={params:e.definition.formatterParams||{}};switch(_typeof(e.definition.formatter)){case"string":"tick"===e.definition.formatter&&(e.definition.formatter="tickCross",void 0===r.params.crossElement&&(r.params.crossElement=!1),console.warn("DEPRECATION WANRING - the tick formatter has been depricated, please use the tickCross formatter with the crossElement param set to false")),t.formatters[e.definition.formatter]?r.formatter=t.formatters[e.definition.formatter]:(console.warn("Formatter Error - No such formatter found: ",e.definition.formatter),r.formatter=t.formatters.plaintext);break;case"function":r.formatter=e.definition.formatter;break;default:r.formatter=t.formatters.plaintext}e.modules.format=r},Format.prototype.cellRendered=function(e){e.column.modules.format.renderedCallback&&e.column.modules.format.renderedCallback()},Format.prototype.formatValue=function(e){function t(t){e.column.modules.format.renderedCallback=t}var r=e.getComponent(),a="function"==typeof e.column.modules.format.params?e.column.modules.format.params(r):e.column.modules.format.params;return e.column.modules.format.formatter.call(this,r,a,t)},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?"&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,r){return this.emptyToSpace(this.sanitizeHTML(e.getValue()))},html:function(e,t,r){return e.getValue()},textarea:function(e,t,r){return e.getElement().style.whiteSpace="pre-wrap",this.emptyToSpace(this.sanitizeHTML(e.getValue()))},money:function(e,t,r){var a,o,i,n,l=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(l))return this.emptyToSpace(this.sanitizeHTML(e.getValue()));for(a=!1!==m?l.toFixed(m):l,a=String(a).split("."),o=a[0],i=a.length>1?s+a[1]:"",n=/(\d+)(\d{3})/;n.test(o);)o=o.replace(n,"$1"+c+"$2");return d?o+i+u:u+o+i},link:function(e,t,r){var a,o=e.getValue(),i=t.urlPrefix||"",n=this.emptyToSpace(o),l=document.createElement("a");if(t.labelField&&(a=e.getData(),n=a[t.labelField]),t.label)switch(_typeof(t.label)){case"string":n=t.label;break;case"function":n=t.label(e)}if(t.urlField&&(a=e.getData(),o=a[t.urlField]),t.url)switch(_typeof(t.url)){case"string":o=t.url;break;case"function":o=t.url(e)}return l.setAttribute("href",i+o),t.target&&l.setAttribute("target",t.target),l.innerHTML=this.emptyToSpace(this.sanitizeHTML(n)),l},image:function(e,t,r){var a=document.createElement("img");switch(a.setAttribute("src",e.getValue()),_typeof(t.height)){case"number":a.style.height=t.height+"px";break;case"string":a.style.height=t.height}switch(_typeof(t.width)){case"number":a.style.width=t.width+"px";break;case"string":a.style.width=t.width}return a.addEventListener("load",function(){e.getRow().normalizeHeight()}),a},tickCross:function(e,t,r){var a=e.getValue(),o=e.getElement(),i=t.allowEmpty,n=t.allowTruthy,l=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 n&&a||!0===a||"true"===a||"True"===a||1===a||"1"===a?(o.setAttribute("aria-checked",!0),l||""):!i||"null"!==a&&""!==a&&null!==a&&void 0!==a?(o.setAttribute("aria-checked",!1),s||""):(o.setAttribute("aria-checked","mixed"),"")},datetime:function(e,t,r){var a=t.inputFormat||"YYYY-MM-DD hh:mm:ss",o=t.outputFormat||"DD/MM/YYYY hh:mm:ss",i=void 0!==t.invalidPlaceholder?t.invalidPlaceholder:"",n=e.getValue(),l=moment(n,a);return l.isValid()?l.format(o):!0===i?n:"function"==typeof i?i(n):i},datetimediff:function(e,t,r){var a=t.inputFormat||"YYYY-MM-DD hh:mm:ss",o=void 0!==t.invalidPlaceholder?t.invalidPlaceholder:"",i=void 0!==t.suffix&&t.suffix,n=void 0!==t.unit?t.unit:void 0,l=void 0!==t.humanize&&t.humanize,s=void 0!==t.date?t.date:moment(),c=e.getValue(),u=moment(c,a);return u.isValid()?l?moment.duration(u.diff(s)).humanize(i):u.diff(s,n)+(i?" "+i:""):!0===o?c:"function"==typeof o?o(c):o},lookup:function(e,t,r){var a=e.getValue();return void 0===t[a]?(console.warn("Missing display value for "+a),a):t[a]},star:function(e,t,r){var a=e.getValue(),o=e.getElement(),i=t&&t.stars?t.stars:5,n=document.createElement("span"),l=document.createElementNS("http://www.w3.org/2000/svg","svg");n.style.verticalAlign="middle",l.setAttribute("width","14"),l.setAttribute("height","14"),l.setAttribute("viewBox","0 0 512 512"),l.setAttribute("xml:space","preserve"),l.style.padding="0 1px",a=parseInt(a)<i?parseInt(a):i;for(var s=1;s<=i;s++){var c=l.cloneNode(!0);c.innerHTML=s<=a?'<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 "/>',n.appendChild(c)}return o.style.whiteSpace="nowrap",o.style.overflow="hidden",o.style.textOverflow="ellipsis",o.setAttribute("aria-label",a),n},traffic:function(e,t,r){var a,o,i=this.sanitizeHTML(e.getValue())||0,n=document.createElement("span"),l=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(i)&&void 0!==e.getValue()){switch(n.classList.add("tabulator-traffic-light"),o=parseFloat(i)<=l?parseFloat(i):l,o=parseFloat(o)>=s?parseFloat(o):s,a=(l-s)/100,o=Math.round((o-s)/a),void 0===c?"undefined":_typeof(c)){case"string":u=c;break;case"function":u=c(i);break;case"object":if(Array.isArray(c)){var d=100/c.length,m=Math.floor(o/d);m=Math.min(m,c.length-1),m=Math.max(m,0),u=c[m];break}}return n.style.backgroundColor=u,n}},progress:function(e,t,r){var a,o,i,n,l,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(o=parseFloat(s)<=u?parseFloat(s):u,o=parseFloat(o)>=d?parseFloat(o):d,a=(u-d)/100,o=Math.round((o-d)/a),_typeof(t.color)){case"string":i=t.color;break;case"function":i=t.color(s);break;case"object":if(Array.isArray(t.color)){var f=100/t.color.length,p=Math.floor(o/f);p=Math.min(p,t.color.length-1),p=Math.max(p,0),i=t.color[p];break}default:i="#2DC214"}switch(_typeof(t.legend)){case"string":n=t.legend;break;case"function":n=t.legend(s);break;case"boolean":n=s;break;default:n=!1}switch(_typeof(t.legendColor)){case"string":l=t.legendColor;break;case"function":l=t.legendColor(s);break;case"object":if(Array.isArray(t.legendColor)){var f=100/t.legendColor.length,p=Math.floor(o/f);p=Math.min(p,t.legendColor.length-1),p=Math.max(p,0),l=t.legendColor[p]}break;default:l="#000"}return c.style.minWidth="30px",c.style.position="relative",c.setAttribute("aria-label",o),"<div style='position:realtive; height:100%;' data-max='"+u+"' data-min='"+d+"'><div style='position:relative; height:100%; width:calc("+o+"%); background-color:"+i+"; display:inline-block;'></div></div>"+(n?"<div style='position:absolute; top:4px; left:0; text-align:"+m+"; width:100%; color:"+l+";'>"+n+"</div>":"")},color:function(e,t,r){return e.getElement().style.backgroundColor=this.sanitizeHTML(e.getValue()),""},buttonTick:function(e,t,r){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,r){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,r){return this.table.rowManager.activeRows.indexOf(e.getRow()._getSelf())+1},handle:function(e,t,r){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,r){function a(t){var r=e.getRow().getElement().getElementsByClassName("tabulator-responsive-collapse")[0];i=t,i?(n.classList.add("open"),r&&(r.style.display="")):(n.classList.remove("open"),r&&(r.style.display="none"))}var o=this,i=!1,n=document.createElement("div");return n.classList.add("tabulator-responsive-collapse-toggle"),n.innerHTML="<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>",e.getElement().classList.add("tabulator-row-handle"),o.table.options.responsiveLayoutCollapseStartOpen&&(i=!0),n.addEventListener("click",function(e){e.stopImmediatePropagation(),a(!i)}),a(i),n}},Tabulator.prototype.registerModule("format",Format);