@toolbox-web/grid 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/plugin/index.d.ts +1 -0
- package/lib/core/plugin/types.d.ts +61 -0
- package/lib/core/types.d.ts +54 -2
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/export/types.d.ts +35 -5
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/internal/utils"),require("../../core/internal/value-accessor"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/utils","../../core/internal/value-accessor","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_export={},e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,r,o){"use strict";function s(e,t,r=!0){let o=e;if(r&&(o=o.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.utility)),t?.length){const e=new Set(t);o=o.filter(t=>e.has(t.field))}return o}function n(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function l(e,t=!0){return"string"==typeof e?t&&(e.includes(",")||e.includes('"')||e.includes("\n")||e.includes("\r"))?`"${e.replace(/"/g,'""')}"`:e:"number"==typeof e?String(e):"boolean"==typeof e?e?"true":"false":null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function i(e,t,o,s={}){const n=s.delimiter??",",i=s.newline??"\n",c=s.quoteStrings??!0,a=[],u=s.bom?"\ufeff":"";if(!1!==o.includeHeaders){const e=t.map(e=>{const t=e.header||e.field;return l(o.processHeader?o.processHeader(t,e.field):t,c)});a.push(e.join(n))}for(const f of e){const e=t.map(e=>{let t=r.resolveCellValue(f,e);return o.processCell&&(t=o.processCell(t,e.field,f)),l(t,c)});a.push(e.join(n))}return u+a.join(i)}function c(e,t){const r=URL.createObjectURL(e),o=document.createElement("a");o.href=r,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}function a(e){return JSON.stringify(u(e))}function u(e){if(null==e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(u);const t={};for(const r of Object.keys(e).sort())t[r]=u(e[r]);return t}class f{#e=new Map;#t=0;register(e){const t=a(e),r=this.#e.get(t);if(r)return r.id;this.#t++;const o=`s${this.#t}`;return this.#e.set(t,{id:o,style:e}),o}getStyleId(e){return this.#e.get(a(e))?.id}get size(){return this.#e.size}toXml(){if(0===this.#e.size)return"";let e="\n<Styles>";for(const{id:t,style:r}of this.#e.values())e+=d(t,r);return e+="\n</Styles>",e}}function d(e,t){let r=`\n<Style ss:ID="${e}">`;if(t.font&&(r+="<Font",t.font.name&&(r+=` ss:FontName="${t.font.name}"`),t.font.size&&(r+=` ss:Size="${t.font.size}"`),t.font.bold&&(r+=' ss:Bold="1"'),t.font.italic&&(r+=' ss:Italic="1"'),t.font.color&&(r+=` ss:Color="${t.font.color}"`),r+="/>"),t.fill){const e=t.fill.pattern??"Solid";r+=`<Interior ss:Color="${t.fill.color}" ss:Pattern="${e}"/>`}return t.numberFormat&&(r+=`<NumberFormat ss:Format="${t.numberFormat}"/>`),t.alignment&&(r+="<Alignment",t.alignment.horizontal&&(r+=` ss:Horizontal="${t.alignment.horizontal}"`),t.alignment.vertical&&(r+=` ss:Vertical="${t.alignment.vertical}"`),t.alignment.wrapText&&(r+=' ss:WrapText="1"'),r+="/>"),t.borders&&(r+="<Borders>",t.borders.top&&(r+=p("Top",t.borders.top)),t.borders.bottom&&(r+=p("Bottom",t.borders.bottom)),t.borders.left&&(r+=p("Left",t.borders.left)),t.borders.right&&(r+=p("Right",t.borders.right)),r+="</Borders>"),r+="</Style>",r}function p(e,t){let r=`<Border ss:Position="${e}" ss:LineStyle="Continuous" ss:Weight="${function(e){switch(e){case"Thin":return 1;case"Medium":return 2;case"Thick":return 3}}(t.style)}"`;return t.color&&(r+=` ss:Color="${t.color}"`),r+="/>",r}function m(e,t,r,o,s){if(t.cellStyle){const n=t.cellStyle(r,o,s);if(n)return e.register(n)}const n=t.columnStyles?.[o];return n?e.getStyleId(n):t.defaultStyle?e.getStyleId(t.defaultStyle):void 0}function h(e,t){const r=Math.min(t.length,50);let o=(e.header??e.field).length;for(let s=0;s<r;s++){const r=t[s][e.field],n=null==r?0:String(r).length;n>o&&(o=n)}return o+2}function g(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function y(e,t,o){const s=o.excelStyles,n=s?function(e){const t=new f;if(e.headerStyle&&t.register(e.headerStyle),e.defaultStyle&&t.register(e.defaultStyle),e.columnStyles)for(const r of Object.values(e.columnStyles))t.register(r);return t}(s):void 0;let l='<?xml version="1.0" encoding="UTF-8"?>\n<?mso-application progid="Excel.Sheet"?>\n<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"\n xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">';if(n){if(s.cellStyle)for(const o of e)for(const e of t){const t=r.resolveCellValue(o,e),l=s.cellStyle(t,e.field,o);l&&n.register(l)}l+=n.toXml()}l+='\n<Worksheet ss:Name="Sheet1">\n<Table>',s&&(l+=function(e,t,r){const o=r.columnWidths,s=r.autoFitColumns;if(!o&&!s)return"";let n="";for(const l of e){let e=o?.[l.field];null==e&&s&&(e=h(l,t)),n+=null!=e?`\n<Column ss:Width="${7*e}"/>`:"\n<Column/>"}return n}(t,e,s));const i=s?.headerStyle&&n?n.getStyleId(s.headerStyle):void 0;if(!1!==o.includeHeaders){l+="\n<Row>";for(const e of t){const t=e.header||e.field;l+=`<Cell${i?` ss:StyleID="${i}"`:""}><Data ss:Type="String">${g(o.processHeader?o.processHeader(t,e.field):t)}</Data></Cell>`}l+="</Row>"}for(const c of e){l+="\n<Row>";for(const e of t){let t=r.resolveCellValue(c,e);o.processCell&&(t=o.processCell(t,e.field,c));let i="String",a="";null==t?a="":"number"!=typeof t||isNaN(t)?t instanceof Date?(i="DateTime",a=t.toISOString()):a=g(String(t)):(i="Number",a=String(t));const u=n&&s?m(n,s,t,e.field,c):void 0;l+=`<Cell${u?` ss:StyleID="${u}"`:""}><Data ss:Type="${i}">${a}</Data></Cell>`}l+="</Row>"}return l+="\n</Table>\n</Worksheet>\n</Workbook>",l}class x extends o.BaseGridPlugin{static manifest={queries:[{type:"export:csv",description:"Triggers a CSV export"}]};name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;handleQuery(e){if("export:csv"===e.type)return this.exportCsv(),!0}resolveExportData(e,t){const r=this.config,o={format:e,fileName:t?.fileName??r.fileName??"export",includeHeaders:t?.includeHeaders??r.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,mode:t?.mode??"raw",columns:t?.columns,rowIndices:t?.rowIndices,excelStyles:t?.excelStyles,fileExtension:t?.fileExtension},l=s(this.columns,t?.columns,r.onlyVisible);let i;if(t?.rowIndices)i=n(this.rows,t.rowIndices);else if(r.onlySelected){const e=this.getSelectionState();i=e?.selected?.size?n(this.rows,[...e.selected]):[...this.rows]}else i=[...this.rows];return{columns:l,rows:i,fullParams:o}}resolveCellOutput(e,r,o,s,n){let l=e;if("formatted"===s){const s=this.#r(r);if(s)try{const t=s(e,o);l=null==t?"":String(t)}catch{l=null==e?"":String(e)}else l="date"===r.type?t.formatDateValue(e):"boolean"===r.type?!!e:e}return n&&(l=n(l,r.field,o)),l}performExport(e,t){const{columns:r,rows:o,fullParams:s}=this.resolveExportData(e,t);this.isExportingFlag=!0;let n=s.fileName??"export";const l=this.#o(r);try{switch(e){case"csv":{const e=i(this.#s(o,r,s),l,{...s,processCell:void 0},{bom:!0});n=n.endsWith(".csv")?n:`${n}.csv`,function(e,t){c(new Blob([e],{type:"text/csv;charset=utf-8;"}),t)}(e,n);break}case"excel":{const e=y(this.#s(o,r,s),l,{...s,processCell:void 0}),t=s.fileExtension??".xls",i=t.startsWith(".")?t:`.${t}`;n=n.endsWith(i)?n:`${n}${i}`,function(e,t){c(new Blob([e],{type:"application/vnd.ms-excel;charset=utf-8;"}),t)}(e,n);break}case"json":{const e=this.#s(o,r,s),t=JSON.stringify(e,null,2);n=n.endsWith(".json")?n:`${n}.json`;c(new Blob([t],{type:"application/json"}),n);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:n,rowCount:o.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}#s(e,t,o){const s=o.mode??"raw";return e.map(e=>{const n={};for(const l of t){const t=r.resolveCellValue(e,l);n[l.field]=this.resolveCellOutput(t,l,e,s,o.processCell)}return n})}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}export(e){const{columns:t,rows:r,fullParams:o}=this.resolveExportData("json",e);return this.#s(r,t,o)}getResolvedColumns(e){return s(this.columns,e?.columns,this.config.onlyVisible)}formatCsv(e,t,r){const{columns:o,fullParams:s}=this.resolveExportData("csv",t);return i(e,this.#o(o),s,r)}formatExcel(e,t){const{columns:r,fullParams:o}=this.resolveExportData("excel",t);return y(e,this.#o(r),o)}#o(e){return e.map(e=>e.valueAccessor?{...e,valueAccessor:void 0}:e)}#r(e){if(e.format)return e.format;if(!e.type)return;const t=this.grid,r=t?.__frameworkAdapter;if(!r?.getTypeDefault)return;const o=r.getTypeDefault(e.type,t?._hostElement);return o?.format}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}e.ExportPlugin=x,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/internal/utils"),require("../../core/internal/value-accessor"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/utils","../../core/internal/value-accessor","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_export={},e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,r,s){"use strict";function o(e,t,r=!0){let s=e;if(r&&(s=s.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.utility)),t?.length){const e=new Set(t);s=s.filter(t=>e.has(t.field))}return s}function n(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}function l(e,t=!0){return"string"==typeof e?t&&(e.includes(",")||e.includes('"')||e.includes("\n")||e.includes("\r"))?`"${e.replace(/"/g,'""')}"`:e:"number"==typeof e?String(e):"boolean"==typeof e?e?"true":"false":null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}function i(e,t,s,o={}){const n=o.delimiter??",",i=o.newline??"\n",c=o.quoteStrings??!0,a=[],u=o.bom?"\ufeff":"";if(!1!==s.includeHeaders){const e=t.map(e=>{const t=e.header||e.field;return l(s.processHeader?s.processHeader(t,e.field):t,c)});a.push(e.join(n))}for(const f of e){const e=t.map(e=>{let t=r.resolveCellValue(f,e);return s.processCell&&(t=s.processCell(t,e.field,f)),l(t,c)});a.push(e.join(n))}return u+a.join(i)}function c(e,t){const r=URL.createObjectURL(e),s=document.createElement("a");s.href=r,s.download=t,s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)}function a(e){return JSON.stringify(u(e))}function u(e){if(null==e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(u);const t={};for(const r of Object.keys(e).sort())t[r]=u(e[r]);return t}class f{#e=new Map;#t=0;register(e){const t=a(e),r=this.#e.get(t);if(r)return r.id;this.#t++;const s=`s${this.#t}`;return this.#e.set(t,{id:s,style:e}),s}getStyleId(e){return this.#e.get(a(e))?.id}get size(){return this.#e.size}toXml(){if(0===this.#e.size)return"";let e="\n<Styles>";for(const{id:t,style:r}of this.#e.values())e+=d(t,r);return e+="\n</Styles>",e}}function d(e,t){let r=`\n<Style ss:ID="${e}">`;if(t.font&&(r+="<Font",t.font.name&&(r+=` ss:FontName="${t.font.name}"`),t.font.size&&(r+=` ss:Size="${t.font.size}"`),t.font.bold&&(r+=' ss:Bold="1"'),t.font.italic&&(r+=' ss:Italic="1"'),t.font.color&&(r+=` ss:Color="${t.font.color}"`),r+="/>"),t.fill){const e=t.fill.pattern??"Solid";r+=`<Interior ss:Color="${t.fill.color}" ss:Pattern="${e}"/>`}return t.numberFormat&&(r+=`<NumberFormat ss:Format="${t.numberFormat}"/>`),t.alignment&&(r+="<Alignment",t.alignment.horizontal&&(r+=` ss:Horizontal="${t.alignment.horizontal}"`),t.alignment.vertical&&(r+=` ss:Vertical="${t.alignment.vertical}"`),t.alignment.wrapText&&(r+=' ss:WrapText="1"'),r+="/>"),t.borders&&(r+="<Borders>",t.borders.top&&(r+=p("Top",t.borders.top)),t.borders.bottom&&(r+=p("Bottom",t.borders.bottom)),t.borders.left&&(r+=p("Left",t.borders.left)),t.borders.right&&(r+=p("Right",t.borders.right)),r+="</Borders>"),r+="</Style>",r}function p(e,t){let r=`<Border ss:Position="${e}" ss:LineStyle="Continuous" ss:Weight="${function(e){switch(e){case"Thin":return 1;case"Medium":return 2;case"Thick":return 3}}(t.style)}"`;return t.color&&(r+=` ss:Color="${t.color}"`),r+="/>",r}function h(e,t,r,s,o){if(t.cellStyle){const n=t.cellStyle(r,s,o);if(n)return e.register(n)}const n=t.columnStyles?.[s];return n?e.getStyleId(n):t.defaultStyle?e.getStyleId(t.defaultStyle):void 0}function m(e,t){const r=Math.min(t.length,50);let s=(e.header??e.field).length;for(let o=0;o<r;o++){const r=t[o][e.field],n=null==r?0:String(r).length;n>s&&(s=n)}return s+2}function g(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function y(e,t,s){const o=s.excelStyles,n=o?function(e){const t=new f;if(e.headerStyle&&t.register(e.headerStyle),e.groupHeaderStyle&&t.register(e.groupHeaderStyle),e.defaultStyle&&t.register(e.defaultStyle),e.columnStyles)for(const r of Object.values(e.columnStyles))t.register(r);return t}(o):void 0;let l='<?xml version="1.0" encoding="UTF-8"?>\n<?mso-application progid="Excel.Sheet"?>\n<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"\n xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">';if(n){if(o.cellStyle)for(const s of e)for(const e of t){const t=r.resolveCellValue(s,e),l=o.cellStyle(t,e.field,s);l&&n.register(l)}l+=n.toXml()}l+='\n<Worksheet ss:Name="Sheet1">\n<Table>',o&&(l+=function(e,t,r){const s=r.columnWidths,o=r.autoFitColumns;if(!s&&!o)return"";let n="";for(const l of e){let e=s?.[l.field];null==e&&o&&(e=m(l,t)),n+=null!=e?`\n<Column ss:Width="${7*e}"/>`:"\n<Column/>"}return n}(t,e,o));const i=o?.headerStyle&&n?n.getStyleId(o.headerStyle):void 0,c=o?.groupHeaderStyle&&n?n.getStyleId(o.groupHeaderStyle):i;if(!1!==s.includeHeaders&&s.headerRows&&s.headerRows.length>0){const e=c?` ss:StyleID="${c}"`:"";for(const t of s.headerRows){l+="\n<Row>";for(const r of t.cells){const t=Math.max(1,0|r.span);l+=`<Cell${e}${t>1?` ss:MergeAcross="${t-1}"`:""}><Data ss:Type="String">${g(r.label??"")}</Data></Cell>`}l+="</Row>"}}if(!1!==s.includeHeaders){l+="\n<Row>";for(const e of t){const t=e.header||e.field;l+=`<Cell${i?` ss:StyleID="${i}"`:""}><Data ss:Type="String">${g(s.processHeader?s.processHeader(t,e.field):t)}</Data></Cell>`}l+="</Row>"}for(const a of e){l+="\n<Row>";for(const e of t){let t=r.resolveCellValue(a,e);s.processCell&&(t=s.processCell(t,e.field,a));let i="String",c="";null==t?c="":"number"!=typeof t||isNaN(t)?t instanceof Date?(i="DateTime",c=t.toISOString()):c=g(String(t)):(i="Number",c=String(t));const u=n&&o?h(n,o,t,e.field,a):void 0;l+=`<Cell${u?` ss:StyleID="${u}"`:""}><Data ss:Type="${i}">${c}</Data></Cell>`}l+="</Row>"}return l+="\n</Table>\n</Worksheet>\n</Workbook>",l}class S extends s.BaseGridPlugin{static manifest={queries:[{type:"export:csv",description:"Triggers a CSV export"}]};name="export";get defaultConfig(){return{fileName:"export",includeHeaders:!0,onlyVisible:!0,onlySelected:!1}}isExportingFlag=!1;lastExportInfo=null;handleQuery(e){if("export:csv"===e.type)return this.exportCsv(),!0}resolveExportData(e,t){const r=this.config,s={format:e,fileName:t?.fileName??r.fileName??"export",includeHeaders:t?.includeHeaders??r.includeHeaders,processCell:t?.processCell,processHeader:t?.processHeader,processHeaderRow:t?.processHeaderRow,mode:t?.mode??"raw",columns:t?.columns,rowIndices:t?.rowIndices,excelStyles:t?.excelStyles,fileExtension:t?.fileExtension,headerRows:t?.headerRows},l=o(this.columns,t?.columns,r.onlyVisible);let i;if(t?.rowIndices)i=n(this.rows,t.rowIndices);else if(r.onlySelected){const e=this.getSelectionState();i=e?.selected?.size?n(this.rows,[...e.selected]):[...this.rows]}else i=[...this.rows];if(!1===s.includeHeaders)s.headerRows=void 0;else{const e=s.headerRows??this.#r(l);s.headerRows=this.#s(e,l,s.processHeaderRow)}return{columns:l,rows:i,fullParams:s}}#r(e){if(0===e.length)return[];const t=this.grid;if(!t?.query)return[];const r=t.query("collectHeaderRows",{columns:e});if(!r||0===r.length)return[];const s=[];for(const o of r)if(o)if(Array.isArray(o))for(const e of o)e&&Array.isArray(e.cells)&&e.cells.length>0&&s.push(e);else Array.isArray(o.cells)&&o.cells.length>0&&s.push(o);return s}#s(e,t,r){if(!e||0===e.length)return;const s=t.length,o=[];for(let n=0;n<e.length;n++){const t=e[n];if(!t||!Array.isArray(t.cells)||0===t.cells.length)continue;const l=[];let i=!1,c=0,a=!1;for(const e of t.cells){const t=Math.max(1,0|e.span);if(c+t>s){a=!0;break}c+=t;const o=r?r(e,n):e;null===o?l.push({label:"",span:t}):(l.push({...o,span:t}),""!==(o.label??"")&&(i=!0))}a||(c<s&&l.push({label:"",span:s-c}),i&&o.push({cells:l}))}return o.length>0?o:void 0}resolveCellOutput(e,r,s,o,n){let l=e;if("formatted"===o){const o=this.#o(r);if(o)try{const t=o(e,s);l=null==t?"":String(t)}catch{l=null==e?"":String(e)}else l="date"===r.type?t.formatDateValue(e):"boolean"===r.type?!!e:e}return n&&(l=n(l,r.field,s)),l}performExport(e,t){const{columns:r,rows:s,fullParams:o}=this.resolveExportData(e,t);this.isExportingFlag=!0;let n=o.fileName??"export";const l=this.#n(r);try{switch(e){case"csv":{const e=i(this.#l(s,r,o),l,{...o,processCell:void 0},{bom:!0});n=n.endsWith(".csv")?n:`${n}.csv`,function(e,t){c(new Blob([e],{type:"text/csv;charset=utf-8;"}),t)}(e,n);break}case"excel":{const e=y(this.#l(s,r,o),l,{...o,processCell:void 0}),t=o.fileExtension??".xls",i=t.startsWith(".")?t:`.${t}`;n=n.endsWith(i)?n:`${n}${i}`,function(e,t){c(new Blob([e],{type:"application/vnd.ms-excel;charset=utf-8;"}),t)}(e,n);break}case"json":{const e=this.#l(s,r,o),t=o.headerRows&&o.headerRows.length>0?{headerRows:o.headerRows,rows:e}:e,l=JSON.stringify(t,null,2);n=n.endsWith(".json")?n:`${n}.json`;c(new Blob([l],{type:"application/json"}),n);break}}this.lastExportInfo={format:e,timestamp:new Date},this.emit("export-complete",{format:e,fileName:n,rowCount:s.length,columnCount:r.length})}finally{this.isExportingFlag=!1}}#l(e,t,s){const o=s.mode??"raw";return e.map(e=>{const n={};for(const l of t){const t=r.resolveCellValue(e,l);n[l.field]=this.resolveCellOutput(t,l,e,o,s.processCell)}return n})}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}export(e){const{columns:t,rows:r,fullParams:s}=this.resolveExportData("json",e);return this.#l(r,t,s)}getResolvedColumns(e){return o(this.columns,e?.columns,this.config.onlyVisible)}formatCsv(e,t,r){const{columns:s,fullParams:o}=this.resolveExportData("csv",t);return i(e,this.#n(s),o,r)}formatExcel(e,t){const{columns:r,fullParams:s}=this.resolveExportData("excel",t);return y(e,this.#n(r),s)}#n(e){return e.map(e=>e.valueAccessor?{...e,valueAccessor:void 0}:e)}#o(e){if(e.format)return e.format;if(!e.type)return;const t=this.grid,r=t?.__frameworkAdapter;if(!r?.getTypeDefault)return;const s=r.getTypeDefault(e.type,t?._hostElement);return s?.format}exportCsv(e){this.performExport("csv",e)}exportExcel(e){this.performExport("excel",e)}exportJson(e){this.performExport("json",e)}isExporting(){return this.isExportingFlag}getLastExport(){return this.lastExportInfo}}e.ExportPlugin=S,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=export.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/shared/data-collection.ts","../../../../../libs/grid/src/lib/plugins/export/csv.ts","../../../../../libs/grid/src/lib/plugins/export/excel-styles.ts","../../../../../libs/grid/src/lib/plugins/export/excel.ts","../../../../../libs/grid/src/lib/plugins/export/ExportPlugin.ts"],"sourcesContent":["/**\n * Shared Data Collection Utilities\n *\n * Pure functions for resolving columns and formatting values, shared between\n * the Clipboard and Export plugins. Each plugin bundles its own copy of this\n * module (no chunk splitting) since plugin builds inline sibling imports.\n *\n * @internal\n */\n\nimport type { ColumnConfig } from '../../core/types';\n\n/**\n * Resolve which columns to include in a data export or copy operation.\n *\n * Filters out hidden columns, utility columns (`meta.utility`), and\n * internal columns (`__`-prefixed fields). Optionally restricts to an\n * explicit set of field names.\n *\n * @param columns - All column configurations\n * @param fields - If provided, only include columns whose field is in this list\n * @param onlyVisible - When `true` (default), exclude hidden and internal columns\n * @returns Filtered column array preserving original order\n */\nexport function resolveColumns(\n columns: readonly ColumnConfig[],\n fields?: string[],\n onlyVisible = true,\n): ColumnConfig[] {\n let result = columns as ColumnConfig[];\n\n if (onlyVisible) {\n result = result.filter((c) => !c.hidden && !c.field.startsWith('__') && c.utility !== true);\n }\n\n if (fields?.length) {\n const fieldSet = new Set(fields);\n result = result.filter((c) => fieldSet.has(c.field));\n }\n\n return result;\n}\n\n/**\n * Resolve which rows to include, optionally filtered to specific indices.\n *\n * @param rows - All row data\n * @param indices - If provided, only include rows at these indices (sorted ascending)\n * @returns Filtered row array\n */\nexport function resolveRows<T>(rows: readonly T[], indices?: number[]): T[] {\n if (!indices?.length) return rows as T[];\n\n return [...indices]\n .sort((a, b) => a - b)\n .map((i) => rows[i])\n .filter((r): r is T => r != null);\n}\n\n/**\n * Format a raw cell value as a text string.\n *\n * Provides the common null / Date / object → string conversion shared by\n * both clipboard and export output builders.\n *\n * @param value - The cell value to format\n * @returns A plain-text representation of the value\n */\nexport function formatValueAsText(value: unknown): string {\n if (value == null) return '';\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n","/**\n * CSV Export Utilities\n *\n * Functions for building and downloading CSV content.\n */\n\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport type { ColumnConfig } from '../../core/types';\nimport type { ExportParams } from './types';\n\n/** CSV export options * @since 0.1.1\n */\nexport interface CsvOptions {\n /** Field delimiter (default: ',') */\n delimiter?: string;\n /** Line separator (default: '\\n') */\n newline?: string;\n /** Whether to quote strings containing special characters (default: true) */\n quoteStrings?: boolean;\n /** Add UTF-8 BOM for Excel compatibility (default: false) */\n bom?: boolean;\n}\n\n/**\n * Format a value for CSV output.\n * Handles null, Date, objects, and strings with special characters.\n *\n * Dispatch order is `typeof`-first because string + number cover the vast\n * majority of cell values; the cheap typeof check skips an `instanceof Date`\n * probe (which V8 cannot fold into a fast path) for every plain string cell.\n */\nexport function formatCsvValue(value: any, quote = true): string {\n // Hot path: strings (most CSV cells).\n if (typeof value === 'string') {\n if (quote && (value.includes(',') || value.includes('\"') || value.includes('\\n') || value.includes('\\r'))) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`;\n }\n return value;\n }\n if (typeof value === 'number') return String(value);\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n if (value == null) return '';\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'object') return JSON.stringify(value);\n // Symbols, bigints, etc.\n return String(value);\n}\n\n/**\n * Build CSV content from rows and columns.\n */\nexport function buildCsv(rows: any[], columns: ColumnConfig[], params: ExportParams, options: CsvOptions = {}): string {\n const delimiter = options.delimiter ?? ',';\n const newline = options.newline ?? '\\n';\n const quote = options.quoteStrings ?? true;\n const lines: string[] = [];\n\n // UTF-8 BOM for Excel compatibility\n const bom = options.bom ? '\\uFEFF' : '';\n\n // Build header row\n if (params.includeHeaders !== false) {\n const headerRow = columns.map((col) => {\n const header = col.header || col.field;\n const processed = params.processHeader ? params.processHeader(header, col.field) : header;\n return formatCsvValue(processed, quote);\n });\n lines.push(headerRow.join(delimiter));\n }\n\n // Build data rows\n for (const row of rows) {\n const cells = columns.map((col) => {\n let value = resolveCellValue(row, col);\n if (params.processCell) {\n value = params.processCell(value, col.field, row);\n }\n return formatCsvValue(value, quote);\n });\n lines.push(cells.join(delimiter));\n }\n\n return bom + lines.join(newline);\n}\n\n/**\n * Download a Blob as a file.\n */\nexport function downloadBlob(blob: Blob, fileName: string): void {\n const url = URL.createObjectURL(blob);\n const link = document.createElement('a');\n link.href = url;\n link.download = fileName;\n link.style.display = 'none';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n URL.revokeObjectURL(url);\n}\n\n/**\n * Download CSV content as a file.\n */\nexport function downloadCsv(content: string, fileName: string): void {\n const blob = new Blob([content], { type: 'text/csv;charset=utf-8;' });\n downloadBlob(blob, fileName);\n}\n","/**\n * Excel Style Engine\n *\n * Builds a deduplicated `<Styles>` block for XML Spreadsheet 2003.\n * Collects unique ExcelCellStyle objects, assigns ss:StyleID values,\n * and generates the corresponding XML.\n */\n\nimport type { ExcelBorder, ExcelCellStyle, ExcelStyleConfig } from './types';\n\n// #region Style Hashing\n\n/**\n * Produce a deterministic string key for a style object.\n * Two structurally identical styles produce the same hash.\n * Recursively sorts object keys for order-independent comparison.\n */\nfunction hashStyle(style: ExcelCellStyle): string {\n return JSON.stringify(sortKeys(style));\n}\n\n/** Recursively sort object keys for deterministic serialization. */\nfunction sortKeys(obj: unknown): unknown {\n if (obj == null || typeof obj !== 'object') return obj;\n if (Array.isArray(obj)) return obj.map(sortKeys);\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n sorted[key] = sortKeys((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n}\n\n// #endregion\n\n// #region Style Registry\n\n/** Maps a hash → style ID and the original style. */\nexport interface StyleEntry {\n id: string;\n style: ExcelCellStyle;\n}\n\n/**\n * Collects unique styles and assigns each an `ss:StyleID`.\n * Register styles via `register()`, then call `getStyleId()` to look up\n * the ID for a given style, and `toXml()` to emit the `<Styles>` block.\n */\nexport class StyleRegistry {\n /** hash → StyleEntry */\n #entries = new Map<string, StyleEntry>();\n #counter = 0;\n\n /**\n * Register a style and return its assigned ID.\n * If an identical style was already registered, returns the existing ID.\n */\n register(style: ExcelCellStyle): string {\n const hash = hashStyle(style);\n const existing = this.#entries.get(hash);\n if (existing) return existing.id;\n\n this.#counter++;\n const id = `s${this.#counter}`;\n this.#entries.set(hash, { id, style });\n return id;\n }\n\n /** Look up the ID previously assigned to a style (or undefined). */\n getStyleId(style: ExcelCellStyle): string | undefined {\n return this.#entries.get(hashStyle(style))?.id;\n }\n\n /** Number of unique styles registered so far. */\n get size(): number {\n return this.#entries.size;\n }\n\n /** Emit the full `<Styles>…</Styles>` XML fragment, or empty string if no styles. */\n toXml(): string {\n if (this.#entries.size === 0) return '';\n\n let xml = '\\n<Styles>';\n for (const { id, style } of this.#entries.values()) {\n xml += buildStyleElement(id, style);\n }\n xml += '\\n</Styles>';\n return xml;\n }\n}\n\n// #endregion\n\n// #region XML Builders\n\nfunction buildStyleElement(id: string, style: ExcelCellStyle): string {\n let xml = `\\n<Style ss:ID=\"${id}\">`;\n\n if (style.font) {\n xml += '<Font';\n if (style.font.name) xml += ` ss:FontName=\"${style.font.name}\"`;\n if (style.font.size) xml += ` ss:Size=\"${style.font.size}\"`;\n if (style.font.bold) xml += ' ss:Bold=\"1\"';\n if (style.font.italic) xml += ' ss:Italic=\"1\"';\n if (style.font.color) xml += ` ss:Color=\"${style.font.color}\"`;\n xml += '/>';\n }\n\n if (style.fill) {\n const pattern = style.fill.pattern ?? 'Solid';\n xml += `<Interior ss:Color=\"${style.fill.color}\" ss:Pattern=\"${pattern}\"/>`;\n }\n\n if (style.numberFormat) {\n xml += `<NumberFormat ss:Format=\"${style.numberFormat}\"/>`;\n }\n\n if (style.alignment) {\n xml += '<Alignment';\n if (style.alignment.horizontal) xml += ` ss:Horizontal=\"${style.alignment.horizontal}\"`;\n if (style.alignment.vertical) xml += ` ss:Vertical=\"${style.alignment.vertical}\"`;\n if (style.alignment.wrapText) xml += ' ss:WrapText=\"1\"';\n xml += '/>';\n }\n\n if (style.borders) {\n xml += '<Borders>';\n if (style.borders.top) xml += buildBorderElement('Top', style.borders.top);\n if (style.borders.bottom) xml += buildBorderElement('Bottom', style.borders.bottom);\n if (style.borders.left) xml += buildBorderElement('Left', style.borders.left);\n if (style.borders.right) xml += buildBorderElement('Right', style.borders.right);\n xml += '</Borders>';\n }\n\n xml += '</Style>';\n return xml;\n}\n\nfunction buildBorderElement(position: string, border: ExcelBorder): string {\n let xml = `<Border ss:Position=\"${position}\" ss:LineStyle=\"Continuous\" ss:Weight=\"${borderWeight(border.style)}\"`;\n if (border.color) xml += ` ss:Color=\"${border.color}\"`;\n xml += '/>';\n return xml;\n}\n\nfunction borderWeight(style: ExcelBorder['style']): number {\n switch (style) {\n case 'Thin':\n return 1;\n case 'Medium':\n return 2;\n case 'Thick':\n return 3;\n }\n}\n\n// #endregion\n\n// #region Style Resolution\n\n/**\n * Build a StyleRegistry pre-populated with all styles declared in the config.\n * This covers headerStyle, defaultStyle, and columnStyles.\n * (cellStyle callbacks are resolved per-cell at render time.)\n */\nexport function buildStyleRegistry(config: ExcelStyleConfig): StyleRegistry {\n const registry = new StyleRegistry();\n\n if (config.headerStyle) registry.register(config.headerStyle);\n\n if (config.defaultStyle) registry.register(config.defaultStyle);\n\n if (config.columnStyles) {\n for (const style of Object.values(config.columnStyles)) {\n registry.register(style);\n }\n }\n\n return registry;\n}\n\n/**\n * Resolve the style ID for a data cell. Precedence (highest → lowest):\n * 1. cellStyle callback return value\n * 2. columnStyles[field]\n * 3. defaultStyle\n */\nexport function resolveDataStyleId(\n registry: StyleRegistry,\n config: ExcelStyleConfig,\n value: unknown,\n field: string,\n row: unknown,\n): string | undefined {\n // 1. Dynamic cell callback\n if (config.cellStyle) {\n const dynamic = config.cellStyle(value, field, row);\n if (dynamic) {\n // Register on-the-fly (dedup handles repeats)\n return registry.register(dynamic);\n }\n }\n\n // 2. Per-column override\n const colStyle = config.columnStyles?.[field];\n if (colStyle) return registry.getStyleId(colStyle);\n\n // 3. Default\n if (config.defaultStyle) return registry.getStyleId(config.defaultStyle);\n\n return undefined;\n}\n\n// #endregion\n\n// #region Column Widths\n\n/** Character width → Excel column width approximation (px ≈ chars × 7) */\nconst CHAR_WIDTH = 7;\n\n/**\n * Build `<Column>` elements for explicit or auto-fit widths.\n */\nexport function buildColumnWidthsXml(\n columns: { field: string; header?: string }[],\n rows: Record<string, unknown>[],\n config: ExcelStyleConfig,\n): string {\n const widths = config.columnWidths;\n const autoFit = config.autoFitColumns;\n\n if (!widths && !autoFit) return '';\n\n let xml = '';\n for (const col of columns) {\n let width: number | undefined = widths?.[col.field];\n\n if (width == null && autoFit) {\n width = autoFitWidth(col, rows);\n }\n\n if (width != null) {\n xml += `\\n<Column ss:Width=\"${width * CHAR_WIDTH}\"/>`;\n } else {\n // Emit an empty column entry to keep ordinal alignment\n xml += '\\n<Column/>';\n }\n }\n\n return xml;\n}\n\n/** Estimate width from header + first N data rows (capped at 50). */\nfunction autoFitWidth(col: { field: string; header?: string }, rows: Record<string, unknown>[]): number {\n const sampleSize = Math.min(rows.length, 50);\n let maxLen = (col.header ?? col.field).length;\n\n for (let i = 0; i < sampleSize; i++) {\n const val = rows[i][col.field];\n const len = val == null ? 0 : String(val).length;\n if (len > maxLen) maxLen = len;\n }\n\n // Add a small padding\n return maxLen + 2;\n}\n\n// #endregion\n","/**\n * Excel Export Utilities\n *\n * Simple Excel XML format export (no external dependencies).\n * Produces XML Spreadsheet 2003 format which opens in Excel.\n */\n\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport type { ColumnConfig } from '../../core/types';\nimport { downloadBlob } from './csv';\nimport { buildColumnWidthsXml, buildStyleRegistry, resolveDataStyleId } from './excel-styles';\nimport type { ExportParams } from './types';\n\n/**\n * Escape XML special characters.\n */\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * Build Excel XML content from rows and columns.\n * Uses XML Spreadsheet 2003 format for broad compatibility.\n */\nexport function buildExcelXml(rows: any[], columns: ColumnConfig[], params: ExportParams): string {\n const styles = params.excelStyles;\n const registry = styles ? buildStyleRegistry(styles) : undefined;\n\n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">`;\n\n // Emit <Styles> block (only when styles are configured)\n if (registry) {\n // Pre-register dynamic cellStyle entries so they appear in <Styles>\n if (styles!.cellStyle) {\n for (const row of rows) {\n for (const col of columns) {\n const value = resolveCellValue(row, col);\n const dynamic = styles!.cellStyle(value, col.field, row);\n if (dynamic) registry.register(dynamic);\n }\n }\n }\n xml += registry.toXml();\n }\n\n xml += '\\n<Worksheet ss:Name=\"Sheet1\">\\n<Table>';\n\n // Column widths\n if (styles) {\n xml += buildColumnWidthsXml(columns, rows as Record<string, unknown>[], styles);\n }\n\n // Header style ID\n const headerStyleId = styles?.headerStyle && registry ? registry.getStyleId(styles.headerStyle) : undefined;\n\n // Build header row\n if (params.includeHeaders !== false) {\n xml += '\\n<Row>';\n for (const col of columns) {\n const header = col.header || col.field;\n const processed = params.processHeader ? params.processHeader(header, col.field) : header;\n const styleAttr = headerStyleId ? ` ss:StyleID=\"${headerStyleId}\"` : '';\n xml += `<Cell${styleAttr}><Data ss:Type=\"String\">${escapeXml(processed)}</Data></Cell>`;\n }\n xml += '</Row>';\n }\n\n // Build data rows\n for (const row of rows) {\n xml += '\\n<Row>';\n for (const col of columns) {\n let value = resolveCellValue(row, col);\n if (params.processCell) {\n value = params.processCell(value, col.field, row);\n }\n\n // Determine cell type based on value\n let type: 'Number' | 'String' | 'DateTime' = 'String';\n let displayValue = '';\n\n if (value == null) {\n displayValue = '';\n } else if (typeof value === 'number' && !isNaN(value)) {\n type = 'Number';\n displayValue = String(value);\n } else if (value instanceof Date) {\n type = 'DateTime';\n displayValue = value.toISOString();\n } else {\n displayValue = escapeXml(String(value));\n }\n\n // Resolve data cell style\n const dataStyleId = registry && styles ? resolveDataStyleId(registry, styles, value, col.field, row) : undefined;\n const styleAttr = dataStyleId ? ` ss:StyleID=\"${dataStyleId}\"` : '';\n\n xml += `<Cell${styleAttr}><Data ss:Type=\"${type}\">${displayValue}</Data></Cell>`;\n }\n xml += '</Row>';\n }\n\n xml += '\\n</Table>\\n</Worksheet>\\n</Workbook>';\n return xml;\n}\n\n/**\n * Download Excel XML content as a file.\n */\nexport function downloadExcel(content: string, fileName: string): void {\n const blob = new Blob([content], {\n type: 'application/vnd.ms-excel;charset=utf-8;',\n });\n downloadBlob(blob, fileName);\n}\n","/**\n * Export Plugin (Class-based)\n *\n * Provides data export functionality for tbw-grid.\n * Supports CSV, Excel (XML), and JSON formats.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { formatDateValue } from '../../core/internal/utils';\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport { BaseGridPlugin, type PluginManifest, type PluginQuery } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, InternalGrid } from '../../core/types';\nimport { resolveColumns, resolveRows } from '../shared/data-collection';\nimport { buildCsv, type CsvOptions, downloadBlob, downloadCsv } from './csv';\nimport { buildExcelXml, downloadExcel } from './excel';\nimport type { ExportCompleteDetail, ExportConfig, ExportFormat, ExportMode, ExportParams } from './types';\n\n/**\n * Subset of {@link ExportParams} accepted by the pure formatters\n * ({@link ExportPlugin.formatCsv} / {@link ExportPlugin.formatExcel}).\n *\n * The formatters operate on already-resolved data, so options that affect\n * value resolution (`mode`, `rowIndices`, `format`, `fileName`,\n * `fileExtension`) are intentionally excluded — if you need them, run them\n * through {@link ExportPlugin.export} first or call the download/export\n * methods.\n *\n * `processCell` **is** honoured: it runs once per cell on the values you pass\n * in, just like the download methods.\n * @since 2.4.0\n */\nexport type FormatCsvParams = Pick<ExportParams, 'columns' | 'includeHeaders' | 'processCell' | 'processHeader'>;\n\n/**\n * Subset of {@link ExportParams} accepted by {@link ExportPlugin.formatExcel}.\n * Same shape as {@link FormatCsvParams} plus `excelStyles`.\n * @since 2.4.0\n */\nexport type FormatExcelParams = FormatCsvParams & Pick<ExportParams, 'excelStyles'>;\n\n/** Selection plugin state interface for type safety */\ninterface SelectionPluginState {\n selected: Set<number>;\n}\n\n/**\n * Export Plugin for tbw-grid\n *\n * Lets users download grid data as CSV, Excel (XML), or JSON with a single click\n * or API call. Great for reporting, data backup, or letting users work with data\n * in Excel. Integrates with SelectionPlugin to export only selected rows.\n *\n * ## Installation\n *\n * ```ts\n * import { ExportPlugin } from '@toolbox-web/grid/plugins/export';\n * ```\n *\n * ## Supported Formats\n *\n * | Format | Method | Description |\n * |--------|--------|-------------|\n * | CSV | `exportToCSV()` | Comma-separated values |\n * | Excel | `exportToExcel()` | Excel XML format (.xlsx) |\n * | JSON | `exportToJSON()` | JSON array of objects |\n *\n * @example Basic Export with Button\n * ```ts\n * import { queryGrid } from '@toolbox-web/grid';\n * import { ExportPlugin } from '@toolbox-web/grid/plugins/export';\n *\n * const grid = queryGrid('tbw-grid');\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', header: 'Name' },\n * { field: 'email', header: 'Email' },\n * ],\n * plugins: [new ExportPlugin({ fileName: 'employees', includeHeaders: true })],\n * };\n *\n * // Trigger export via button\n * document.getElementById('export-btn').addEventListener('click', () => {\n * grid.getPluginByName('export').exportToCSV();\n * });\n * ```\n *\n * @example Export Selected Rows Only\n * ```ts\n * import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';\n *\n * grid.gridConfig = {\n * plugins: [\n * new SelectionPlugin({ mode: 'row' }),\n * new ExportPlugin({ onlySelected: true }),\n * ],\n * };\n * ```\n *\n * @see {@link ExportConfig} for all configuration options\n * @see {@link ExportParams} for method parameters\n * @see SelectionPlugin for exporting selected rows\n *\n * @internal Extends BaseGridPlugin\n * @since 0.1.1\n */\nexport class ExportPlugin extends BaseGridPlugin<ExportConfig> {\n /**\n * Plugin manifest — declares queries for inter-plugin communication.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n queries: [{ type: 'export:csv', description: 'Triggers a CSV export' }],\n };\n\n /** @internal */\n readonly name = 'export';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ExportConfig> {\n return {\n fileName: 'export',\n includeHeaders: true,\n onlyVisible: true,\n onlySelected: false,\n };\n }\n\n // #region Internal State\n private isExportingFlag = false;\n private lastExportInfo: { format: ExportFormat; timestamp: Date } | null = null;\n // #endregion\n\n // #region Query System\n\n /** @internal */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'export:csv') {\n this.exportCsv();\n return true;\n }\n return undefined;\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Resolve the columns and rows that an export with these params would\n * include, plus a fully-defaulted ExportParams for downstream consumers.\n *\n * Honours `config.onlyVisible`, `config.onlySelected`, `params.columns`, and\n * `params.rowIndices`.\n */\n private resolveExportData(\n format: ExportFormat,\n params?: Partial<ExportParams>,\n ): { columns: ColumnConfig[]; rows: Record<string, unknown>[]; fullParams: ExportParams } {\n const config = this.config;\n\n const fullParams: ExportParams = {\n format,\n fileName: params?.fileName ?? config.fileName ?? 'export',\n includeHeaders: params?.includeHeaders ?? config.includeHeaders,\n processCell: params?.processCell,\n processHeader: params?.processHeader,\n mode: params?.mode ?? 'raw',\n columns: params?.columns,\n rowIndices: params?.rowIndices,\n excelStyles: params?.excelStyles,\n fileExtension: params?.fileExtension,\n };\n\n const columns = resolveColumns(this.columns, params?.columns, config.onlyVisible) as ColumnConfig[];\n\n let rows: Record<string, unknown>[];\n if (params?.rowIndices) {\n rows = resolveRows(this.rows as Record<string, unknown>[], params.rowIndices);\n } else if (config.onlySelected) {\n const selectionState = this.getSelectionState();\n if (selectionState?.selected?.size) {\n rows = resolveRows(this.rows as Record<string, unknown>[], [...selectionState.selected]);\n } else {\n rows = [...this.rows] as Record<string, unknown>[];\n }\n } else {\n rows = [...this.rows] as Record<string, unknown>[];\n }\n\n return { columns, rows, fullParams };\n }\n\n /**\n * Apply the configured export `mode` to a single cell value.\n *\n * - `'raw'` : returns the underlying value (after optional `processCell`).\n * - `'formatted'` : applies the column-type default formatter and `column.format`,\n * returning the same string the grid displays. `processCell`\n * runs last on the formatted value.\n */\n private resolveCellOutput(\n value: unknown,\n col: ColumnConfig,\n row: Record<string, unknown>,\n mode: ExportMode,\n processCell?: (value: any, field: string, row: any) => any,\n ): unknown {\n let out: unknown = value;\n\n if (mode === 'formatted') {\n const formatFn = this.#resolveFormatFn(col);\n if (formatFn) {\n try {\n const formatted = formatFn(value, row);\n out = formatted == null ? '' : String(formatted);\n } catch {\n out = value == null ? '' : String(value);\n }\n } else if (col.type === 'date') {\n out = formatDateValue(value);\n } else if (col.type === 'boolean') {\n out = !!value;\n } else {\n out = value;\n }\n }\n\n if (processCell) {\n out = processCell(out, col.field, row);\n }\n\n return out;\n }\n\n private performExport(format: ExportFormat, params?: Partial<ExportParams>): void {\n const { columns, rows, fullParams } = this.resolveExportData(format, params);\n\n this.isExportingFlag = true;\n let fileName = fullParams.fileName ?? 'export';\n\n // buildCsv / buildExcelXml read each cell via `resolveCellValue(row, col)`.\n // Our pre-resolved row objects are keyed by `column.field`, so any\n // `valueAccessor` on the column would misfire on these synthetic rows.\n // Strip accessors before delegating to keep the lookup as a plain field read.\n const downstreamColumns = this.#stripAccessors(columns);\n\n try {\n switch (format) {\n case 'csv': {\n const data = this.#buildExportData(rows, columns, fullParams);\n // processCell already applied during data resolution — strip it so buildCsv\n // doesn't double-apply.\n const content = buildCsv(data, downstreamColumns, { ...fullParams, processCell: undefined }, { bom: true });\n fileName = fileName.endsWith('.csv') ? fileName : `${fileName}.csv`;\n downloadCsv(content, fileName);\n break;\n }\n\n case 'excel': {\n const data = this.#buildExportData(rows, columns, fullParams);\n const content = buildExcelXml(data, downstreamColumns, { ...fullParams, processCell: undefined });\n const ext = fullParams.fileExtension ?? '.xls';\n const normalizedExt = ext.startsWith('.') ? ext : `.${ext}`;\n fileName = fileName.endsWith(normalizedExt) ? fileName : `${fileName}${normalizedExt}`;\n downloadExcel(content, fileName);\n break;\n }\n\n case 'json': {\n const data = this.#buildExportData(rows, columns, fullParams);\n const content = JSON.stringify(data, null, 2);\n fileName = fileName.endsWith('.json') ? fileName : `${fileName}.json`;\n const blob = new Blob([content], { type: 'application/json' });\n downloadBlob(blob, fileName);\n break;\n }\n }\n\n this.lastExportInfo = { format, timestamp: new Date() };\n\n this.emit<ExportCompleteDetail>('export-complete', {\n format,\n fileName,\n rowCount: rows.length,\n columnCount: columns.length,\n });\n } finally {\n this.isExportingFlag = false;\n }\n }\n\n /**\n * Resolve every cell into a plain object keyed by `column.field`, applying\n * the configured `mode` and `processCell` once. The result can be fed to\n * `buildCsv` / `buildExcelXml` directly — they read values via\n * `resolveCellValue`, which on plain key/value objects is a simple\n * `row[field]` lookup, so no double-resolution occurs.\n */\n #buildExportData(\n rows: Record<string, unknown>[],\n columns: ColumnConfig[],\n params: ExportParams,\n ): Record<string, unknown>[] {\n const mode = params.mode ?? 'raw';\n return rows.map((row) => {\n const obj: Record<string, unknown> = {};\n for (const col of columns) {\n const raw = resolveCellValue(row, col);\n obj[col.field] = this.resolveCellOutput(raw, col, row, mode, params.processCell);\n }\n return obj;\n });\n }\n\n private getSelectionState(): SelectionPluginState | null {\n try {\n return (this.grid?.getPluginState?.('selection') as SelectionPluginState | null) ?? null;\n } catch {\n return null;\n }\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Returns the row data that would be included in an export, without\n * producing a file. Honours `mode`, `onlyVisible`, `onlySelected`,\n * `columns`, `rowIndices`, `processCell`, and (for `mode: 'formatted'`)\n * `column.format`.\n *\n * Each returned object is keyed by `column.field` in column order.\n *\n * @example\n * ```ts\n * // Underlying typed values (Date stays Date, number stays number)\n * const raw = exporter.export();\n *\n * // What the user sees in each cell\n * const display = exporter.export({ mode: 'formatted' });\n * ```\n */\n export(params?: Partial<ExportParams>): Record<string, unknown>[] {\n const { columns, rows, fullParams } = this.resolveExportData('json', params);\n return this.#buildExportData(rows, columns, fullParams);\n }\n\n /**\n * Returns the columns (in order) that an export with these params would\n * include. Useful when handing rows to a third-party serializer that needs\n * header labels, widths, or types alongside the data.\n */\n getResolvedColumns(params?: Partial<ExportParams>): ColumnConfig[] {\n return resolveColumns(this.columns, params?.columns, this.config.onlyVisible) as ColumnConfig[];\n }\n\n /**\n * Format an array of row objects as a CSV string. Column order, headers,\n * and which fields to emit are taken from the plugin's resolved columns\n * (respecting `onlyVisible` and `params.columns`).\n *\n * This is a **pure formatter** — it does not re-resolve values from the\n * grid. Pass `data` produced by {@link ExportPlugin.export} (or any\n * compatible row objects keyed by `column.field`).\n *\n * `params.processCell` is honoured: it runs once per cell on the values in\n * `data`. `mode` is **not** accepted here — apply it upstream via\n * `export({ mode: 'formatted' })`.\n *\n * @example\n * ```ts\n * const csv = exporter.formatCsv(exporter.export());\n * await navigator.clipboard.writeText(csv);\n * ```\n */\n formatCsv(data: Record<string, unknown>[], params?: FormatCsvParams, options?: CsvOptions): string {\n const { columns, fullParams } = this.resolveExportData('csv', params);\n return buildCsv(data, this.#stripAccessors(columns), fullParams, options);\n }\n\n /**\n * Format an array of row objects as an Excel XML Spreadsheet 2003 string.\n * See {@link formatCsv} for the data-shape contract — this method is also a\n * pure formatter and `params.processCell` is honoured the same way.\n */\n formatExcel(data: Record<string, unknown>[], params?: FormatExcelParams): string {\n const { columns, fullParams } = this.resolveExportData('excel', params);\n return buildExcelXml(data, this.#stripAccessors(columns), fullParams);\n }\n\n /** @internal Drop `valueAccessor` so downstream builders read pre-resolved fields. */\n #stripAccessors(columns: ColumnConfig[]): ColumnConfig[] {\n return columns.map((c) => (c.valueAccessor ? ({ ...c, valueAccessor: undefined } as ColumnConfig) : c));\n }\n\n /**\n * @internal Resolve the format function for a column for `mode: 'formatted'`.\n * Mirrors the priority chain in core/internal/rows.ts (`column.format` → adapter\n * type default), but inlined so this module stays free of browser-only imports.\n */\n #resolveFormatFn(col: ColumnConfig): ((value: unknown, row: unknown) => string) | undefined {\n if (col.format) return col.format as (value: unknown, row: unknown) => string;\n if (!col.type) return undefined;\n // The grid host carries optional `__frameworkAdapter` and `_hostElement` from\n // InternalGrid. Narrow with a structural guard rather than an `as unknown as`\n // cast — these keys are documented public-internal in core/types.ts.\n const grid = this.grid as Partial<Pick<InternalGrid<unknown>, '__frameworkAdapter' | '_hostElement'>> | undefined;\n const adapter = grid?.__frameworkAdapter;\n if (!adapter?.getTypeDefault) return undefined;\n const appDefault = adapter.getTypeDefault(col.type, grid?._hostElement);\n return appDefault?.format as ((value: unknown, row: unknown) => string) | undefined;\n }\n\n /**\n * Export data to CSV format.\n * @param params - Optional export parameters\n */\n exportCsv(params?: Partial<ExportParams>): void {\n this.performExport('csv', params);\n }\n\n /**\n * Export data to Excel format (XML Spreadsheet).\n * @param params - Optional export parameters\n */\n exportExcel(params?: Partial<ExportParams>): void {\n this.performExport('excel', params);\n }\n\n /**\n * Export data to JSON format.\n * @param params - Optional export parameters\n */\n exportJson(params?: Partial<ExportParams>): void {\n this.performExport('json', params);\n }\n\n /**\n * Check if an export is currently in progress.\n * @returns Whether export is in progress\n */\n isExporting(): boolean {\n return this.isExportingFlag;\n }\n\n /**\n * Get information about the last export.\n * @returns Export info or null if no export has occurred\n */\n getLastExport(): { format: ExportFormat; timestamp: Date } | null {\n return this.lastExportInfo;\n }\n // #endregion\n}\n"],"names":["resolveColumns","columns","fields","onlyVisible","result","filter","c","hidden","field","startsWith","utility","length","fieldSet","Set","has","resolveRows","rows","indices","sort","a","b","map","i","r","formatCsvValue","value","quote","includes","replace","String","Date","toISOString","JSON","stringify","buildCsv","params","options","delimiter","newline","quoteStrings","lines","bom","includeHeaders","headerRow","col","header","processHeader","push","join","row","cells","resolveCellValue","processCell","downloadBlob","blob","fileName","url","URL","createObjectURL","link","document","createElement","href","download","style","display","body","appendChild","click","removeChild","revokeObjectURL","hashStyle","sortKeys","obj","Array","isArray","sorted","key","Object","keys","StyleRegistry","entries","Map","counter","register","hash","existing","this","get","id","set","getStyleId","size","toXml","xml","values","buildStyleElement","font","name","bold","italic","color","fill","pattern","numberFormat","alignment","horizontal","vertical","wrapText","borders","top","buildBorderElement","bottom","left","right","position","border","borderWeight","resolveDataStyleId","registry","config","cellStyle","dynamic","colStyle","columnStyles","defaultStyle","autoFitWidth","sampleSize","Math","min","maxLen","val","len","escapeXml","str","buildExcelXml","styles","excelStyles","headerStyle","buildStyleRegistry","widths","columnWidths","autoFit","autoFitColumns","width","buildColumnWidthsXml","headerStyleId","type","displayValue","isNaN","dataStyleId","ExportPlugin","BaseGridPlugin","static","queries","description","defaultConfig","onlySelected","isExportingFlag","lastExportInfo","handleQuery","query","exportCsv","resolveExportData","format","fullParams","mode","rowIndices","fileExtension","selectionState","getSelectionState","selected","resolveCellOutput","out","formatFn","resolveFormatFn","formatted","formatDateValue","performExport","downstreamColumns","stripAccessors","content","buildExportData","endsWith","Blob","downloadCsv","ext","normalizedExt","downloadExcel","data","timestamp","emit","rowCount","columnCount","raw","grid","getPluginState","getResolvedColumns","formatCsv","formatExcel","valueAccessor","adapter","__frameworkAdapter","getTypeDefault","appDefault","_hostElement","exportExcel","exportJson","isExporting","getLastExport"],"m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AiBnI,GACf,GAAIA,EAAIwH,OAAQ,OAAOxH,EAAIwH,OAC3B,IAAKxH,EAAIuG,KAAM,OAIf,MAAMgD,EAAO5G,KAAK4G,KACZM,EAAUN,GAAMO,mBACtB,IAAKD,GAASE,eAAgB,OAC9B,MAAMC,EAAaH,EAAQE,eAAe/J,EAAIuG,KAAMgD,GAAMU,cAC1D,OAAOD,GAAYxC,MACrB,CAMA,SAAAF,CAAU/H,GACRoD,KAAK2F,cAAc,MAAO/I,EAC5B,CAMA,WAAA2K,CAAY3K,GACVoD,KAAK2F,cAAc,QAAS/I,EAC9B,CAMA,UAAA4K,CAAW5K,GACToD,KAAK2F,cAAc,OAAQ/I,EAC7B,CAMA,WAAA6K,GACE,OAAOzH,KAAKuE,eACd,CAMA,aAAAmD,GACE,OAAO1H,KAAKwE,cACd"}
|
|
1
|
+
{"version":3,"file":"export.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/shared/data-collection.ts","../../../../../libs/grid/src/lib/plugins/export/csv.ts","../../../../../libs/grid/src/lib/plugins/export/excel-styles.ts","../../../../../libs/grid/src/lib/plugins/export/excel.ts","../../../../../libs/grid/src/lib/plugins/export/ExportPlugin.ts"],"sourcesContent":["/**\n * Shared Data Collection Utilities\n *\n * Pure functions for resolving columns and formatting values, shared between\n * the Clipboard and Export plugins. Each plugin bundles its own copy of this\n * module (no chunk splitting) since plugin builds inline sibling imports.\n *\n * @internal\n */\n\nimport type { ColumnConfig } from '../../core/types';\n\n/**\n * Resolve which columns to include in a data export or copy operation.\n *\n * Filters out hidden columns, utility columns (`meta.utility`), and\n * internal columns (`__`-prefixed fields). Optionally restricts to an\n * explicit set of field names.\n *\n * @param columns - All column configurations\n * @param fields - If provided, only include columns whose field is in this list\n * @param onlyVisible - When `true` (default), exclude hidden and internal columns\n * @returns Filtered column array preserving original order\n */\nexport function resolveColumns(\n columns: readonly ColumnConfig[],\n fields?: string[],\n onlyVisible = true,\n): ColumnConfig[] {\n let result = columns as ColumnConfig[];\n\n if (onlyVisible) {\n result = result.filter((c) => !c.hidden && !c.field.startsWith('__') && c.utility !== true);\n }\n\n if (fields?.length) {\n const fieldSet = new Set(fields);\n result = result.filter((c) => fieldSet.has(c.field));\n }\n\n return result;\n}\n\n/**\n * Resolve which rows to include, optionally filtered to specific indices.\n *\n * @param rows - All row data\n * @param indices - If provided, only include rows at these indices (sorted ascending)\n * @returns Filtered row array\n */\nexport function resolveRows<T>(rows: readonly T[], indices?: number[]): T[] {\n if (!indices?.length) return rows as T[];\n\n return [...indices]\n .sort((a, b) => a - b)\n .map((i) => rows[i])\n .filter((r): r is T => r != null);\n}\n\n/**\n * Format a raw cell value as a text string.\n *\n * Provides the common null / Date / object → string conversion shared by\n * both clipboard and export output builders.\n *\n * @param value - The cell value to format\n * @returns A plain-text representation of the value\n */\nexport function formatValueAsText(value: unknown): string {\n if (value == null) return '';\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n","/**\n * CSV Export Utilities\n *\n * Functions for building and downloading CSV content.\n */\n\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport type { ColumnConfig } from '../../core/types';\nimport type { ExportParams } from './types';\n\n/** CSV export options * @since 0.1.1\n */\nexport interface CsvOptions {\n /** Field delimiter (default: ',') */\n delimiter?: string;\n /** Line separator (default: '\\n') */\n newline?: string;\n /** Whether to quote strings containing special characters (default: true) */\n quoteStrings?: boolean;\n /** Add UTF-8 BOM for Excel compatibility (default: false) */\n bom?: boolean;\n}\n\n/**\n * Format a value for CSV output.\n * Handles null, Date, objects, and strings with special characters.\n *\n * Dispatch order is `typeof`-first because string + number cover the vast\n * majority of cell values; the cheap typeof check skips an `instanceof Date`\n * probe (which V8 cannot fold into a fast path) for every plain string cell.\n */\nexport function formatCsvValue(value: any, quote = true): string {\n // Hot path: strings (most CSV cells).\n if (typeof value === 'string') {\n if (quote && (value.includes(',') || value.includes('\"') || value.includes('\\n') || value.includes('\\r'))) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`;\n }\n return value;\n }\n if (typeof value === 'number') return String(value);\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n if (value == null) return '';\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'object') return JSON.stringify(value);\n // Symbols, bigints, etc.\n return String(value);\n}\n\n/**\n * Build CSV content from rows and columns.\n */\nexport function buildCsv(rows: any[], columns: ColumnConfig[], params: ExportParams, options: CsvOptions = {}): string {\n const delimiter = options.delimiter ?? ',';\n const newline = options.newline ?? '\\n';\n const quote = options.quoteStrings ?? true;\n const lines: string[] = [];\n\n // UTF-8 BOM for Excel compatibility\n const bom = options.bom ? '\\uFEFF' : '';\n\n // Build header row\n if (params.includeHeaders !== false) {\n const headerRow = columns.map((col) => {\n const header = col.header || col.field;\n const processed = params.processHeader ? params.processHeader(header, col.field) : header;\n return formatCsvValue(processed, quote);\n });\n lines.push(headerRow.join(delimiter));\n }\n\n // Build data rows\n for (const row of rows) {\n const cells = columns.map((col) => {\n let value = resolveCellValue(row, col);\n if (params.processCell) {\n value = params.processCell(value, col.field, row);\n }\n return formatCsvValue(value, quote);\n });\n lines.push(cells.join(delimiter));\n }\n\n return bom + lines.join(newline);\n}\n\n/**\n * Download a Blob as a file.\n */\nexport function downloadBlob(blob: Blob, fileName: string): void {\n const url = URL.createObjectURL(blob);\n const link = document.createElement('a');\n link.href = url;\n link.download = fileName;\n link.style.display = 'none';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n URL.revokeObjectURL(url);\n}\n\n/**\n * Download CSV content as a file.\n */\nexport function downloadCsv(content: string, fileName: string): void {\n const blob = new Blob([content], { type: 'text/csv;charset=utf-8;' });\n downloadBlob(blob, fileName);\n}\n","/**\n * Excel Style Engine\n *\n * Builds a deduplicated `<Styles>` block for XML Spreadsheet 2003.\n * Collects unique ExcelCellStyle objects, assigns ss:StyleID values,\n * and generates the corresponding XML.\n */\n\nimport type { ExcelBorder, ExcelCellStyle, ExcelStyleConfig } from './types';\n\n// #region Style Hashing\n\n/**\n * Produce a deterministic string key for a style object.\n * Two structurally identical styles produce the same hash.\n * Recursively sorts object keys for order-independent comparison.\n */\nfunction hashStyle(style: ExcelCellStyle): string {\n return JSON.stringify(sortKeys(style));\n}\n\n/** Recursively sort object keys for deterministic serialization. */\nfunction sortKeys(obj: unknown): unknown {\n if (obj == null || typeof obj !== 'object') return obj;\n if (Array.isArray(obj)) return obj.map(sortKeys);\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n sorted[key] = sortKeys((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n}\n\n// #endregion\n\n// #region Style Registry\n\n/** Maps a hash → style ID and the original style. */\nexport interface StyleEntry {\n id: string;\n style: ExcelCellStyle;\n}\n\n/**\n * Collects unique styles and assigns each an `ss:StyleID`.\n * Register styles via `register()`, then call `getStyleId()` to look up\n * the ID for a given style, and `toXml()` to emit the `<Styles>` block.\n */\nexport class StyleRegistry {\n /** hash → StyleEntry */\n #entries = new Map<string, StyleEntry>();\n #counter = 0;\n\n /**\n * Register a style and return its assigned ID.\n * If an identical style was already registered, returns the existing ID.\n */\n register(style: ExcelCellStyle): string {\n const hash = hashStyle(style);\n const existing = this.#entries.get(hash);\n if (existing) return existing.id;\n\n this.#counter++;\n const id = `s${this.#counter}`;\n this.#entries.set(hash, { id, style });\n return id;\n }\n\n /** Look up the ID previously assigned to a style (or undefined). */\n getStyleId(style: ExcelCellStyle): string | undefined {\n return this.#entries.get(hashStyle(style))?.id;\n }\n\n /** Number of unique styles registered so far. */\n get size(): number {\n return this.#entries.size;\n }\n\n /** Emit the full `<Styles>…</Styles>` XML fragment, or empty string if no styles. */\n toXml(): string {\n if (this.#entries.size === 0) return '';\n\n let xml = '\\n<Styles>';\n for (const { id, style } of this.#entries.values()) {\n xml += buildStyleElement(id, style);\n }\n xml += '\\n</Styles>';\n return xml;\n }\n}\n\n// #endregion\n\n// #region XML Builders\n\nfunction buildStyleElement(id: string, style: ExcelCellStyle): string {\n let xml = `\\n<Style ss:ID=\"${id}\">`;\n\n if (style.font) {\n xml += '<Font';\n if (style.font.name) xml += ` ss:FontName=\"${style.font.name}\"`;\n if (style.font.size) xml += ` ss:Size=\"${style.font.size}\"`;\n if (style.font.bold) xml += ' ss:Bold=\"1\"';\n if (style.font.italic) xml += ' ss:Italic=\"1\"';\n if (style.font.color) xml += ` ss:Color=\"${style.font.color}\"`;\n xml += '/>';\n }\n\n if (style.fill) {\n const pattern = style.fill.pattern ?? 'Solid';\n xml += `<Interior ss:Color=\"${style.fill.color}\" ss:Pattern=\"${pattern}\"/>`;\n }\n\n if (style.numberFormat) {\n xml += `<NumberFormat ss:Format=\"${style.numberFormat}\"/>`;\n }\n\n if (style.alignment) {\n xml += '<Alignment';\n if (style.alignment.horizontal) xml += ` ss:Horizontal=\"${style.alignment.horizontal}\"`;\n if (style.alignment.vertical) xml += ` ss:Vertical=\"${style.alignment.vertical}\"`;\n if (style.alignment.wrapText) xml += ' ss:WrapText=\"1\"';\n xml += '/>';\n }\n\n if (style.borders) {\n xml += '<Borders>';\n if (style.borders.top) xml += buildBorderElement('Top', style.borders.top);\n if (style.borders.bottom) xml += buildBorderElement('Bottom', style.borders.bottom);\n if (style.borders.left) xml += buildBorderElement('Left', style.borders.left);\n if (style.borders.right) xml += buildBorderElement('Right', style.borders.right);\n xml += '</Borders>';\n }\n\n xml += '</Style>';\n return xml;\n}\n\nfunction buildBorderElement(position: string, border: ExcelBorder): string {\n let xml = `<Border ss:Position=\"${position}\" ss:LineStyle=\"Continuous\" ss:Weight=\"${borderWeight(border.style)}\"`;\n if (border.color) xml += ` ss:Color=\"${border.color}\"`;\n xml += '/>';\n return xml;\n}\n\nfunction borderWeight(style: ExcelBorder['style']): number {\n switch (style) {\n case 'Thin':\n return 1;\n case 'Medium':\n return 2;\n case 'Thick':\n return 3;\n }\n}\n\n// #endregion\n\n// #region Style Resolution\n\n/**\n * Build a StyleRegistry pre-populated with all styles declared in the config.\n * This covers headerStyle, defaultStyle, and columnStyles.\n * (cellStyle callbacks are resolved per-cell at render time.)\n */\nexport function buildStyleRegistry(config: ExcelStyleConfig): StyleRegistry {\n const registry = new StyleRegistry();\n\n if (config.headerStyle) registry.register(config.headerStyle);\n\n if (config.groupHeaderStyle) registry.register(config.groupHeaderStyle);\n\n if (config.defaultStyle) registry.register(config.defaultStyle);\n\n if (config.columnStyles) {\n for (const style of Object.values(config.columnStyles)) {\n registry.register(style);\n }\n }\n\n return registry;\n}\n\n/**\n * Resolve the style ID for a data cell. Precedence (highest → lowest):\n * 1. cellStyle callback return value\n * 2. columnStyles[field]\n * 3. defaultStyle\n */\nexport function resolveDataStyleId(\n registry: StyleRegistry,\n config: ExcelStyleConfig,\n value: unknown,\n field: string,\n row: unknown,\n): string | undefined {\n // 1. Dynamic cell callback\n if (config.cellStyle) {\n const dynamic = config.cellStyle(value, field, row);\n if (dynamic) {\n // Register on-the-fly (dedup handles repeats)\n return registry.register(dynamic);\n }\n }\n\n // 2. Per-column override\n const colStyle = config.columnStyles?.[field];\n if (colStyle) return registry.getStyleId(colStyle);\n\n // 3. Default\n if (config.defaultStyle) return registry.getStyleId(config.defaultStyle);\n\n return undefined;\n}\n\n// #endregion\n\n// #region Column Widths\n\n/** Character width → Excel column width approximation (px ≈ chars × 7) */\nconst CHAR_WIDTH = 7;\n\n/**\n * Build `<Column>` elements for explicit or auto-fit widths.\n */\nexport function buildColumnWidthsXml(\n columns: { field: string; header?: string }[],\n rows: Record<string, unknown>[],\n config: ExcelStyleConfig,\n): string {\n const widths = config.columnWidths;\n const autoFit = config.autoFitColumns;\n\n if (!widths && !autoFit) return '';\n\n let xml = '';\n for (const col of columns) {\n let width: number | undefined = widths?.[col.field];\n\n if (width == null && autoFit) {\n width = autoFitWidth(col, rows);\n }\n\n if (width != null) {\n xml += `\\n<Column ss:Width=\"${width * CHAR_WIDTH}\"/>`;\n } else {\n // Emit an empty column entry to keep ordinal alignment\n xml += '\\n<Column/>';\n }\n }\n\n return xml;\n}\n\n/** Estimate width from header + first N data rows (capped at 50). */\nfunction autoFitWidth(col: { field: string; header?: string }, rows: Record<string, unknown>[]): number {\n const sampleSize = Math.min(rows.length, 50);\n let maxLen = (col.header ?? col.field).length;\n\n for (let i = 0; i < sampleSize; i++) {\n const val = rows[i][col.field];\n const len = val == null ? 0 : String(val).length;\n if (len > maxLen) maxLen = len;\n }\n\n // Add a small padding\n return maxLen + 2;\n}\n\n// #endregion\n","/**\n * Excel Export Utilities\n *\n * Simple Excel XML format export (no external dependencies).\n * Produces XML Spreadsheet 2003 format which opens in Excel.\n */\n\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport type { ColumnConfig } from '../../core/types';\nimport { downloadBlob } from './csv';\nimport { buildColumnWidthsXml, buildStyleRegistry, resolveDataStyleId } from './excel-styles';\nimport type { ExportParams } from './types';\n\n/**\n * Escape XML special characters.\n */\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * Build Excel XML content from rows and columns.\n * Uses XML Spreadsheet 2003 format for broad compatibility.\n */\nexport function buildExcelXml(rows: any[], columns: ColumnConfig[], params: ExportParams): string {\n const styles = params.excelStyles;\n const registry = styles ? buildStyleRegistry(styles) : undefined;\n\n let xml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">`;\n\n // Emit <Styles> block (only when styles are configured)\n if (registry) {\n // Pre-register dynamic cellStyle entries so they appear in <Styles>\n if (styles!.cellStyle) {\n for (const row of rows) {\n for (const col of columns) {\n const value = resolveCellValue(row, col);\n const dynamic = styles!.cellStyle(value, col.field, row);\n if (dynamic) registry.register(dynamic);\n }\n }\n }\n xml += registry.toXml();\n }\n\n xml += '\\n<Worksheet ss:Name=\"Sheet1\">\\n<Table>';\n\n // Column widths\n if (styles) {\n xml += buildColumnWidthsXml(columns, rows as Record<string, unknown>[], styles);\n }\n\n // Header style ID\n const headerStyleId = styles?.headerStyle && registry ? registry.getStyleId(styles.headerStyle) : undefined;\n // Group-header style ID (for plugin-contributed rows). Falls back to\n // headerStyleId so users get sensible defaults without configuring twice.\n const groupHeaderStyleId =\n styles?.groupHeaderStyle && registry ? registry.getStyleId(styles.groupHeaderStyle) : headerStyleId;\n\n // Build plugin-contributed header rows (e.g. column groups) above the leaf\n // header. Each row's cells must independently span the full column count;\n // `span > 1` becomes `ss:MergeAcross=\"span-1\"` and we skip the next\n // `span-1` cell slots (Excel implicitly fills them from the merge).\n if (params.includeHeaders !== false && params.headerRows && params.headerRows.length > 0) {\n const styleAttr = groupHeaderStyleId ? ` ss:StyleID=\"${groupHeaderStyleId}\"` : '';\n for (const headerRow of params.headerRows) {\n xml += '\\n<Row>';\n for (const cell of headerRow.cells) {\n const span = Math.max(1, cell.span | 0);\n const mergeAttr = span > 1 ? ` ss:MergeAcross=\"${span - 1}\"` : '';\n xml += `<Cell${styleAttr}${mergeAttr}><Data ss:Type=\"String\">${escapeXml(cell.label ?? '')}</Data></Cell>`;\n }\n xml += '</Row>';\n }\n }\n\n // Build header row\n if (params.includeHeaders !== false) {\n xml += '\\n<Row>';\n for (const col of columns) {\n const header = col.header || col.field;\n const processed = params.processHeader ? params.processHeader(header, col.field) : header;\n const styleAttr = headerStyleId ? ` ss:StyleID=\"${headerStyleId}\"` : '';\n xml += `<Cell${styleAttr}><Data ss:Type=\"String\">${escapeXml(processed)}</Data></Cell>`;\n }\n xml += '</Row>';\n }\n\n // Build data rows\n for (const row of rows) {\n xml += '\\n<Row>';\n for (const col of columns) {\n let value = resolveCellValue(row, col);\n if (params.processCell) {\n value = params.processCell(value, col.field, row);\n }\n\n // Determine cell type based on value\n let type: 'Number' | 'String' | 'DateTime' = 'String';\n let displayValue = '';\n\n if (value == null) {\n displayValue = '';\n } else if (typeof value === 'number' && !isNaN(value)) {\n type = 'Number';\n displayValue = String(value);\n } else if (value instanceof Date) {\n type = 'DateTime';\n displayValue = value.toISOString();\n } else {\n displayValue = escapeXml(String(value));\n }\n\n // Resolve data cell style\n const dataStyleId = registry && styles ? resolveDataStyleId(registry, styles, value, col.field, row) : undefined;\n const styleAttr = dataStyleId ? ` ss:StyleID=\"${dataStyleId}\"` : '';\n\n xml += `<Cell${styleAttr}><Data ss:Type=\"${type}\">${displayValue}</Data></Cell>`;\n }\n xml += '</Row>';\n }\n\n xml += '\\n</Table>\\n</Worksheet>\\n</Workbook>';\n return xml;\n}\n\n/**\n * Download Excel XML content as a file.\n */\nexport function downloadExcel(content: string, fileName: string): void {\n const blob = new Blob([content], {\n type: 'application/vnd.ms-excel;charset=utf-8;',\n });\n downloadBlob(blob, fileName);\n}\n","/**\n * Export Plugin (Class-based)\n *\n * Provides data export functionality for tbw-grid.\n * Supports CSV, Excel (XML), and JSON formats.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { formatDateValue } from '../../core/internal/utils';\nimport { resolveCellValue } from '../../core/internal/value-accessor';\nimport { BaseGridPlugin, type PluginManifest, type PluginQuery } from '../../core/plugin/base-plugin';\nimport { type CollectHeaderRowsContext, type HeaderRowCell, type HeaderRowContribution } from '../../core/plugin/types';\nimport type { ColumnConfig, InternalGrid } from '../../core/types';\nimport { resolveColumns, resolveRows } from '../shared/data-collection';\nimport { buildCsv, type CsvOptions, downloadBlob, downloadCsv } from './csv';\nimport { buildExcelXml, downloadExcel } from './excel';\nimport type { ExportCompleteDetail, ExportConfig, ExportFormat, ExportMode, ExportParams } from './types';\n\n/**\n * Subset of {@link ExportParams} accepted by the pure formatters\n * ({@link ExportPlugin.formatCsv} / {@link ExportPlugin.formatExcel}).\n *\n * The formatters operate on already-resolved data, so options that affect\n * value resolution (`mode`, `rowIndices`, `format`, `fileName`,\n * `fileExtension`) are intentionally excluded — if you need them, run them\n * through {@link ExportPlugin.export} first or call the download/export\n * methods.\n *\n * `processCell` **is** honoured: it runs once per cell on the values you pass\n * in, just like the download methods.\n * @since 2.4.0\n */\nexport type FormatCsvParams = Pick<ExportParams, 'columns' | 'includeHeaders' | 'processCell' | 'processHeader'>;\n\n/**\n * Subset of {@link ExportParams} accepted by {@link ExportPlugin.formatExcel}.\n * Same shape as {@link FormatCsvParams} plus `excelStyles`.\n * @since 2.4.0\n */\nexport type FormatExcelParams = FormatCsvParams & Pick<ExportParams, 'excelStyles'>;\n\n/** Selection plugin state interface for type safety */\ninterface SelectionPluginState {\n selected: Set<number>;\n}\n\n/**\n * Export Plugin for tbw-grid\n *\n * Lets users download grid data as CSV, Excel (XML), or JSON with a single click\n * or API call. Great for reporting, data backup, or letting users work with data\n * in Excel. Integrates with SelectionPlugin to export only selected rows.\n *\n * ## Installation\n *\n * ```ts\n * import { ExportPlugin } from '@toolbox-web/grid/plugins/export';\n * ```\n *\n * ## Supported Formats\n *\n * | Format | Method | Description |\n * |--------|--------|-------------|\n * | CSV | `exportToCSV()` | Comma-separated values |\n * | Excel | `exportToExcel()` | Excel XML format (.xlsx) |\n * | JSON | `exportToJSON()` | JSON array of objects |\n *\n * @example Basic Export with Button\n * ```ts\n * import { queryGrid } from '@toolbox-web/grid';\n * import { ExportPlugin } from '@toolbox-web/grid/plugins/export';\n *\n * const grid = queryGrid('tbw-grid');\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', header: 'Name' },\n * { field: 'email', header: 'Email' },\n * ],\n * plugins: [new ExportPlugin({ fileName: 'employees', includeHeaders: true })],\n * };\n *\n * // Trigger export via button\n * document.getElementById('export-btn').addEventListener('click', () => {\n * grid.getPluginByName('export').exportToCSV();\n * });\n * ```\n *\n * @example Export Selected Rows Only\n * ```ts\n * import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';\n *\n * grid.gridConfig = {\n * plugins: [\n * new SelectionPlugin({ mode: 'row' }),\n * new ExportPlugin({ onlySelected: true }),\n * ],\n * };\n * ```\n *\n * @see {@link ExportConfig} for all configuration options\n * @see {@link ExportParams} for method parameters\n * @see SelectionPlugin for exporting selected rows\n *\n * @internal Extends BaseGridPlugin\n * @since 0.1.1\n */\nexport class ExportPlugin extends BaseGridPlugin<ExportConfig> {\n /**\n * Plugin manifest — declares queries for inter-plugin communication.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n queries: [{ type: 'export:csv', description: 'Triggers a CSV export' }],\n };\n\n /** @internal */\n readonly name = 'export';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ExportConfig> {\n return {\n fileName: 'export',\n includeHeaders: true,\n onlyVisible: true,\n onlySelected: false,\n };\n }\n\n // #region Internal State\n private isExportingFlag = false;\n private lastExportInfo: { format: ExportFormat; timestamp: Date } | null = null;\n // #endregion\n\n // #region Query System\n\n /** @internal */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'export:csv') {\n this.exportCsv();\n return true;\n }\n return undefined;\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Resolve the columns and rows that an export with these params would\n * include, plus a fully-defaulted ExportParams for downstream consumers.\n *\n * Honours `config.onlyVisible`, `config.onlySelected`, `params.columns`, and\n * `params.rowIndices`.\n */\n private resolveExportData(\n format: ExportFormat,\n params?: Partial<ExportParams>,\n ): { columns: ColumnConfig[]; rows: Record<string, unknown>[]; fullParams: ExportParams } {\n const config = this.config;\n\n const fullParams: ExportParams = {\n format,\n fileName: params?.fileName ?? config.fileName ?? 'export',\n includeHeaders: params?.includeHeaders ?? config.includeHeaders,\n processCell: params?.processCell,\n processHeader: params?.processHeader,\n processHeaderRow: params?.processHeaderRow,\n mode: params?.mode ?? 'raw',\n columns: params?.columns,\n rowIndices: params?.rowIndices,\n excelStyles: params?.excelStyles,\n fileExtension: params?.fileExtension,\n headerRows: params?.headerRows,\n };\n\n const columns = resolveColumns(this.columns, params?.columns, config.onlyVisible) as ColumnConfig[];\n\n let rows: Record<string, unknown>[];\n if (params?.rowIndices) {\n rows = resolveRows(this.rows as Record<string, unknown>[], params.rowIndices);\n } else if (config.onlySelected) {\n const selectionState = this.getSelectionState();\n if (selectionState?.selected?.size) {\n rows = resolveRows(this.rows as Record<string, unknown>[], [...selectionState.selected]);\n } else {\n rows = [...this.rows] as Record<string, unknown>[];\n }\n } else {\n rows = [...this.rows] as Record<string, unknown>[];\n }\n\n // Resolve header rows.\n //\n // Two entry paths:\n // 1. Auto-collect: broadcast `collectHeaderRows` to all plugins.\n // 2. Manual: caller passed `params.headerRows` directly (typical for\n // pure-formatter usage where there's no grid to query).\n //\n // Both paths run through the same processing pipeline so\n // `processHeaderRow`, span validation, and blank-row dropping behave\n // identically regardless of how the rows arrived.\n //\n // All gated on `includeHeaders`: `false` skips both leaf AND contributed\n // rows (all-or-nothing per #314 design).\n if (fullParams.includeHeaders === false) {\n fullParams.headerRows = undefined;\n } else {\n const raw = fullParams.headerRows ?? this.#collectHeaderRows(columns);\n fullParams.headerRows = this.#processHeaderRows(raw, columns, fullParams.processHeaderRow);\n }\n\n return { columns, rows, fullParams };\n }\n\n /**\n * Broadcast the `'collectHeaderRows'` query to all plugins and flatten the\n * responses. Each plugin may return a single contribution or an array of\n * contributions (one per row) — both shapes are flattened to a single\n * `HeaderRowContribution[]`.\n */\n #collectHeaderRows(columns: ColumnConfig[]): HeaderRowContribution[] {\n if (columns.length === 0) return [];\n const grid = this.grid as { query?: <T>(type: string, context: CollectHeaderRowsContext) => T[] } | undefined;\n if (!grid?.query) return [];\n const responses = grid.query<HeaderRowContribution | HeaderRowContribution[] | undefined>('collectHeaderRows', {\n columns,\n });\n if (!responses || responses.length === 0) return [];\n const flat: HeaderRowContribution[] = [];\n for (const r of responses) {\n if (!r) continue;\n if (Array.isArray(r)) {\n for (const row of r) {\n if (row && Array.isArray(row.cells) && row.cells.length > 0) flat.push(row);\n }\n } else if (Array.isArray(r.cells) && r.cells.length > 0) {\n flat.push(r);\n }\n }\n return flat;\n }\n\n /**\n * Normalize, validate, and filter a list of header-row contributions.\n *\n * - Applies the optional `processHeaderRow` callback per cell. `null`\n * returns blank the cell (span preserved); rows where every cell ends\n * up blank are dropped (`#314` \"collapse fully-blank row\" rule).\n * - Validates that each row's spans sum to `columns.length`. Rows that\n * under-fill are padded with a trailing blank cell; rows that\n * over-fill (malformed third-party contribution) are skipped to keep\n * downstream formatters structurally sound.\n *\n * Returns `undefined` (not `[]`) when no row survives so downstream\n * formatters can short-circuit with a single `headerRows?.length` check.\n */\n #processHeaderRows(\n rows: HeaderRowContribution[] | undefined,\n columns: ColumnConfig[],\n processHeaderRow?: (cell: HeaderRowCell, rowIndex: number) => HeaderRowCell | null,\n ): HeaderRowContribution[] | undefined {\n if (!rows || rows.length === 0) return undefined;\n const expectedSpan = columns.length;\n\n const processed: HeaderRowContribution[] = [];\n for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {\n const row = rows[rowIndex];\n if (!row || !Array.isArray(row.cells) || row.cells.length === 0) continue;\n\n const outCells: HeaderRowCell[] = [];\n let anyVisible = false;\n let runningSpan = 0;\n let overflowed = false;\n for (const cell of row.cells) {\n const span = Math.max(1, cell.span | 0);\n if (runningSpan + span > expectedSpan) {\n // Malformed: cumulative span exceeds column count. Skip the row.\n overflowed = true;\n break;\n }\n runningSpan += span;\n const next = processHeaderRow ? processHeaderRow(cell, rowIndex) : cell;\n if (next === null) {\n outCells.push({ label: '', span });\n } else {\n outCells.push({ ...next, span });\n if ((next.label ?? '') !== '') anyVisible = true;\n }\n }\n if (overflowed) continue;\n // Pad under-filled rows with a trailing blank cell so leaf headers\n // stay aligned. (A well-behaved contribution from the grouping plugin\n // always fully covers `columns.length`; this guards against\n // third-party plugins that drift.)\n if (runningSpan < expectedSpan) {\n outCells.push({ label: '', span: expectedSpan - runningSpan });\n }\n if (anyVisible) processed.push({ cells: outCells });\n // else: every cell collapsed → row dropped.\n }\n\n return processed.length > 0 ? processed : undefined;\n }\n\n /**\n * Apply the configured export `mode` to a single cell value.\n *\n * - `'raw'` : returns the underlying value (after optional `processCell`).\n * - `'formatted'` : applies the column-type default formatter and `column.format`,\n * returning the same string the grid displays. `processCell`\n * runs last on the formatted value.\n */\n private resolveCellOutput(\n value: unknown,\n col: ColumnConfig,\n row: Record<string, unknown>,\n mode: ExportMode,\n processCell?: (value: any, field: string, row: any) => any,\n ): unknown {\n let out: unknown = value;\n\n if (mode === 'formatted') {\n const formatFn = this.#resolveFormatFn(col);\n if (formatFn) {\n try {\n const formatted = formatFn(value, row);\n out = formatted == null ? '' : String(formatted);\n } catch {\n out = value == null ? '' : String(value);\n }\n } else if (col.type === 'date') {\n out = formatDateValue(value);\n } else if (col.type === 'boolean') {\n out = !!value;\n } else {\n out = value;\n }\n }\n\n if (processCell) {\n out = processCell(out, col.field, row);\n }\n\n return out;\n }\n\n private performExport(format: ExportFormat, params?: Partial<ExportParams>): void {\n const { columns, rows, fullParams } = this.resolveExportData(format, params);\n\n this.isExportingFlag = true;\n let fileName = fullParams.fileName ?? 'export';\n\n // buildCsv / buildExcelXml read each cell via `resolveCellValue(row, col)`.\n // Our pre-resolved row objects are keyed by `column.field`, so any\n // `valueAccessor` on the column would misfire on these synthetic rows.\n // Strip accessors before delegating to keep the lookup as a plain field read.\n const downstreamColumns = this.#stripAccessors(columns);\n\n try {\n switch (format) {\n case 'csv': {\n const data = this.#buildExportData(rows, columns, fullParams);\n // processCell already applied during data resolution — strip it so buildCsv\n // doesn't double-apply.\n const content = buildCsv(data, downstreamColumns, { ...fullParams, processCell: undefined }, { bom: true });\n fileName = fileName.endsWith('.csv') ? fileName : `${fileName}.csv`;\n downloadCsv(content, fileName);\n break;\n }\n\n case 'excel': {\n const data = this.#buildExportData(rows, columns, fullParams);\n const content = buildExcelXml(data, downstreamColumns, { ...fullParams, processCell: undefined });\n const ext = fullParams.fileExtension ?? '.xls';\n const normalizedExt = ext.startsWith('.') ? ext : `.${ext}`;\n fileName = fileName.endsWith(normalizedExt) ? fileName : `${fileName}${normalizedExt}`;\n downloadExcel(content, fileName);\n break;\n }\n\n case 'json': {\n const data = this.#buildExportData(rows, columns, fullParams);\n // When plugins contributed header rows (e.g. column groups), emit an\n // envelope `{ headerRows, rows }` so consumers can reconstruct\n // multi-level headers. Without contributions the output stays a flat\n // array — non-breaking for existing JSON consumers.\n const payload =\n fullParams.headerRows && fullParams.headerRows.length > 0\n ? { headerRows: fullParams.headerRows, rows: data }\n : data;\n const content = JSON.stringify(payload, null, 2);\n fileName = fileName.endsWith('.json') ? fileName : `${fileName}.json`;\n const blob = new Blob([content], { type: 'application/json' });\n downloadBlob(blob, fileName);\n break;\n }\n }\n\n this.lastExportInfo = { format, timestamp: new Date() };\n\n this.emit<ExportCompleteDetail>('export-complete', {\n format,\n fileName,\n rowCount: rows.length,\n columnCount: columns.length,\n });\n } finally {\n this.isExportingFlag = false;\n }\n }\n\n /**\n * Resolve every cell into a plain object keyed by `column.field`, applying\n * the configured `mode` and `processCell` once. The result can be fed to\n * `buildCsv` / `buildExcelXml` directly — they read values via\n * `resolveCellValue`, which on plain key/value objects is a simple\n * `row[field]` lookup, so no double-resolution occurs.\n */\n #buildExportData(\n rows: Record<string, unknown>[],\n columns: ColumnConfig[],\n params: ExportParams,\n ): Record<string, unknown>[] {\n const mode = params.mode ?? 'raw';\n return rows.map((row) => {\n const obj: Record<string, unknown> = {};\n for (const col of columns) {\n const raw = resolveCellValue(row, col);\n obj[col.field] = this.resolveCellOutput(raw, col, row, mode, params.processCell);\n }\n return obj;\n });\n }\n\n private getSelectionState(): SelectionPluginState | null {\n try {\n return (this.grid?.getPluginState?.('selection') as SelectionPluginState | null) ?? null;\n } catch {\n return null;\n }\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Returns the row data that would be included in an export, without\n * producing a file. Honours `mode`, `onlyVisible`, `onlySelected`,\n * `columns`, `rowIndices`, `processCell`, and (for `mode: 'formatted'`)\n * `column.format`.\n *\n * Each returned object is keyed by `column.field` in column order.\n *\n * @example\n * ```ts\n * // Underlying typed values (Date stays Date, number stays number)\n * const raw = exporter.export();\n *\n * // What the user sees in each cell\n * const display = exporter.export({ mode: 'formatted' });\n * ```\n */\n export(params?: Partial<ExportParams>): Record<string, unknown>[] {\n const { columns, rows, fullParams } = this.resolveExportData('json', params);\n return this.#buildExportData(rows, columns, fullParams);\n }\n\n /**\n * Returns the columns (in order) that an export with these params would\n * include. Useful when handing rows to a third-party serializer that needs\n * header labels, widths, or types alongside the data.\n */\n getResolvedColumns(params?: Partial<ExportParams>): ColumnConfig[] {\n return resolveColumns(this.columns, params?.columns, this.config.onlyVisible) as ColumnConfig[];\n }\n\n /**\n * Format an array of row objects as a CSV string. Column order, headers,\n * and which fields to emit are taken from the plugin's resolved columns\n * (respecting `onlyVisible` and `params.columns`).\n *\n * This is a **pure formatter** — it does not re-resolve values from the\n * grid. Pass `data` produced by {@link ExportPlugin.export} (or any\n * compatible row objects keyed by `column.field`).\n *\n * `params.processCell` is honoured: it runs once per cell on the values in\n * `data`. `mode` is **not** accepted here — apply it upstream via\n * `export({ mode: 'formatted' })`.\n *\n * @example\n * ```ts\n * const csv = exporter.formatCsv(exporter.export());\n * await navigator.clipboard.writeText(csv);\n * ```\n */\n formatCsv(data: Record<string, unknown>[], params?: FormatCsvParams, options?: CsvOptions): string {\n const { columns, fullParams } = this.resolveExportData('csv', params);\n return buildCsv(data, this.#stripAccessors(columns), fullParams, options);\n }\n\n /**\n * Format an array of row objects as an Excel XML Spreadsheet 2003 string.\n * See {@link formatCsv} for the data-shape contract — this method is also a\n * pure formatter and `params.processCell` is honoured the same way.\n */\n formatExcel(data: Record<string, unknown>[], params?: FormatExcelParams): string {\n const { columns, fullParams } = this.resolveExportData('excel', params);\n return buildExcelXml(data, this.#stripAccessors(columns), fullParams);\n }\n\n /** @internal Drop `valueAccessor` so downstream builders read pre-resolved fields. */\n #stripAccessors(columns: ColumnConfig[]): ColumnConfig[] {\n return columns.map((c) => (c.valueAccessor ? ({ ...c, valueAccessor: undefined } as ColumnConfig) : c));\n }\n\n /**\n * @internal Resolve the format function for a column for `mode: 'formatted'`.\n * Mirrors the priority chain in core/internal/rows.ts (`column.format` → adapter\n * type default), but inlined so this module stays free of browser-only imports.\n */\n #resolveFormatFn(col: ColumnConfig): ((value: unknown, row: unknown) => string) | undefined {\n if (col.format) return col.format as (value: unknown, row: unknown) => string;\n if (!col.type) return undefined;\n // The grid host carries optional `__frameworkAdapter` and `_hostElement` from\n // InternalGrid. Narrow with a structural guard rather than an `as unknown as`\n // cast — these keys are documented public-internal in core/types.ts.\n const grid = this.grid as Partial<Pick<InternalGrid<unknown>, '__frameworkAdapter' | '_hostElement'>> | undefined;\n const adapter = grid?.__frameworkAdapter;\n if (!adapter?.getTypeDefault) return undefined;\n const appDefault = adapter.getTypeDefault(col.type, grid?._hostElement);\n return appDefault?.format as ((value: unknown, row: unknown) => string) | undefined;\n }\n\n /**\n * Export data to CSV format.\n * @param params - Optional export parameters\n */\n exportCsv(params?: Partial<ExportParams>): void {\n this.performExport('csv', params);\n }\n\n /**\n * Export data to Excel format (XML Spreadsheet).\n * @param params - Optional export parameters\n */\n exportExcel(params?: Partial<ExportParams>): void {\n this.performExport('excel', params);\n }\n\n /**\n * Export data to JSON format.\n * @param params - Optional export parameters\n */\n exportJson(params?: Partial<ExportParams>): void {\n this.performExport('json', params);\n }\n\n /**\n * Check if an export is currently in progress.\n * @returns Whether export is in progress\n */\n isExporting(): boolean {\n return this.isExportingFlag;\n }\n\n /**\n * Get information about the last export.\n * @returns Export info or null if no export has occurred\n */\n getLastExport(): { format: ExportFormat; timestamp: Date } | null {\n return this.lastExportInfo;\n }\n // #endregion\n}\n"],"names":["resolveColumns","columns","fields","onlyVisible","result","filter","c","hidden","field","startsWith","utility","length","fieldSet","Set","has","resolveRows","rows","indices","sort","a","b","map","i","r","formatCsvValue","value","quote","includes","replace","String","Date","toISOString","JSON","stringify","buildCsv","params","options","delimiter","newline","quoteStrings","lines","bom","includeHeaders","headerRow","col","header","processHeader","push","join","row","cells","resolveCellValue","processCell","downloadBlob","blob","fileName","url","URL","createObjectURL","link","document","createElement","href","download","style","display","body","appendChild","click","removeChild","revokeObjectURL","hashStyle","sortKeys","obj","Array","isArray","sorted","key","Object","keys","StyleRegistry","entries","Map","counter","register","hash","existing","this","get","id","set","getStyleId","size","toXml","xml","values","buildStyleElement","font","name","bold","italic","color","fill","pattern","numberFormat","alignment","horizontal","vertical","wrapText","borders","top","buildBorderElement","bottom","left","right","position","border","borderWeight","resolveDataStyleId","registry","config","cellStyle","dynamic","colStyle","columnStyles","defaultStyle","autoFitWidth","sampleSize","Math","min","maxLen","val","len","escapeXml","str","buildExcelXml","styles","excelStyles","headerStyle","groupHeaderStyle","buildStyleRegistry","widths","columnWidths","autoFit","autoFitColumns","width","buildColumnWidthsXml","headerStyleId","groupHeaderStyleId","headerRows","styleAttr","cell","span","max","label","type","displayValue","isNaN","dataStyleId","ExportPlugin","BaseGridPlugin","static","queries","description","defaultConfig","onlySelected","isExportingFlag","lastExportInfo","handleQuery","query","exportCsv","resolveExportData","format","fullParams","processHeaderRow","mode","rowIndices","fileExtension","selectionState","getSelectionState","selected","raw","collectHeaderRows","processHeaderRows","grid","responses","flat","expectedSpan","processed","rowIndex","outCells","anyVisible","runningSpan","overflowed","next","resolveCellOutput","out","formatFn","resolveFormatFn","formatted","formatDateValue","performExport","downstreamColumns","stripAccessors","content","buildExportData","endsWith","Blob","downloadCsv","ext","normalizedExt","downloadExcel","data","payload","timestamp","emit","rowCount","columnCount","getPluginState","getResolvedColumns","formatCsv","formatExcel","valueAccessor","adapter","__frameworkAdapter","getTypeDefault","appDefault","_hostElement","exportExcel","exportJson","isExporting","getLastExport"],"mappings":"4fAwBO,SAASA,EACdC,EACAC,EACAC,GAAc,GAEd,IAAIC,EAASH,EAMb,GAJIE,IACFC,EAASA,EAAOC,OAAQC,IAAOA,EAAEC,SAAWD,EAAEE,MAAMC,WAAW,QAAuB,IAAdH,EAAEI,UAGxER,GAAQS,OAAQ,CAClB,MAAMC,EAAW,IAAIC,IAAIX,GACzBE,EAASA,EAAOC,OAAQC,GAAMM,EAASE,IAAIR,EAAEE,O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,GACVoD,KAAKkH,cAAc,QAAStK,EAC9B,CAMA,UAAAkM,CAAWlM,GACToD,KAAKkH,cAAc,OAAQtK,EAC7B,CAMA,WAAAmM,GACE,OAAO/I,KAAK+E,eACd,CAMA,aAAAiE,GACE,OAAOhJ,KAAKgF,cACd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("../../core/internal/diagnostics"),require("../../core/plugin/base-plugin"),require("../../core/internal/sanitize")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/diagnostics","../../core/plugin/base-plugin","../../core/internal/sanitize"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_groupingColumns={},e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,r,t,o){"use strict";function i(e){if(!e.length)return[];const r=[],t=new Map,o=(e,t)=>{if(!t.length)return;const o=r[r.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...t):r.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let i=[],n=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===i.length&&(n=s),void i.push(e);i.length&&(o(n,i.slice()),i=[]);const d="string"==typeof l?l:l.id,u="string"==typeof l?void 0:l.label;u&&!t.has(d)&&t.set(d,u);const c=t.get(d)??u,g=r[r.length-1];g&&!g.implicit&&g.id===d?g.columns.push(e):r.push({id:d,label:c,columns:[e],firstIndex:s})}),i.length&&o(n,i),1===r.length&&r[0].implicit&&r[0].columns.length===e.length?[]:r}function n(e){const r=function(e){const r=new Set;for(let t=0;t<e.length;t++){if(!String(e[t].id).startsWith("__implicit__"))continue;if(!e[t].columns.every(e=>e.field?.startsWith("__tbw_")))continue;let o=null;for(let r=t-1;r>=0;r--)if(!String(e[r].id).startsWith("__implicit__")){o=e[r].id;break}let i=null;for(let r=t+1;r<e.length;r++)if(!String(e[r].id).startsWith("__implicit__")){i=e[r].id;break}o&&i&&o===i&&r.add(String(e[t].id))}return r}(e),t=function(e,r){const t=[];for(const o of e){if(String(o.id).startsWith("__implicit__")&&r.has(String(o.id)))continue;const e=t[t.length-1];e&&!String(o.id).startsWith("__implicit__")&&e.id===o.id?t[t.length-1]={...e,columns:[...e.columns,...o.columns]}:t.push({...o,columns:[...o.columns]})}return t}(e,r);return{merged:t,embedded:r}}function s(e,r){const t=e.columns[0],o=e.columns[e.columns.length-1],i=t?r.findIndex(e=>e.field===t.field):-1,n=o?r.findIndex(e=>e.field===o.field):-1;return-1!==i&&-1!==n?[i,n]:null}class l extends t.BaseGridPlugin{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#e=new Set;#r=[];#t=new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#o,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#e.clear(),this.#r=[],this.#t.clear()}#o=e=>{if(!this.isActive)return;const r=e,{field:t,columnOrder:o}=r.detail;if(this.config.lockGroupOrder){const e=new Map;for(const r of this.groups){if(r.id.startsWith("__implicit__"))continue;const t=e.get(r.id);t?t.push(...r.columns):e.set(r.id,[...r.columns])}for(const[,i]of e)if(!this.#i(i,o))return r.preventDefault(),void this.#n(t)}this.#s(o)};#s(e){this.#e.clear();const r=new Map;for(const t of this.groups)for(const e of t.columns)r.set(e.field,t.id);for(let t=0;t<e.length-1;t++){r.get(e[t])!==r.get(e[t+1])&&this.#e.add(e[t])}}#i(e,r){const t=e.map(e=>r.indexOf(e.field)).filter(e=>-1!==e).sort((e,r)=>e-r);return t.length<=1||t.length===t[t.length-1]-t[0]+1}#n(e){const r=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);r&&(r.style.setProperty("--_flash-color","var(--tbw-color-error)"),r.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#l()}#l(){let e;if(this.#r.length>0)e=this.#r.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){const r=new Map;for(const e of this.groups){if(e.id.startsWith("__implicit__"))continue;const t=r.get(e.id);if(t)for(const r of e.columns)t.fields.includes(r.field)||t.fields.push(r.field);else r.set(e.id,{id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)})}e=Array.from(r.values());const t=this.columns;for(const o of t)if(o.hidden&&o.group){const r="string"==typeof o.group?o.group:o.group.id,t="string"==typeof o.group?o.group:o.group.label??o.group.id,i=e.find(e=>e.id===r);i?i.fields.includes(o.field)||i.fields.push(o.field):e.push({id:r,label:t,fields:[o.field]})}}else{const r=this.columns,t=new Map;for(const e of r){if(!e.group)continue;const r="string"==typeof e.group?e.group:e.group.id,o="string"==typeof e.group?e.group:e.group.label??e.group.id,i=t.get(r);i?i.fields.includes(e.field)||i.fields.push(e.field):t.set(r,{id:r,label:o,fields:[e.field]})}e=Array.from(t.values())}const r=this.grid?.getColumnOrder();if(r&&r.length>0){const t=new Map(r.map((e,r)=>[e,r]));for(const r of e)r.fields.sort((e,r)=>(t.get(e)??1/0)-(t.get(r)??1/0))}return e}static detect(e,r){const t=r?.features?.groupingColumns;if(t&&"object"==typeof t&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;if(r?.columnGroups&&Array.isArray(r.columnGroups)&&r.columnGroups.length>0)return!0;const o=r?.columns;return!!Array.isArray(o)&&function(e){return e.some(e=>null!=e.group)}(o)}processColumns(e){const t=this.config?.columnGroups,o=this.grid?.gridConfig?.columnGroups;let n,s;if(t&&Array.isArray(t)&&t.length>0?(o&&Array.isArray(o)&&o.length>0&&this.warn(r.COLUMN_GROUPS_CONFLICT,"columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),n=t):o&&Array.isArray(o)&&o.length>0&&(n=o),n&&n.length>0){const t=n.map(e=>{return e.id?e:(e.header||r.throwDiagnostic(r.COLUMN_GROUP_NO_ID,'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:(t=e.header,t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))});var t});this.#r=t,this.#t.clear();for(const e of t)e.renderer&&this.#t.set(e.id,e.renderer);const o=new Map;for(const e of t)for(const r of e.children)o.set(r,{id:e.id,label:e.header});s=e.map(e=>{const r=o.get(e.field);return r&&!e.group?{...e,group:r}:e})}else this.#r=[],this.#t.clear(),s=[...e];const l=i(s);if(0===l.length)return this.isActive=!1,this.groups=[],s;if(this.#t.size>0)for(const r of l){const e=this.#t.get(r.id);e&&(r.renderer=e)}this.isActive=!0,this.groups=l,this.#e.clear();for(const r of l){const e=r.columns[r.columns.length-1];e?.field&&this.#e.add(e.field)}return s}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),r=e?.querySelector(".header-group-row");return void(r&&r.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const r=e.querySelector(".header-group-row");r&&r.remove();const t=this.visibleColumns,l=i(t);if(0===l.length)return;if(this.#t.size>0)for(const o of l){const e=this.#t.get(o.id);e&&(o.renderer=e)}this.#e.clear();const d=n(l);for(let o=0;o<d.merged.length;o++){const e=d.merged[o],r=e.columns[e.columns.length-1];r?.field&&o<d.merged.length-1&&this.#e.add(r.field)}const u=function(e,r,t,i){if(0===e.length)return null;const l=document.createElement("div");l.className="header-group-row",l.setAttribute("role","row");const{merged:d}=i??n(e);for(const n of d){const e=String(n.id),i=e.startsWith("__implicit__"),d=s(n,r);if(!d)continue;const[u,c]=d,g=c-u+1,a=i?"":n.label||n.id,p=document.createElement("div");p.className="cell header-group-cell",i&&p.classList.add("implicit-group"),p.setAttribute("data-group",e),p.style.gridColumn=`${u+1} / span ${g}`;const f=!i&&(n.renderer||t)||void 0;if(f&&!i){const r=f({id:e,label:String(a),columns:n.columns,firstIndex:u,isImplicit:!1});r instanceof HTMLElement?p.appendChild(r):"string"==typeof r?p.innerHTML=o.sanitizeHTML(r):p.textContent=a}else p.textContent=a;l.appendChild(p)}return l}(l,t,this.config.groupHeaderRenderer,d);if(u){u.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(u,r):e.appendChild(u)}const c=e.querySelector(".header-row");c&&(c.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,r,t,o){if(!r.length||!e)return;const{merged:i,embedded:s}=o??n(r),l=new Map;for(const n of i)if(!String(n.id).startsWith("__implicit__"))for(const e of n.columns)e.field&&l.set(e.field,n.id);for(let n=0;n<r.length;n++){const e=r[n];if(String(e.id).startsWith("__implicit__")&&s.has(String(e.id)))for(let t=n-1;t>=0;t--)if(!String(r[t].id).startsWith("__implicit__")){for(const o of e.columns)o.field&&l.set(o.field,r[t].id);break}}const d=Array.from(e.querySelectorAll(".cell[data-field]"));d.forEach(e=>{const r=e.getAttribute("data-field")||"",t=l.get(r);t&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",t))});for(const n of i){const e=n.columns[n.columns.length-1],r=d.find(r=>r.getAttribute("data-field")===e.field);r&&r.classList.add("group-end")}}(c,l,0,d))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#e.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){return this.groups.filter(r=>r.id===e).flatMap(e=>e.columns)}refresh(){this.requestRender()}}e.GroupingColumnsPlugin=l,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("../../core/internal/diagnostics"),require("../../core/plugin/base-plugin"),require("../../core/internal/sanitize")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/diagnostics","../../core/plugin/base-plugin","../../core/internal/sanitize"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_groupingColumns={},e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,r,t,o){"use strict";function i(e){if(!e.length)return[];const r=[],t=new Map,o=(e,t)=>{if(!t.length)return;const o=r[r.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...t):r.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let i=[],n=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===i.length&&(n=s),void i.push(e);i.length&&(o(n,i.slice()),i=[]);const d="string"==typeof l?l:l.id,u="string"==typeof l?void 0:l.label;u&&!t.has(d)&&t.set(d,u);const c=t.get(d)??u,g=r[r.length-1];g&&!g.implicit&&g.id===d?g.columns.push(e):r.push({id:d,label:c,columns:[e],firstIndex:s})}),i.length&&o(n,i),1===r.length&&r[0].implicit&&r[0].columns.length===e.length?[]:r}function n(e){const r=function(e){const r=new Set;for(let t=0;t<e.length;t++){if(!String(e[t].id).startsWith("__implicit__"))continue;if(!e[t].columns.every(e=>e.field?.startsWith("__tbw_")))continue;let o=null;for(let r=t-1;r>=0;r--)if(!String(e[r].id).startsWith("__implicit__")){o=e[r].id;break}let i=null;for(let r=t+1;r<e.length;r++)if(!String(e[r].id).startsWith("__implicit__")){i=e[r].id;break}o&&i&&o===i&&r.add(String(e[t].id))}return r}(e),t=function(e,r){const t=[];for(const o of e){if(String(o.id).startsWith("__implicit__")&&r.has(String(o.id)))continue;const e=t[t.length-1];e&&!String(o.id).startsWith("__implicit__")&&e.id===o.id?t[t.length-1]={...e,columns:[...e.columns,...o.columns]}:t.push({...o,columns:[...o.columns]})}return t}(e,r);return{merged:t,embedded:r}}function s(e,r){const t=e.columns[0],o=e.columns[e.columns.length-1],i=t?r.findIndex(e=>e.field===t.field):-1,n=o?r.findIndex(e=>e.field===o.field):-1;return-1!==i&&-1!==n?[i,n]:null}class l extends t.BaseGridPlugin{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"},{type:"collectHeaderRows",description:"Contributes a group-header row above the leaf header for exports / printers"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#e=new Set;#r=[];#t=new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#o,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#e.clear(),this.#r=[],this.#t.clear()}#o=e=>{if(!this.isActive)return;const r=e,{field:t,columnOrder:o}=r.detail;if(this.config.lockGroupOrder){const e=new Map;for(const r of this.groups){if(r.id.startsWith("__implicit__"))continue;const t=e.get(r.id);t?t.push(...r.columns):e.set(r.id,[...r.columns])}for(const[,i]of e)if(!this.#i(i,o))return r.preventDefault(),void this.#n(t)}this.#s(o)};#s(e){this.#e.clear();const r=new Map;for(const t of this.groups)for(const e of t.columns)r.set(e.field,t.id);for(let t=0;t<e.length-1;t++){r.get(e[t])!==r.get(e[t+1])&&this.#e.add(e[t])}}#i(e,r){const t=e.map(e=>r.indexOf(e.field)).filter(e=>-1!==e).sort((e,r)=>e-r);return t.length<=1||t.length===t[t.length-1]-t[0]+1}#n(e){const r=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);r&&(r.style.setProperty("--_flash-color","var(--tbw-color-error)"),r.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){return"getColumnGrouping"===e.type?this.#l():"collectHeaderRows"===e.type?this.#d(e.context):void 0}#d(e){const r=e?.columns;if(!Array.isArray(r)||0===r.length)return;const t=i(r);if(0===t.length)return;const{merged:o}=n(t),s=[];for(const i of o){const e=String(i.id).startsWith("__implicit__"),t=i.columns[0],o=i.columns[i.columns.length-1];if(!t||!o)continue;const n=r.findIndex(e=>e.field===t.field),l=r.findIndex(e=>e.field===o.field);if(n<0||l<0)continue;const d=l-n+1;s.push({label:e?"":i.label??i.id,span:d,source:this.name})}if(0===s.length)return;return s.reduce((e,r)=>e+r.span,0)!==r.length?{cells:[{label:"",span:r.length,source:this.name}]}:{cells:s}}#l(){let e;if(this.#r.length>0)e=this.#r.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){const r=new Map;for(const e of this.groups){if(e.id.startsWith("__implicit__"))continue;const t=r.get(e.id);if(t)for(const r of e.columns)t.fields.includes(r.field)||t.fields.push(r.field);else r.set(e.id,{id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)})}e=Array.from(r.values());const t=this.columns;for(const o of t)if(o.hidden&&o.group){const r="string"==typeof o.group?o.group:o.group.id,t="string"==typeof o.group?o.group:o.group.label??o.group.id,i=e.find(e=>e.id===r);i?i.fields.includes(o.field)||i.fields.push(o.field):e.push({id:r,label:t,fields:[o.field]})}}else{const r=this.columns,t=new Map;for(const e of r){if(!e.group)continue;const r="string"==typeof e.group?e.group:e.group.id,o="string"==typeof e.group?e.group:e.group.label??e.group.id,i=t.get(r);i?i.fields.includes(e.field)||i.fields.push(e.field):t.set(r,{id:r,label:o,fields:[e.field]})}e=Array.from(t.values())}const r=this.grid?.getColumnOrder();if(r&&r.length>0){const t=new Map(r.map((e,r)=>[e,r]));for(const r of e)r.fields.sort((e,r)=>(t.get(e)??1/0)-(t.get(r)??1/0))}return e}static detect(e,r){const t=r?.features?.groupingColumns;if(t&&"object"==typeof t&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;if(r?.columnGroups&&Array.isArray(r.columnGroups)&&r.columnGroups.length>0)return!0;const o=r?.columns;return!!Array.isArray(o)&&function(e){return e.some(e=>null!=e.group)}(o)}processColumns(e){const t=this.config?.columnGroups,o=this.grid?.gridConfig?.columnGroups;let n,s;if(t&&Array.isArray(t)&&t.length>0?(o&&Array.isArray(o)&&o.length>0&&this.warn(r.COLUMN_GROUPS_CONFLICT,"columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),n=t):o&&Array.isArray(o)&&o.length>0&&(n=o),n&&n.length>0){const t=n.map(e=>{return e.id?e:(e.header||r.throwDiagnostic(r.COLUMN_GROUP_NO_ID,'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:(t=e.header,t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))});var t});this.#r=t,this.#t.clear();for(const e of t)e.renderer&&this.#t.set(e.id,e.renderer);const o=new Map;for(const e of t)for(const r of e.children)o.set(r,{id:e.id,label:e.header});s=e.map(e=>{const r=o.get(e.field);return r&&!e.group?{...e,group:r}:e})}else this.#r=[],this.#t.clear(),s=[...e];const l=i(s);if(0===l.length)return this.isActive=!1,this.groups=[],s;if(this.#t.size>0)for(const r of l){const e=this.#t.get(r.id);e&&(r.renderer=e)}this.isActive=!0,this.groups=l,this.#e.clear();for(const r of l){const e=r.columns[r.columns.length-1];e?.field&&this.#e.add(e.field)}return s}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),r=e?.querySelector(".header-group-row");return void(r&&r.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const r=e.querySelector(".header-group-row");r&&r.remove();const t=this.visibleColumns,l=i(t);if(0===l.length)return;if(this.#t.size>0)for(const o of l){const e=this.#t.get(o.id);e&&(o.renderer=e)}this.#e.clear();const d=n(l);for(let o=0;o<d.merged.length;o++){const e=d.merged[o],r=e.columns[e.columns.length-1];r?.field&&o<d.merged.length-1&&this.#e.add(r.field)}const u=function(e,r,t,i){if(0===e.length)return null;const l=document.createElement("div");l.className="header-group-row",l.setAttribute("role","row");const{merged:d}=i??n(e);for(const n of d){const e=String(n.id),i=e.startsWith("__implicit__"),d=s(n,r);if(!d)continue;const[u,c]=d,g=c-u+1,a=i?"":n.label||n.id,p=document.createElement("div");p.className="cell header-group-cell",i&&p.classList.add("implicit-group"),p.setAttribute("data-group",e),p.style.gridColumn=`${u+1} / span ${g}`;const f=!i&&(n.renderer||t)||void 0;if(f&&!i){const r=f({id:e,label:String(a),columns:n.columns,firstIndex:u,isImplicit:!1});r instanceof HTMLElement?p.appendChild(r):"string"==typeof r?p.innerHTML=o.sanitizeHTML(r):p.textContent=a}else p.textContent=a;l.appendChild(p)}return l}(l,t,this.config.groupHeaderRenderer,d);if(u){u.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(u,r):e.appendChild(u)}const c=e.querySelector(".header-row");c&&(c.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,r,t,o){if(!r.length||!e)return;const{merged:i,embedded:s}=o??n(r),l=new Map;for(const n of i)if(!String(n.id).startsWith("__implicit__"))for(const e of n.columns)e.field&&l.set(e.field,n.id);for(let n=0;n<r.length;n++){const e=r[n];if(String(e.id).startsWith("__implicit__")&&s.has(String(e.id)))for(let t=n-1;t>=0;t--)if(!String(r[t].id).startsWith("__implicit__")){for(const o of e.columns)o.field&&l.set(o.field,r[t].id);break}}const d=Array.from(e.querySelectorAll(".cell[data-field]"));d.forEach(e=>{const r=e.getAttribute("data-field")||"",t=l.get(r);t&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",t))});for(const n of i){const e=n.columns[n.columns.length-1],r=d.find(r=>r.getAttribute("data-field")===e.field);r&&r.classList.add("group-end")}}(c,l,0,d))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#e.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){return this.groups.filter(r=>r.id===e).flatMap(e=>e.columns)}refresh(){this.requestRender()}}e.GroupingColumnsPlugin=l,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=grouping-columns.umd.js.map
|