From aece6ca5987e787b3f99279ea002698bf35a0481 Mon Sep 17 00:00:00 2001 From: Travis Clarke Date: Thu, 1 Jun 2017 16:37:02 -0700 Subject: [PATCH] v5.0.0-rc.3 - fix handle{Row,Col}Span ordering and terminating conditions --- .gitignore | 2 +- README.md | 5 ++- bower.json | 2 +- dist/css/tableexport.css | 2 +- dist/css/tableexport.min.css | 2 +- dist/js/tableexport.js | 54 ++++++++++++++++++------------ dist/js/tableexport.min.js | 4 +-- dist/tableexport.d.ts | 4 +-- docs/README.md | 5 ++- gitbook | 2 +- package.json | 2 +- src/stable/css/tableexport.css | 2 +- src/stable/css/tableexport.min.css | 2 +- src/stable/js/tableexport.js | 54 ++++++++++++++++++------------ src/stable/js/tableexport.min.js | 4 +-- 15 files changed, 88 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index d93f71e..409e41c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ /assets /index.html /search -/test +test /module /docs/_book rollup.config.js diff --git a/README.md b/README.md index e842a61..1fba665 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# [TableExport](https://tableexport.v4.travismclarke.com)   [![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport) +[![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport) + +# [TableExport](https://tableexport.v4.travismclarke.com) The simple, easy-to-implement library to export HTML tables to `xlsx`, `xls`, `csv`, and `txt` files. ## Docs @@ -328,6 +330,7 @@ When used alongside Bootstrap, there are four custom classes **`.xlsx`, `.xls`, - [x] Reimplement and test the `update`, `reset`, and `remove` **TableExport** prototype properties without requiring jQuery. - [x] Make jQuery as *peer dependency* and ensure proper **TableExport** rendering in browser, AMD, and CommonJS environments. - [x] Force jQuery to be an optionally loaded module. +- [ ] Use the enhanced [SheetJS](https://github.com/SheetJS/js-xlsx#supported-output-formats) `csv` and `txt` formats when the library is available. - [ ] Allow `ignoreCSS` and `emptyCSS` to work with any `selector|selector[]` instead of solely a single CSS class. - [ ] Ensure (via testing) full consistency and backwards-compatibility for jQuery. - [ ] Add **Export as PDF** support. diff --git a/bower.json b/bower.json index e900c68..ca0d340 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tableexport.js", - "version": "5.0.0-rc.2", + "version": "5.0.0-rc.3", "authors": [ "clarketm " ], diff --git a/dist/css/tableexport.css b/dist/css/tableexport.css index bde2791..6638a37 100644 --- a/dist/css/tableexport.css +++ b/dist/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * diff --git a/dist/css/tableexport.min.css b/dist/css/tableexport.min.css index b8c3d4b..fcfcad9 100644 --- a/dist/css/tableexport.min.css +++ b/dist/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index fca9867..a8251d7 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * @@ -106,7 +106,7 @@ }; })(); - context.rcMap = new RowColMap().build.call(self, context); + context.rcMap = new RowColMap().build(context, settings); var formatMap = {}; for (var type in _FORMAT) { @@ -142,7 +142,7 @@ * Version. * @memberof TableExport.prototype */ - version: '5.0.0-rc.2', + version: '5.0.0-rc.3', /** * Default library options. * @memberof TableExport.prototype @@ -811,13 +811,15 @@ }; this.getRowColMapProp = function (ir, ic, key) { if (this.rcMap[ir]) { - if (typeof ic === 'undefined') { + if (typeof key === 'undefined') { + return this.rcMap[ir][ic]; + } else if (typeof ic === 'undefined') { return this.rcMap[ir][key]; } else if (this.rcMap[ir][ic]) { return this.rcMap[ir][ic][key]; } } - return false; + return undefined; }; this.setRowColMapProp = function (ir, ic, key, value) { this.rcMap[ir] = this.rcMap[ir] || []; @@ -880,38 +882,48 @@ SPAN: 'span', DEFAULT: 'default' }, - build: function (context) { + build: function (context, settings) { var self = this; - var settings = self.settings; - var OFFSET = 1; - - var _RowColMap = new RowColMap(); + var OFFSET = self.OFFSET; + var rowLength = self.rowLength = context.rows.length; + // var colLength = self.colLength = Math.max.apply(null, + // _nodesArray(context.rows).map(function (val) { + // return val.querySelectorAll('th, td').length + // })); var handleIgnoreRow = function (ir) { - _RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.IGNORE, true); - + self.setRowColMapProp(ir, undefined, self.TYPE.IGNORE, true); }; var handleIgnoreCol = function (ir, ic) { - _RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.IGNORE, true); + self.setRowColMapProp(ir, ic, self.TYPE.IGNORE, true); }; var handleEmpty = function (ir, ic) { - _RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.EMPTY, true); + self.setRowColMapProp(ir, ic, self.TYPE.EMPTY, true); }; var handleRowSpan = function (val, ir, ic) { var rowSpan = val.getAttribute('rowspan'); var hasColSpan = val.hasAttribute('colspan'); - hasColSpan && handleColSpan(val, ir, ic); - for (var _row = 1; _row < rowSpan; _row++) { - _RowColMap.setRowColMapProp(_row + ir, undefined, _RowColMap.TYPE.SPAN, true); - _RowColMap.setRowColMapProp(_row + ir, ic, undefined, 1); + + for (var _row = 0; _row < rowSpan; _row++) { + if (_row + ir >= rowLength) { + return; + } hasColSpan && handleColSpan(val, _row + ir, ic); + if (_row >= 1) { + self.setRowColMapProp(_row + ir, undefined, self.TYPE.SPAN, true); + self.setRowColMapProp(_row + ir, ic, undefined, 1); + } } }; var handleColSpan = function (val, ir, ic) { var colSpan = val.getAttribute('colspan'); - _RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.SPAN, true); - _RowColMap.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET); + + if (colSpan <= 1) { + return; + } + self.setRowColMapProp(ir, undefined, self.TYPE.SPAN, true); + self.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET); }; _nodesArray(context.rows).map(function (val, ir) { @@ -934,7 +946,7 @@ }); }); - return _RowColMap; + return self; } }; diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 178de42..665336c 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,e){if("function"==typeof define&&define.amd)define(function(t){var r;try{r=t("jquery")}catch(o){}return e(r,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var r;try{r=require("jquery")}catch(o){}module.exports=e(r,require("blobjs"),require("file-saverjs"),require("xlsx"))}else t.TableExport=e(t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(t,e,r,o){"use strict";function n(){for(var t=arguments,e=1;e tr")),e.rows=i.headers?a(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=i.footers?e.rows.concat(a(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=i.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===i.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:i.filename?i.filename:r.defaultFilename,e.uuid=g(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=i.bootstrapSettings.bootstrapSpacing+i.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);s[e.uuid]=s[e.uuid]||{},s[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build.call(r,e);var n={};for(var p in h)n[h[p]]=0;i.formats.forEach(function(t){!(!o||v||t!==h.XLS)&&(t=h.BIFF2),!(o&&!v||t!==h.XLSX)&&(t=h.XLS),n[t]||(e.setExportData(r.exporters[t].call(r,e)),n[t]++)})});var p=document.querySelectorAll("button[tableexport-id]");return b(p,"click",r.downloadHandler,r),r};c.prototype={version:"5.0.0-rc.2",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLSX],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLSX});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},biff2:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},xls:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},csv:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.CSV],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a='"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"';return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.CSV});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},txt:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.TXT],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.TXT});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("tableexport-id",t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return c.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=c.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?m.STRING:~t.indexOf(e.number.defaultClass)?m.NUMBER:~t.indexOf(e["boolean"].defaultClass)?m.BOOLEAN:~t.indexOf(e.date.defaultClass)?m.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=c.prototype.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){r.s.r>a&&(r.s.r=a),r.s.c>i&&(r.s.c=i),r.e.r=e?a+p:a:i++,i!==n);u++);return"undefined"!=typeof o?new Array(a).concat(r).join(o):new Array(a).concat(r)}return r},this.handleRowColMapProp=function(t,e,r,o,n){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t){var e=this,r=e.settings,o=1,n=new d,s=function(t){n.setRowColMapProp(t,void 0,n.TYPE.IGNORE,!0)},p=function(t,e){n.setRowColMapProp(t,e,n.TYPE.IGNORE,!0)},l=function(t,e){n.setRowColMapProp(t,e,n.TYPE.EMPTY,!0)},u=function(t,e,r){var o=t.getAttribute("rowspan"),a=t.hasAttribute("colspan");a&&c(t,e,r);for(var i=1;i tr")),e.rows=i.headers?a(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=i.footers?e.rows.concat(a(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=i.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===i.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:i.filename?i.filename:r.defaultFilename,e.uuid=g(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=i.bootstrapSettings.bootstrapSpacing+i.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);s[e.uuid]=s[e.uuid]||{},s[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build(e,i);var n={};for(var p in h)n[h[p]]=0;i.formats.forEach(function(t){!(!o||v||t!==h.XLS)&&(t=h.BIFF2),!(o&&!v||t!==h.XLSX)&&(t=h.XLS),n[t]||(e.setExportData(r.exporters[t].call(r,e)),n[t]++)})});var p=document.querySelectorAll("button[tableexport-id]");return b(p,"click",r.downloadHandler,r),r};c.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLSX],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLSX});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},biff2:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},xls:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},csv:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.CSV],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a='"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"';return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.CSV});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},txt:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.TXT],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.TXT});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("tableexport-id",t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return c.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=c.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?m.STRING:~t.indexOf(e.number.defaultClass)?m.NUMBER:~t.indexOf(e["boolean"].defaultClass)?m.BOOLEAN:~t.indexOf(e.date.defaultClass)?m.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=c.prototype.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){r.s.r>a&&(r.s.r=a),r.s.c>i&&(r.s.c=i),r.e.r=e?a+p:a:i++,i!==n);u++);return"undefined"!=typeof o?new Array(a).concat(r).join(o):new Array(a).concat(r)}return r},this.handleRowColMapProp=function(t,e,r,o,n){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,o=r.OFFSET,n=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},p=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},l=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},u=function(t,e,o){for(var a=t.getAttribute("rowspan"),i=t.hasAttribute("colspan"),s=0;s=n)return;i&&c(t,s+e,o),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,o,void 0,1))}},c=function(t,e,n){var a=t.getAttribute("colspan");a<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,n+o,void 0,a-o))};return a(t.rows).map(function(r,o){(~e.ignoreRows.indexOf(o-t.thAdj)||i(r,e.ignoreCSS))&&s(o);var n=r.querySelectorAll("th, td");return a(n).map(function(t,r){(~e.ignoreCols.indexOf(r)||i(t,e.ignoreCSS))&&p(o,r),i(t,e.emptyCSS)&&l(o,r),t.hasAttribute("rowspan")?u(t,o,r):t.hasAttribute("colspan")&&c(t,o,r)})}),r}};var m=function(){return c.prototype.CONSTANTS.TYPE}(),h=function(){return c.prototype.CONSTANTS.FORMAT}(),g=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),y=function(){var t,e,r=0;return function(o){var n=o.type;if(o=JSON.stringify(o),0===o.length)return r;for(t=0;t /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * diff --git a/docs/README.md b/docs/README.md index e842a61..1fba665 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,6 @@ -# [TableExport](https://tableexport.v4.travismclarke.com)   [![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport) +[![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport) + +# [TableExport](https://tableexport.v4.travismclarke.com) The simple, easy-to-implement library to export HTML tables to `xlsx`, `xls`, `csv`, and `txt` files. ## Docs @@ -328,6 +330,7 @@ When used alongside Bootstrap, there are four custom classes **`.xlsx`, `.xls`, - [x] Reimplement and test the `update`, `reset`, and `remove` **TableExport** prototype properties without requiring jQuery. - [x] Make jQuery as *peer dependency* and ensure proper **TableExport** rendering in browser, AMD, and CommonJS environments. - [x] Force jQuery to be an optionally loaded module. +- [ ] Use the enhanced [SheetJS](https://github.com/SheetJS/js-xlsx#supported-output-formats) `csv` and `txt` formats when the library is available. - [ ] Allow `ignoreCSS` and `emptyCSS` to work with any `selector|selector[]` instead of solely a single CSS class. - [ ] Ensure (via testing) full consistency and backwards-compatibility for jQuery. - [ ] Add **Export as PDF** support. diff --git a/gitbook b/gitbook index 08c78f8..783ac86 160000 --- a/gitbook +++ b/gitbook @@ -1 +1 @@ -Subproject commit 08c78f85b0bfb76048ac6db1847885db1db221f0 +Subproject commit 783ac86149e0038820df6fd725b81a3cc605af1d diff --git a/package.json b/package.json index e2ffe06..24d7fda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tableexport", - "version": "5.0.0-rc.2", + "version": "5.0.0-rc.3", "authors": [ "clarketm " ], diff --git a/src/stable/css/tableexport.css b/src/stable/css/tableexport.css index bde2791..6638a37 100644 --- a/src/stable/css/tableexport.css +++ b/src/stable/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * diff --git a/src/stable/css/tableexport.min.css b/src/stable/css/tableexport.min.css index b8c3d4b..fcfcad9 100644 --- a/src/stable/css/tableexport.min.css +++ b/src/stable/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index fca9867..a8251d7 100644 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * @@ -106,7 +106,7 @@ }; })(); - context.rcMap = new RowColMap().build.call(self, context); + context.rcMap = new RowColMap().build(context, settings); var formatMap = {}; for (var type in _FORMAT) { @@ -142,7 +142,7 @@ * Version. * @memberof TableExport.prototype */ - version: '5.0.0-rc.2', + version: '5.0.0-rc.3', /** * Default library options. * @memberof TableExport.prototype @@ -811,13 +811,15 @@ }; this.getRowColMapProp = function (ir, ic, key) { if (this.rcMap[ir]) { - if (typeof ic === 'undefined') { + if (typeof key === 'undefined') { + return this.rcMap[ir][ic]; + } else if (typeof ic === 'undefined') { return this.rcMap[ir][key]; } else if (this.rcMap[ir][ic]) { return this.rcMap[ir][ic][key]; } } - return false; + return undefined; }; this.setRowColMapProp = function (ir, ic, key, value) { this.rcMap[ir] = this.rcMap[ir] || []; @@ -880,38 +882,48 @@ SPAN: 'span', DEFAULT: 'default' }, - build: function (context) { + build: function (context, settings) { var self = this; - var settings = self.settings; - var OFFSET = 1; - - var _RowColMap = new RowColMap(); + var OFFSET = self.OFFSET; + var rowLength = self.rowLength = context.rows.length; + // var colLength = self.colLength = Math.max.apply(null, + // _nodesArray(context.rows).map(function (val) { + // return val.querySelectorAll('th, td').length + // })); var handleIgnoreRow = function (ir) { - _RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.IGNORE, true); - + self.setRowColMapProp(ir, undefined, self.TYPE.IGNORE, true); }; var handleIgnoreCol = function (ir, ic) { - _RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.IGNORE, true); + self.setRowColMapProp(ir, ic, self.TYPE.IGNORE, true); }; var handleEmpty = function (ir, ic) { - _RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.EMPTY, true); + self.setRowColMapProp(ir, ic, self.TYPE.EMPTY, true); }; var handleRowSpan = function (val, ir, ic) { var rowSpan = val.getAttribute('rowspan'); var hasColSpan = val.hasAttribute('colspan'); - hasColSpan && handleColSpan(val, ir, ic); - for (var _row = 1; _row < rowSpan; _row++) { - _RowColMap.setRowColMapProp(_row + ir, undefined, _RowColMap.TYPE.SPAN, true); - _RowColMap.setRowColMapProp(_row + ir, ic, undefined, 1); + + for (var _row = 0; _row < rowSpan; _row++) { + if (_row + ir >= rowLength) { + return; + } hasColSpan && handleColSpan(val, _row + ir, ic); + if (_row >= 1) { + self.setRowColMapProp(_row + ir, undefined, self.TYPE.SPAN, true); + self.setRowColMapProp(_row + ir, ic, undefined, 1); + } } }; var handleColSpan = function (val, ir, ic) { var colSpan = val.getAttribute('colspan'); - _RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.SPAN, true); - _RowColMap.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET); + + if (colSpan <= 1) { + return; + } + self.setRowColMapProp(ir, undefined, self.TYPE.SPAN, true); + self.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET); }; _nodesArray(context.rows).map(function (val, ir) { @@ -934,7 +946,7 @@ }); }); - return _RowColMap; + return self; } }; diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 178de42..665336c 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com) + * TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com) * * Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com * @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,e){if("function"==typeof define&&define.amd)define(function(t){var r;try{r=t("jquery")}catch(o){}return e(r,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var r;try{r=require("jquery")}catch(o){}module.exports=e(r,require("blobjs"),require("file-saverjs"),require("xlsx"))}else t.TableExport=e(t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(t,e,r,o){"use strict";function n(){for(var t=arguments,e=1;e tr")),e.rows=i.headers?a(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=i.footers?e.rows.concat(a(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=i.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===i.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:i.filename?i.filename:r.defaultFilename,e.uuid=g(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=i.bootstrapSettings.bootstrapSpacing+i.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);s[e.uuid]=s[e.uuid]||{},s[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build.call(r,e);var n={};for(var p in h)n[h[p]]=0;i.formats.forEach(function(t){!(!o||v||t!==h.XLS)&&(t=h.BIFF2),!(o&&!v||t!==h.XLSX)&&(t=h.XLS),n[t]||(e.setExportData(r.exporters[t].call(r,e)),n[t]++)})});var p=document.querySelectorAll("button[tableexport-id]");return b(p,"click",r.downloadHandler,r),r};c.prototype={version:"5.0.0-rc.2",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLSX],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLSX});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},biff2:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},xls:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},csv:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.CSV],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a='"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"';return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.CSV});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},txt:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.TXT],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.TXT});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("tableexport-id",t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return c.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=c.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?m.STRING:~t.indexOf(e.number.defaultClass)?m.NUMBER:~t.indexOf(e["boolean"].defaultClass)?m.BOOLEAN:~t.indexOf(e.date.defaultClass)?m.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=c.prototype.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){r.s.r>a&&(r.s.r=a),r.s.c>i&&(r.s.c=i),r.e.r=e?a+p:a:i++,i!==n);u++);return"undefined"!=typeof o?new Array(a).concat(r).join(o):new Array(a).concat(r)}return r},this.handleRowColMapProp=function(t,e,r,o,n){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t){var e=this,r=e.settings,o=1,n=new d,s=function(t){n.setRowColMapProp(t,void 0,n.TYPE.IGNORE,!0)},p=function(t,e){n.setRowColMapProp(t,e,n.TYPE.IGNORE,!0)},l=function(t,e){n.setRowColMapProp(t,e,n.TYPE.EMPTY,!0)},u=function(t,e,r){var o=t.getAttribute("rowspan"),a=t.hasAttribute("colspan");a&&c(t,e,r);for(var i=1;i tr")),e.rows=i.headers?a(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=i.footers?e.rows.concat(a(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=i.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===i.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:i.filename?i.filename:r.defaultFilename,e.uuid=g(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=i.bootstrapSettings.bootstrapSpacing+i.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);s[e.uuid]=s[e.uuid]||{},s[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build(e,i);var n={};for(var p in h)n[h[p]]=0;i.formats.forEach(function(t){!(!o||v||t!==h.XLS)&&(t=h.BIFF2),!(o&&!v||t!==h.XLSX)&&(t=h.XLS),n[t]||(e.setExportData(r.exporters[t].call(r,e)),n[t]++)})});var p=document.querySelectorAll("button[tableexport-id]");return b(p,"click",r.downloadHandler,r),r};c.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"}},typeConfig:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLSX],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLSX});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},biff2:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=t.rcMap,i=a(t.rows).map(function(t,o){if(n.isIgnore(o))return n.handleRowColMapProp(n.TYPE.IGNORE);var i=t.querySelectorAll("th, td");return a(i).map(function(t,a){var i={v:r.formatValue(t.textContent),t:e.getType(t.className)};return n.isIgnore(o,a)?n.handleRowColMapProp(n.TYPE.IGNORE):n.isEmpty(o,a)?n.handleRowColMapProp(n.TYPE.EMPTY):n.handleRowColMapProp(n.TYPE.DEFAULT,o,a,i)}).filter(p)}).map(l).filter(p),s=JSON.stringify({data:i,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,s,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,s,!0)},xls:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.XLS],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.XLS});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},csv:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.CSV],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a='"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"';return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.CSV});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)},txt:function(t){var e=this,r=e.settings,o=c.prototype.formatConfig[h.TXT],n=o.separator,i=t.rcMap,s=a(t.rows).map(function(t,e){if(i.isIgnore(e))return i.handleRowColMapProp(i.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return a(o).map(function(t,o){var a=r.formatValue(t.textContent);return i.isIgnore(e,o)?i.handleRowColMapProp(i.TYPE.IGNORE):i.isEmpty(e,o)?i.handleRowColMapProp(i.TYPE.EMPTY):i.handleRowColMapProp(i.TYPE.DEFAULT,e,o,a,n)}).filter(p).join(n)}).filter(p).join(e.rowDel),l=JSON.stringify({data:s,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),u=y({uuid:t.uuid,type:h.TXT});return r.exportButtons&&t.checkCaption(c.prototype.createObjButton(u,l,o.buttonContent,o.defaultClass,r.bootstrapSettings)),f.getInstance().setItem(u,l,!0)}},createObjButton:function(t,e,r,o,n){var a=document.createElement("button");return a.setAttribute("tableexport-id",t),a.className=n.bootstrapClass+n.bootstrapTheme+o,a.textContent=r,a},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return c.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=c.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?m.STRING:~t.indexOf(e.number.defaultClass)?m.NUMBER:~t.indexOf(e["boolean"].defaultClass)?m.BOOLEAN:~t.indexOf(e.date.defaultClass)?m.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=c.prototype.typeConfig,a=0;a!==t.length;++a)for(var i=0;i!==t[a].length;++i){r.s.r>a&&(r.s.r=a),r.s.c>i&&(r.s.c=i),r.e.r=e?a+p:a:i++,i!==n);u++);return"undefined"!=typeof o?new Array(a).concat(r).join(o):new Array(a).concat(r)}return r},this.handleRowColMapProp=function(t,e,r,o,n){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,o=r.OFFSET,n=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},p=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},l=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},u=function(t,e,o){for(var a=t.getAttribute("rowspan"),i=t.hasAttribute("colspan"),s=0;s=n)return;i&&c(t,s+e,o),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,o,void 0,1))}},c=function(t,e,n){var a=t.getAttribute("colspan");a<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,n+o,void 0,a-o))};return a(t.rows).map(function(r,o){(~e.ignoreRows.indexOf(o-t.thAdj)||i(r,e.ignoreCSS))&&s(o);var n=r.querySelectorAll("th, td");return a(n).map(function(t,r){(~e.ignoreCols.indexOf(r)||i(t,e.ignoreCSS))&&p(o,r),i(t,e.emptyCSS)&&l(o,r),t.hasAttribute("rowspan")?u(t,o,r):t.hasAttribute("colspan")&&c(t,o,r)})}),r}};var m=function(){return c.prototype.CONSTANTS.TYPE}(),h=function(){return c.prototype.CONSTANTS.FORMAT}(),g=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),y=function(){var t,e,r=0;return function(o){var n=o.type;if(o=JSON.stringify(o),0===o.length)return r;for(t=0;t