tabulator-tables
Version:
Interactive table generation JavaScript library
2 lines • 19.7 kB
JavaScript
/* 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},Edit=function(e){this.table=e,this.currentCell=!1,this.mouseClick=!1,this.recursionBlock=!1,this.invalidEdit=!1};Edit.prototype.initializeColumn=function(e){var t=this,i={editor:!1,blocked:!1,check:e.definition.editable,params:e.definition.editorParams||{}};switch(_typeof(e.definition.editor)){case"string":"tick"===e.definition.editor&&(e.definition.editor="tickCross",console.warn("DEPRECATION WANRING - the tick editor has been depricated, please use the tickCross editor")),t.editors[e.definition.editor]?i.editor=t.editors[e.definition.editor]:console.warn("Editor Error - No such editor found: ",e.definition.editor);break;case"function":i.editor=e.definition.editor;break;case"boolean":!0===e.definition.editor&&("function"!=typeof e.definition.formatter?("tick"===e.definition.formatter&&(e.definition.formatter="tickCross",console.warn("DEPRECATION WANRING - the tick editor has been depricated, please use the tickCross editor")),t.editors[e.definition.formatter]?i.editor=t.editors[e.definition.formatter]:i.editor=t.editors.input):console.warn("Editor Error - Cannot auto lookup editor for a custom formatter: ",e.definition.formatter))}i.editor&&(e.modules.edit=i)},Edit.prototype.getCurrentCell=function(){return!!this.currentCell&&this.currentCell.getComponent()},Edit.prototype.clearEditor=function(){var e,t=this.currentCell;if(this.invalidEdit=!1,t){for(this.currentCell=!1,e=t.getElement(),e.classList.remove("tabulator-validation-fail"),e.classList.remove("tabulator-editing");e.firstChild;)e.removeChild(e.firstChild);t.row.getElement().classList.remove("tabulator-row-editing")}},Edit.prototype.cancelEdit=function(){if(this.currentCell){var e=this.currentCell,t=this.currentCell.getComponent();this.clearEditor(),e.setValueActual(e.getValue()),e.column.cellEvents.cellEditCancelled&&e.column.cellEvents.cellEditCancelled.call(this.table,t),this.table.options.cellEditCancelled.call(this.table,t)}},Edit.prototype.bindEditor=function(e){var t=this,i=e.getElement();i.setAttribute("tabindex",0),i.addEventListener("click",function(e){i.classList.contains("tabulator-editing")||i.focus()}),i.addEventListener("mousedown",function(e){t.mouseClick=!0}),i.addEventListener("focus",function(i){t.recursionBlock||t.edit(e,i,!1)})},Edit.prototype.focusCellNoEvent=function(e){this.recursionBlock=!0,"ie"!==this.table.browser&&e.getElement().focus(),this.recursionBlock=!1},Edit.prototype.editCell=function(e,t){this.focusCellNoEvent(e),this.edit(e,!1,t)},Edit.prototype.edit=function(e,t,i){function n(t){if(d.currentCell===e){var i=!0;e.column.modules.validate&&d.table.modExists("validate")&&(i=d.table.modules.validate.validate(e.column.modules.validate,e.getComponent(),t)),!0===i?(d.clearEditor(),e.setValue(t,!0),d.table.options.dataTree&&d.table.modExists("dataTree")&&d.table.modules.dataTree.checkForRestyle(e)):(d.invalidEdit=!0,m.classList.add("tabulator-validation-fail"),d.focusCellNoEvent(e),c(),d.table.options.validationFailed.call(d.table,e.getComponent(),t,i))}}function a(){d.currentCell===e&&(d.cancelEdit(),d.table.options.dataTree&&d.table.modExists("dataTree")&&d.table.modules.dataTree.checkForRestyle(e))}function o(e){c=e}var r,l,s,d=this,u=!0,c=function(){},m=e.getElement();if(this.currentCell)return void(this.invalidEdit||this.cancelEdit());if(e.column.modules.edit.blocked)return this.mouseClick=!1,m.blur(),!1;switch(t&&t.stopPropagation(),_typeof(e.column.modules.edit.check)){case"function":u=e.column.modules.edit.check(e.getComponent());break;case"boolean":u=e.column.modules.edit.check}if(u||i){if(d.cancelEdit(),d.currentCell=e,l=e.getComponent(),this.mouseClick&&(this.mouseClick=!1,e.column.cellEvents.cellClick&&e.column.cellEvents.cellClick.call(this.table,t,l)),e.column.cellEvents.cellEditing&&e.column.cellEvents.cellEditing.call(this.table,l),d.table.options.cellEditing.call(this.table,l),s="function"==typeof e.column.modules.edit.params?e.column.modules.edit.params(l):e.column.modules.edit.params,!1===(r=e.column.modules.edit.editor.call(d,l,o,n,a,s)))return m.blur(),!1;if(!(r instanceof Node))return console.warn("Edit Error - Editor should return an instance of Node, the editor returned:",r),m.blur(),!1;for(m.classList.add("tabulator-editing"),e.row.getElement().classList.add("tabulator-row-editing");m.firstChild;)m.removeChild(m.firstChild);m.appendChild(r),c();for(var v=m.children,f=0;f<v.length;f++)v[f].addEventListener("click",function(e){e.stopPropagation()});return!0}return this.mouseClick=!1,m.blur(),!1},Edit.prototype.editors={input:function(e,t,i,n,a){function o(e){(null===r||void 0===r)&&""!==l.value||l.value!=r?i(l.value):n()}var r=e.getValue(),l=document.createElement("input");return l.setAttribute("type",a.search?"search":"text"),l.style.padding="4px",l.style.width="100%",l.style.boxSizing="border-box",l.value=void 0!==r?r:"",t(function(){l.focus(),l.style.height="100%"}),l.addEventListener("change",o),l.addEventListener("blur",o),l.addEventListener("keydown",function(e){switch(e.keyCode){case 13:i(l.value);break;case 27:n()}}),l},textarea:function(e,t,i,n,a){function o(t){(null===r||void 0===r)&&""!==s.value||s.value!=r?(i(s.value),setTimeout(function(){e.getRow().normalizeHeight()},300)):n()}var r=e.getValue(),l=String(null!==r&&void 0!==r?r:""),s=(l.match(/(?:\r\n|\r|\n)/g),document.createElement("textarea")),d=0;return s.style.display="block",s.style.padding="2px",s.style.height="100%",s.style.width="100%",s.style.boxSizing="border-box",s.style.whiteSpace="pre-wrap",s.style.resize="none",s.value=l,t(function(){s.focus(),s.style.height="100%"}),s.addEventListener("change",o),s.addEventListener("blur",o),s.addEventListener("keyup",function(){s.style.height="";var t=s.scrollHeight;s.style.height=t+"px",t!=d&&(d=t,e.getRow().normalizeHeight())}),s.addEventListener("keydown",function(e){27==e.keyCode&&n()}),s},number:function(e,t,i,n,a){function o(){var e=l.value;isNaN(e)||""===e||(e=Number(e)),e!=r?i(e):n()}var r=e.getValue(),l=document.createElement("input");l.setAttribute("type","number"),void 0!==a.max&&l.setAttribute("max",a.max),void 0!==a.min&&l.setAttribute("min",a.min),void 0!==a.step&&l.setAttribute("step",a.step),l.style.padding="4px",l.style.width="100%",l.style.boxSizing="border-box",l.value=r;var s=function(e){o()};return t(function(){l.removeEventListener("blur",s),l.focus(),l.style.height="100%",l.addEventListener("blur",s)}),l.addEventListener("keydown",function(e){switch(e.keyCode){case 13:case 9:o();break;case 27:n()}}),l},range:function(e,t,i,n,a){function o(){var e=l.value;isNaN(e)||""===e||(e=Number(e)),e!=r?i(e):n()}var r=e.getValue(),l=document.createElement("input");return l.setAttribute("type","range"),void 0!==a.max&&l.setAttribute("max",a.max),void 0!==a.min&&l.setAttribute("min",a.min),void 0!==a.step&&l.setAttribute("step",a.step),l.style.padding="4px",l.style.width="100%",l.style.boxSizing="border-box",l.value=r,t(function(){l.focus(),l.style.height="100%"}),l.addEventListener("blur",function(e){o()}),l.addEventListener("keydown",function(e){switch(e.keyCode){case 13:case 9:o();break;case 27:n()}}),l},select:function(e,t,i,n,a){function o(){var t={},i=e.getColumn()._getSelf();return f.table.getData().forEach(function(e){var n=i.getFieldValue(e);null!==n&&void 0!==n&&""!==n&&(t[n]=!0)}),t=a.sortValuesList?"asc"==a.sortValuesList?Object.keys(t).sort():Object.keys(t).sort().reverse():Object.keys(t)}function r(t,i){function n(e){var e={label:a.listItemFormatter?a.listItemFormatter(e.value,e.label):e.label,value:e.value,element:!1};return e.value!==i&&(isNaN(parseFloat(e.value))||isNaN(parseFloat(e.value))||parseFloat(e.value)!==parseFloat(i))||s(e),o.push(e),r.push(e),e}var o=[],r=[];if("function"==typeof t&&(t=t(e)),Array.isArray(t))t.forEach(function(e){var t;"object"===(void 0===e?"undefined":_typeof(e))?e.options?(t={label:e.label,group:!0,element:!1},r.push(t),e.options.forEach(function(e){n(e)})):n(e):(t={label:a.listItemFormatter?a.listItemFormatter(e,e):e,value:e,element:!1},t.value!==i&&(isNaN(parseFloat(t.value))||isNaN(parseFloat(t.value))||parseFloat(t.value)!==parseFloat(i))||s(t),o.push(t),r.push(t))});else for(var d in t){var u={label:a.listItemFormatter?a.listItemFormatter(d,t[d]):t[d],value:d,element:!1};u.value!==i&&(isNaN(parseFloat(u.value))||isNaN(parseFloat(u.value))||parseFloat(u.value)!==parseFloat(i))||s(u),o.push(u),r.push(u)}E=o,g=r,l()}function l(){for(;y.firstChild;)y.removeChild(y.firstChild);g.forEach(function(e){var t=e.element;t||(e.group?(t=document.createElement("div"),t.classList.add("tabulator-edit-select-list-group"),t.tabIndex=0,t.innerHTML=""===e.label?" ":e.label):(t=document.createElement("div"),t.classList.add("tabulator-edit-select-list-item"),t.tabIndex=0,t.innerHTML=""===e.label?" ":e.label,t.addEventListener("click",function(){s(e),d()}),e===k&&t.classList.add("active")),t.addEventListener("mousedown",function(){C=!1,setTimeout(function(){C=!0},10)}),e.element=t),y.appendChild(t)})}function s(e){k&&k.element&&k.element.classList.remove("active"),k=e,b.value=" "===e.label?"":e.label,e.element&&e.element.classList.add("active")}function d(){m(),h!==k.value?(h=k.value,i(k.value)):n()}function u(){m(),n()}function c(){if(!y.parentNode){!0===a.values?r(o(),h):r(a.values||[],h);var e=Tabulator.prototype.helpers.elOffset(p);y.style.minWidth=p.offsetWidth+"px",y.style.top=e.top+p.offsetHeight+"px",y.style.left=e.left+"px",document.body.appendChild(y)}}function m(){y.parentNode&&y.parentNode.removeChild(y),v()}function v(){f.table.rowManager.element.removeEventListener("scroll",u)}var f=this,p=e.getElement(),h=e.getValue(),b=document.createElement("input"),y=document.createElement("div"),E=[],g=[],k={},C=!0;return this.table.rowManager.element.addEventListener("scroll",u),(Array.isArray(a)||!Array.isArray(a)&&"object"===(void 0===a?"undefined":_typeof(a))&&!a.values)&&(console.warn("DEPRECATION WANRING - values for the select editor must now be passed into the values property of the editorParams object, not as the editorParams object"),a={values:a}),b.setAttribute("type","text"),b.style.padding="4px",b.style.width="100%",b.style.boxSizing="border-box",b.style.cursor="default",b.readOnly=0!=this.currentCell,b.value=void 0!==h||null===h?h:"",!0===a.values?r(o(),h):r(a.values||[],h),b.addEventListener("keydown",function(e){var t;switch(e.keyCode){case 38:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault(),t=E.indexOf(k),t>0&&s(E[t-1]);break;case 40:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault(),t=E.indexOf(k),t<E.length-1&&s(-1==t?E[0]:E[t+1]);break;case 37:case 39:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault();break;case 13:d();break;case 27:u()}}),b.addEventListener("blur",function(e){C&&u()}),b.addEventListener("focus",function(e){c()}),y=document.createElement("div"),y.classList.add("tabulator-edit-select-list"),t(function(){b.style.height="100%",b.focus()}),b},autocomplete:function(e,t,i,n,a){function o(){var t={},i=e.getColumn()._getSelf();return p.table.getData().forEach(function(e){var n=i.getFieldValue(e);null!==n&&void 0!==n&&""!==n&&(t[n]=!0)}),t=a.sortValuesList?"asc"==a.sortValuesList?Object.keys(t).sort():Object.keys(t).sort().reverse():Object.keys(t)}function r(e,t){var i=[];if(Array.isArray(e))e.forEach(function(e){var n={title:a.listItemFormatter?a.listItemFormatter(e,e):e,value:e,element:!1};n.value!==t&&(isNaN(parseFloat(n.value))||isNaN(parseFloat(n.value))||parseFloat(n.value)!==parseFloat(t))||d(n),i.push(n)});else for(var n in e){var o={title:a.listItemFormatter?a.listItemFormatter(n,e[n]):e[n],value:n,element:!1};o.value!==t&&(isNaN(parseFloat(o.value))||isNaN(parseFloat(o.value))||parseFloat(o.value)!==parseFloat(t))||d(o),i.push(o)}a.searchFunc&&i.forEach(function(e){e.search={title:e.title,value:e.value}}),g=i}function l(e,t){var i=[],n=[],o=[];a.searchFunc?(g.forEach(function(e){n.push(e.search)}),o=a.searchFunc(e,n),o.forEach(function(e){var t=g.find(function(t){return t.search===e});t&&i.push(t)})):""===e?a.showListOnEmpty&&g.forEach(function(e){i.push(e)}):g.forEach(function(t){null===t.value&&void 0===t.value||(String(t.value).toLowerCase().indexOf(String(e).toLowerCase())>-1||String(t.title).toLowerCase().indexOf(String(e).toLowerCase())>-1)&&i.push(t)}),k=i,s(t)}function s(e){for(var t=!1;E.firstChild;)E.removeChild(E.firstChild);k.forEach(function(i){var n=i.element;n||(n=document.createElement("div"),n.classList.add("tabulator-edit-select-list-item"),n.tabIndex=0,n.innerHTML=i.title,n.addEventListener("click",function(){d(i),u()}),n.addEventListener("mousedown",function(){w=!1,setTimeout(function(){w=!0},10)}),i.element=n,e&&i.value==b&&(y.value=i.title,i.element.classList.add("active"),t=!0),i===L&&(i.element.classList.add("active"),t=!0)),E.appendChild(n)}),t||d(!1)}function d(e,t){L&&L.element&&L.element.classList.remove("active"),L=e,e&&e.element&&e.element.classList.add("active")}function u(){v(),L?b!==L.value?(b=L.value,y.value=L.title,i(L.value)):n():a.freetext?(b=y.value,i(y.value)):a.allowEmpty&&""===y.value?(b=y.value,i(y.value)):n()}function c(){v(),n()}function m(){if(!E.parentNode){for(;E.firstChild;)E.removeChild(E.firstChild);C=!0===a.values?o():a.values||[],r(C,b);var e=Tabulator.prototype.helpers.elOffset(h);E.style.minWidth=h.offsetWidth+"px",E.style.top=e.top+h.offsetHeight+"px",E.style.left=e.left+"px",document.body.appendChild(E)}}function v(){E.parentNode&&E.parentNode.removeChild(E),f()}function f(){p.table.rowManager.element.removeEventListener("scroll",c)}var p=this,h=e.getElement(),b=e.getValue(),y=document.createElement("input"),E=document.createElement("div"),g=[],k=[],C=[],L={},w=!0;return this.table.rowManager.element.addEventListener("scroll",c),y.setAttribute("type","search"),y.style.padding="4px",y.style.width="100%",y.style.boxSizing="border-box",y.addEventListener("keydown",function(e){var t;switch(e.keyCode){case 38:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault(),t=k.indexOf(L),d(t>0?k[t-1]:!1);break;case 40:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault(),t=k.indexOf(L),t<k.length-1&&d(-1==t?k[0]:k[t+1]);break;case 37:case 39:e.stopImmediatePropagation(),e.stopPropagation(),e.preventDefault();break;case 13:u();break;case 27:c();break;case 36:case 35:e.stopImmediatePropagation()}}),y.addEventListener("keyup",function(e){switch(e.keyCode){case 38:case 37:case 39:case 40:case 13:case 27:break;default:l(y.value)}}),y.addEventListener("search",function(e){l(y.value)}),y.addEventListener("blur",function(e){w&&u()}),y.addEventListener("focus",function(e){var t=void 0!==b||null===b?b:"";m(),y.value=t,l(t,!0)}),E=document.createElement("div"),E.classList.add("tabulator-edit-select-list"),t(function(){y.style.height="100%",y.focus()}),y},star:function(e,t,i,n,a){function o(e){m.forEach(function(t,i){i<e?("ie"==l.table.browser?t.setAttribute("class","tabulator-star-active"):t.classList.replace("tabulator-star-inactive","tabulator-star-active"),t.innerHTML='<polygon fill="#488CE9" stroke="#014AAE" 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 "/>'):("ie"==l.table.browser?t.setAttribute("class","tabulator-star-inactive"):t.classList.replace("tabulator-star-active","tabulator-star-inactive"),t.innerHTML='<polygon fill="#010155" 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 "/>')})}function r(e){d=e,o(e)}var l=this,s=e.getElement(),d=e.getValue(),u=s.getElementsByTagName("svg").length||5,c=s.getElementsByTagName("svg")[0]?s.getElementsByTagName("svg")[0].getAttribute("width"):14,m=[],v=document.createElement("div"),f=document.createElementNS("http://www.w3.org/2000/svg","svg");s.style.whiteSpace="nowrap",s.style.overflow="hidden",s.style.textOverflow="ellipsis",v.style.verticalAlign="middle",v.style.display="inline-block",v.style.padding="4px",f.setAttribute("width",c),f.setAttribute("height",c),f.setAttribute("viewBox","0 0 512 512"),f.setAttribute("xml:space","preserve"),f.style.padding="0 1px";for(var p=1;p<=u;p++)!function(e){var t=document.createElement("span"),n=f.cloneNode(!0);m.push(n),t.addEventListener("mouseenter",function(t){t.stopPropagation(),t.stopImmediatePropagation(),o(e)}),t.addEventListener("mousemove",function(e){e.stopPropagation(),e.stopImmediatePropagation()}),t.addEventListener("click",function(t){t.stopPropagation(),t.stopImmediatePropagation(),i(e)}),t.appendChild(n),v.appendChild(t)}(p);return d=Math.min(parseInt(d),u),o(d),v.addEventListener("mousemove",function(e){o(0)}),v.addEventListener("click",function(e){i(0)}),s.addEventListener("blur",function(e){n()}),s.addEventListener("keydown",function(e){switch(e.keyCode){case 39:r(d+1);break;case 37:r(d-1);break;case 13:i(d);break;case 27:n()}}),v},progress:function(e,t,i,n,a){function o(){var e=c*Math.round(f.offsetWidth/(s.clientWidth/100))+u;i(e),s.setAttribute("aria-valuenow",e),s.setAttribute("aria-label",m)}var r,l,s=e.getElement(),d=void 0===a.max?s.getElementsByTagName("div")[0].getAttribute("max")||100:a.max,u=void 0===a.min?s.getElementsByTagName("div")[0].getAttribute("min")||0:a.min,c=(d-u)/100,m=e.getValue()||0,v=document.createElement("div"),f=document.createElement("div");return v.style.position="absolute",v.style.right="0",v.style.top="0",v.style.bottom="0",v.style.width="5px",v.classList.add("tabulator-progress-handle"),f.style.display="inline-block",f.style.position="relative",f.style.height="100%",f.style.backgroundColor="#488CE9",f.style.maxWidth="100%",f.style.minWidth="0%",s.style.padding="4px 4px",m=Math.min(parseFloat(m),d),m=Math.max(parseFloat(m),u),m=Math.round((m-u)/c),f.style.width=m+"%",s.setAttribute("aria-valuemin",u),s.setAttribute("aria-valuemax",d),f.appendChild(v),v.addEventListener("mousedown",function(e){r=e.screenX,l=f.offsetWidth}),v.addEventListener("mouseover",function(){v.style.cursor="ew-resize"}),s.addEventListener("mousemove",function(e){r&&(f.style.width=l+e.screenX-r+"px")}),s.addEventListener("mouseup",function(e){r&&(e.stopPropagation(),e.stopImmediatePropagation(),r=!1,l=!1,o())}),s.addEventListener("keydown",function(e){switch(e.keyCode){case 39:f.style.width=f.clientWidth+s.clientWidth/100+"px";break;case 37:f.style.width=f.clientWidth-s.clientWidth/100+"px";break;case 13:o();break;case 27:n()}}),s.addEventListener("blur",function(){n()}),f},tickCross:function(e,t,i,n,a){function o(e){return s?e?u?d:l.checked:l.checked&&!u?(l.checked=!1,l.indeterminate=!0,u=!0,d):(u=!1,l.checked):l.checked}var r=e.getValue(),l=document.createElement("input"),s=a.tristate,d=void 0===a.indeterminateValue?null:a.indeterminateValue,u=!1;return l.setAttribute("type","checkbox"),l.style.marginTop="5px",l.style.boxSizing="border-box",l.value=r,!s||void 0!==r&&r!==d&&""!==r||(u=!0,l.indeterminate=!0),"firefox"!=this.table.browser&&t(function(){l.focus()}),l.checked=!0===r||"true"===r||"True"===r||1===r,l.addEventListener("change",function(e){i(o())}),l.addEventListener("blur",function(e){i(o(!0))}),l.addEventListener("keydown",function(e){13==e.keyCode&&i(o()),27==e.keyCode&&n()}),l}},Tabulator.prototype.registerModule("edit",Edit);