otsdaq_utilities  v2_05_02_indev
clipboard.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Clipboard=function(t){this.table=t,this.mode=!0,this.copySelector=!1,this.copySelectorParams={},this.copyFormatter=!1,this.copyFormatterParams={},this.pasteParser=function(){},this.pasteAction=function(){},this.htmlElement=!1,this.config={},this.blocked=!0};Clipboard.prototype.initialize=function(){var t=this;this.mode=this.table.options.clipboard,!0!==this.mode&&"copy"!==this.mode||this.table.element.addEventListener("copy",function(o){var e;t.processConfig(),t.blocked||(o.preventDefault(),e=t.generateContent(),window.clipboardData&&window.clipboardData.setData?window.clipboardData.setData("Text",e):o.clipboardData&&o.clipboardData.setData?(o.clipboardData.setData("text/plain",e),t.htmlElement&&o.clipboardData.setData("text/html",t.htmlElement.outerHTML)):o.originalEvent&&o.originalEvent.clipboardData.setData&&(o.originalEvent.clipboardData.setData("text/plain",e),t.htmlElement&&o.originalEvent.clipboardData.setData("text/html",t.htmlElement.outerHTML)),t.table.options.clipboardCopied.call(this.table,e),t.reset())}),!0!==this.mode&&"paste"!==this.mode||this.table.element.addEventListener("paste",function(o){t.paste(o)}),this.setPasteParser(this.table.options.clipboardPasteParser),this.setPasteAction(this.table.options.clipboardPasteAction)},Clipboard.prototype.processConfig=function(){var t={columnHeaders:"groups",rowGroups:!0,columnCalcs:!0};if(void 0!==this.table.options.clipboardCopyHeader&&(t.columnHeaders=this.table.options.clipboardCopyHeader,console.warn("DEPRECATION WARNING - clipboardCopyHeader option has been deprecated, please use the columnHeaders property on the clipboardCopyConfig option")),this.table.options.clipboardCopyConfig)for(var o in this.table.options.clipboardCopyConfig)t[o]=this.table.options.clipboardCopyConfig[o];t.rowGroups&&this.table.options.groupBy&&this.table.modExists("groupRows")&&(this.config.rowGroups=!0),t.columnHeaders?"groups"!==t.columnHeaders&&!0!==t||this.table.columnManager.columns.length==this.table.columnManager.columnsByIndex.length?this.config.columnHeaders="columns":this.config.columnHeaders="groups":this.config.columnHeaders=!1,t.columnCalcs&&this.table.modExists("columnCalcs")&&(this.config.columnCalcs=!0)},Clipboard.prototype.reset=function(){this.blocked=!1,this.originalSelectionText=""},Clipboard.prototype.setPasteAction=function(t){switch(void 0===t?"undefined":_typeof(t)){case"string":this.pasteAction=this.pasteActions[t],this.pasteAction||console.warn("Clipboard Error - No such paste action found:",t);break;case"function":this.pasteAction=t}},Clipboard.prototype.setPasteParser=function(t){switch(void 0===t?"undefined":_typeof(t)){case"string":this.pasteParser=this.pasteParsers[t],this.pasteParser||console.warn("Clipboard Error - No such paste parser found:",t);break;case"function":this.pasteParser=t}},Clipboard.prototype.paste=function(t){var o,e,r;this.checkPaseOrigin(t)&&(o=this.getPasteData(t),e=this.pasteParser.call(this,o),e?(t.preventDefault(),this.table.modExists("mutator")&&(e=this.mutateData(e)),r=this.pasteAction.call(this,e),this.table.options.clipboardPasted.call(this.table,o,e,r)):this.table.options.clipboardPasteError.call(this.table,o))},Clipboard.prototype.mutateData=function(t){var o=this,e=[];return Array.isArray(t)?t.forEach(function(t){e.push(o.table.modules.mutator.transformRow(t,"clipboard"))}):e=t,e},Clipboard.prototype.checkPaseOrigin=function(t){var o=!0;return("DIV"!=t.target.tagName||this.table.modules.edit.currentCell)&&(o=!1),o},Clipboard.prototype.getPasteData=function(t){var o;return window.clipboardData&&window.clipboardData.getData?o=window.clipboardData.getData("Text"):t.clipboardData&&t.clipboardData.getData?o=t.clipboardData.getData("text/plain"):t.originalEvent&&t.originalEvent.clipboardData.getData&&(o=t.originalEvent.clipboardData.getData("text/plain")),o},Clipboard.prototype.copy=function(t,o,e,r,a){var n,i,l;this.blocked=!1,!0!==this.mode&&"copy"!==this.mode||(void 0!==window.getSelection&&void 0!==document.createRange?(n=document.createRange(),n.selectNodeContents(this.table.element),i=window.getSelection(),i.toString()&&a&&(t="userSelection",e="raw",o=i.toString()),i.removeAllRanges(),i.addRange(n)):void 0!==document.selection&&void 0!==document.body.createTextRange&&(l=document.body.createTextRange(),l.moveToElementText(this.table.element),l.select()),this.setSelector(t),this.copySelectorParams=void 0!==o&&null!=o?o:this.config.columnHeaders,this.setFormatter(e),this.copyFormatterParams=void 0!==r&&null!=r?r:{},document.execCommand("copy"),i&&i.removeAllRanges())},Clipboard.prototype.setSelector=function(t){switch(t=t||this.table.options.clipboardCopySelector,void 0===t?"undefined":_typeof(t)){case"string":this.copySelectors[t]?this.copySelector=this.copySelectors[t]:console.warn("Clipboard Error - No such selector found:",t);break;case"function":this.copySelector=t}},Clipboard.prototype.setFormatter=function(t){switch(t=t||this.table.options.clipboardCopyFormatter,void 0===t?"undefined":_typeof(t)){case"string":this.copyFormatters[t]?this.copyFormatter=this.copyFormatters[t]:console.warn("Clipboard Error - No such formatter found:",t);break;case"function":this.copyFormatter=t}},Clipboard.prototype.generateContent=function(){var t;return this.htmlElement=!1,t=this.copySelector.call(this,this.config,this.copySelectorParams),this.copyFormatter.call(this,t,this.config,this.copyFormatterParams)},Clipboard.prototype.generateSimpleHeaders=function(t){var o=[];return t.forEach(function(t){o.push(t.definition.title)}),o},Clipboard.prototype.generateColumnGroupHeaders=function(t){var o=this,e=[];return this.table.columnManager.columns.forEach(function(t){var r=o.processColumnGroup(t);r&&e.push(r)}),e},Clipboard.prototype.processColumnGroup=function(t){var o=this,e=t.columns,r={type:"group",title:t.definition.title,column:t};if(e.length){if(r.subGroups=[],r.width=0,e.forEach(function(t){var e=o.processColumnGroup(t);e&&(r.width+=e.width,r.subGroups.push(e))}),!r.width)return!1}else{if(!t.field||!(t.definition.clipboard||t.visible&&!1!==t.definition.clipboard))return!1;r.width=1}return r},Clipboard.prototype.groupHeadersToRows=function(t){function o(t,a){void 0===r[a]&&(r[a]=[]),r[a].push(t.title),t.subGroups?t.subGroups.forEach(function(t){o(t,a+1)}):e()}function e(){var t=0;r.forEach(function(o){var e=o.length;e>t&&(t=e)}),r.forEach(function(o){var e=o.length;if(e<t)for(var r=e;r<t;r++)o.push("")})}var r=[];return t.forEach(function(t){o(t,0)}),r},Clipboard.prototype.rowsToData=function(t,o,e,r){var a=[];return t.forEach(function(t){var e=[],r=t instanceof RowComponent?t.getData("clipboard"):t;o.forEach(function(t){var o=t.getFieldValue(r);switch(void 0===o?"undefined":_typeof(o)){case"object":o=JSON.stringify(o);break;case"undefined":case"null":o="";break;default:o=o}e.push(o)}),a.push(e)}),a},Clipboard.prototype.buildComplexRows=function(t){var o=this,e=[];return this.table.modules.groupRows.getGroups().forEach(function(t){e.push(o.processGroupData(t))}),e},Clipboard.prototype.processGroupData=function(t){var o=this,e=t.getSubGroups(),r={type:"group",key:t.key};return e.length?(r.subGroups=[],e.forEach(function(t){r.subGroups.push(o.processGroupData(t))})):r.rows=t.getRows(!0),r},Clipboard.prototype.getCalcRow=function(t,o,e,r){var a=t[e];return a&&(r&&(a=a[r]),Object.keys(a).length)?this.rowsToData([a],o):[]},Clipboard.prototype.buildOutput=function(t,o,e){var r,a=this,n=[],i=[],l=[];return this.table.columnManager.columnsByIndex.forEach(function(t){(t.definition.clipboard||t.visible&&!1!==t.definition.clipboard)&&l.push(t)}),"groups"==o.columnHeaders?(i=this.generateColumnGroupHeaders(this.table.columnManager.columns),n=n.concat(this.groupHeadersToRows(i))):(i=l,n.push(this.generateSimpleHeaders(i))),this.config.columnCalcs&&(r=this.table.getCalcResults()),this.table.options.clipboardCopyStyled&&this.generateHTML(t,i,r,o,e),o.rowGroups?t.forEach(function(t){n=n.concat(a.parseRowGroupData(t,l,o,e,r||{}))}):(o.columnCalcs&&(n=n.concat(this.getCalcRow(r,l,"top"))),n=n.concat(this.rowsToData(t,l,o,e)),o.columnCalcs&&(n=n.concat(this.getCalcRow(r,l,"bottom")))),n},Clipboard.prototype.parseRowGroupData=function(t,o,e,r,a){var n=this,i=[];return i.push([t.key]),t.subGroups?t.subGroups.forEach(function(o){i=i.concat(n.parseRowGroupData(o,e,r,a[t.key]?a[t.key].groups||{}:{}))}):(e.columnCalcs&&(i=i.concat(this.getCalcRow(a,o,t.key,"top"))),i=i.concat(this.rowsToData(t.rows,o,e,r)),e.columnCalcs&&(i=i.concat(this.getCalcRow(a,o,t.key,"bottom")))),i},Clipboard.prototype.generateHTML=function(t,o,e,r,a){function n(t,o){var e=[];return void 0===y[o]&&(y[o]=[]),y[o].push({title:t.title,width:t.width,height:1,children:!!t.subGroups,element:t.column.getElement()}),t.subGroups?(t.subGroups.forEach(function(t){e=e.concat(n(t,o+1))}),e):[t.column]}function i(t,o,e){var r=t[o];r&&(e&&(r=r[e]),Object.keys(r).length&&l([r]))}function l(t){t.forEach(function(t,e){var r,a=document.createElement("tr"),n=h,i=!1;t instanceof RowComponent?r=t.getData("clipboard"):(r=t,i=!0),o.forEach(function(t,e){var n=document.createElement("td"),i=t.getFieldValue(r);switch(void 0===i?"undefined":_typeof(i)){case"object":i=JSON.stringify(i);break;case"undefined":case"null":i="";break;default:i=i}n.innerHTML=i,t.definition.align&&(n.style.textAlign=t.definition.align),o.length,b&&g.mapElementStyles(b,n,["border-top","border-left","border-right","border-bottom","color","font-weight","font-family","font-size"]),a.appendChild(n)}),i?n=d:(e%2||!p||(n=p),e%2&&u&&(n=u)),n&&g.mapElementStyles(n,a,["border-top","border-left","border-right","border-bottom","color","font-weight","font-family","font-size","background-color"]),c.appendChild(a)})}function s(t,e){var a=document.createElement("tr"),n=document.createElement("td");n.colSpan=o.length,n.innerHTML=t.key,a.appendChild(n),c.appendChild(a),g.mapElementStyles(f,a,["border-top","border-left","border-right","border-bottom","color","font-weight","font-family","font-size","background-color"]),t.subGroups?t.subGroups.forEach(function(o){s(o,e[t.key]?e[t.key].groups||{}:{})}):(r.columnCalcs&&i(e,t.key,"top"),l(t.rows),r.columnCalcs&&i(e,t.key,"bottom"))}var c,p,u,d,h,b,f,m,g=this,y=[];if(this.htmlElement=document.createElement("table"),g.mapElementStyles(this.table.element,this.htmlElement,["border-top","border-left","border-right","border-bottom"]),r.columnHeaders)if("groups"==r.columnHeaders){var C=[];o.forEach(function(t){C=C.concat(n(t,0))}),o=C,function(){y.forEach(function(t,o){t.forEach(function(t){t.children||(t.height=y.length-o)})})}(),function(t){var o=document.createElement("thead");t.forEach(function(t){var e=document.createElement("tr");t.forEach(function(t){var o=document.createElement("th");t.width>1&&(o.colSpan=t.width),t.height>1&&(o.rowSpan=t.height),o.innerHTML=t.title,g.mapElementStyles(t.element,o,["border-top","border-left","border-right","border-bottom","background-color","color","font-weight","font-family","font-size"]),e.appendChild(o)}),g.mapElementStyles(g.table.columnManager.getHeadersElement(),e,["border-top","border-left","border-right","border-bottom","background-color","color","font-weight","font-family","font-size"]),o.appendChild(e)}),g.htmlElement.appendChild(o)}(y)}else!function(){var t=document.createElement("tr");o.forEach(function(o){var e=document.createElement("th");e.innerHTML=o.definition.title,g.mapElementStyles(o.getElement(),e,["border-top","border-left","border-right","border-bottom","background-color","color","font-weight","font-family","font-size"]),t.appendChild(e)}),g.mapElementStyles(g.table.columnManager.getHeadersElement(),t,["border-top","border-left","border-right","border-bottom","background-color","color","font-weight","font-family","font-size"]),g.htmlElement.appendChild(document.createElement("thead").appendChild(t))}();c=document.createElement("tbody"),window.getComputedStyle&&(p=this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)"),u=this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)"),d=this.table.element.querySelector(".tabulator-row.tabulator-calcs"),h=this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)"),f=this.table.element.getElementsByClassName("tabulator-group")[0],h&&(m=h.getElementsByClassName("tabulator-cell"),b=m[0],m[m.length-1])),r.rowGroups?t.forEach(function(t){s(t,e||{})}):(r.columnCalcs&&i(e,"top"),l(t),r.columnCalcs&&i(e,"bottom")),this.htmlElement.appendChild(c)},Clipboard.prototype.mapElementStyles=function(t,o,e){var r={"background-color":"backgroundColor",color:"fontColor","font-weight":"fontWeight","font-family":"fontFamily","font-size":"fontSize","border-top":"borderTop","border-left":"borderLeft","border-right":"borderRight","border-bottom":"borderBottom"};if(window.getComputedStyle){var a=window.getComputedStyle(t);e.forEach(function(t){o.style[r[t]]=a.getPropertyValue(t)})}},Clipboard.prototype.copySelectors={userSelection:function(t,o){return o},selected:function(t,o){var e=[];return this.table.modExists("selectRow",!0)&&(e=this.table.modules.selectRow.getSelectedRows()),t.rowGroups&&console.warn("Clipboard Warning - select coptSelector does not support row groups"),this.buildOutput(e,t,o)},table:function(t,o){return t.rowGroups&&console.warn("Clipboard Warning - table coptSelector does not support row groups"),this.buildOutput(this.table.rowManager.getComponents(),t,o)},active:function(t,o){var e;return e=t.rowGroups?this.buildComplexRows(t):this.table.rowManager.getComponents("active"),this.buildOutput(e,t,o)},visible:function(t,o){var e;return e=t.rowGroups?this.buildComplexRows(t):this.table.rowManager.getComponents("visible"),this.buildOutput(e,t,o)}},Clipboard.prototype.copyFormatters={raw:function(t,o){return t},table:function(t,o){var e=[];return t.forEach(function(t){var o=[];t.forEach(function(t){void 0===t&&(t=""),t=void 0===t||null===t?"":t.toString(),t.match(/\r|\n/)&&(t=t.split('"').join('""'),t='"'+t+'"'),o.push(t)}),e.push(o.join("\t"))}),e.join("\n")}},Clipboard.prototype.pasteParsers={table:function(t){var o=[],e=!0,r=this.table.columnManager.columns,a=[],n=[];return t=t.split("\n"),t.forEach(function(t){o.push(t.split("\t"))}),!(!o.length||1===o.length&&o[0].length<2)&&(!0,o[0].forEach(function(t){var o=r.find(function(o){return t&&o.definition.title&&t.trim()&&o.definition.title.trim()===t.trim()});o?a.push(o):e=!1}),e||(e=!0,a=[],o[0].forEach(function(t){var o=r.find(function(o){return t&&o.field&&t.trim()&&o.field.trim()===t.trim()});o?a.push(o):e=!1}),e||(a=this.table.columnManager.columnsByIndex)),e&&o.shift(),o.forEach(function(t){var o={};t.forEach(function(t,e){a[e]&&(o[a[e].field]=t)}),n.push(o)}),n)}},Clipboard.prototype.pasteActions={replace:function(t){return this.table.setData(t)},update:function(t){return this.table.updateOrAddData(t)},insert:function(t){return this.table.addData(t)}},Tabulator.prototype.registerModule("clipboard",Clipboard);