@svgrid/enterprise 3.1.17 → 3.1.19

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.
Files changed (62) hide show
  1. package/dist/SvGridEditPanel.svelte +14 -1
  2. package/dist/SvGridScheduler.svelte +15 -6
  3. package/dist/SvSheet.svelte +2 -0
  4. package/dist/cdn/svgrid-enterprise.svelte-external.js +8253 -8166
  5. package/dist/designer/assets/{index-C1Ujg62Z.js → index-DA9jVAjf.js} +359 -348
  6. package/dist/designer/assets/index-WCxj6WfJ.css +1 -0
  7. package/dist/designer/assets/{src-hO8VnnI5.js → src-fddEt37f.js} +2 -2
  8. package/dist/designer/index.html +3 -3
  9. package/dist/export-pdf.d.ts +8 -0
  10. package/dist/export-pdf.js +14 -0
  11. package/dist/export.js +2 -2
  12. package/dist/fields/SvBase.svelte +36 -33
  13. package/dist/fields/base-connect.js +50 -9
  14. package/dist/fields/base-sql.d.ts +8 -0
  15. package/dist/fields/base-sql.js +12 -3
  16. package/dist/install.js +3 -3
  17. package/dist/node/studio.js +207 -62
  18. package/dist/sheet-enable.d.ts +8 -2
  19. package/dist/sheet-enable.js +21 -9
  20. package/dist/sources/introspect-supabase.d.ts +6 -3
  21. package/dist/sources/introspect-supabase.js +29 -11
  22. package/dist/sources/supabase.d.ts +10 -0
  23. package/dist/sources/supabase.js +11 -2
  24. package/dist/studio/cli.d.ts +9 -0
  25. package/dist/studio/cli.js +41 -7
  26. package/dist/studio/emit-project.d.ts +3 -1
  27. package/dist/studio/emit-project.js +84 -33
  28. package/dist/studio/emit-schema.js +9 -2
  29. package/dist/studio/index.d.ts +1 -1
  30. package/dist/studio/init-flow.d.ts +7 -0
  31. package/dist/studio/init-flow.js +23 -2
  32. package/dist/studio/introspect-db.d.ts +15 -1
  33. package/dist/studio/introspect-db.js +29 -5
  34. package/dist/studio/scaffold.js +4 -2
  35. package/dist/sveltekit/sql-source.d.ts +24 -0
  36. package/dist/sveltekit/sql-source.js +34 -1
  37. package/dist/sveltekit/sql.js +14 -2
  38. package/dist/version.d.ts +2 -2
  39. package/dist/version.js +2 -2
  40. package/dist/wc/GridFooter-BgoA77TJ.js +145 -0
  41. package/dist/wc/{GridMenus-q9qYpzKh.js → GridMenus-DVGuqp2l.js} +430 -430
  42. package/dist/wc/{PinSplitter-D-qtDhSM.js → PinSplitter-Btco0txr.js} +24 -24
  43. package/dist/wc/{SvChartMenu-CQNrQGT2.js → SvChartMenu-Ue-HFR5c.js} +58 -58
  44. package/dist/wc/{SvDateRangeInput-BYNOfYxD.js → SvDateRangeInput-CJZohgBe.js} +43 -43
  45. package/dist/wc/{SvDateTimePicker-Bq9N0Oiy.js → SvDateTimePicker-DmK_QkkU.js} +241 -241
  46. package/dist/wc/{SvField-B_kurx_P.js → SvField-C-OodMMv.js} +71 -71
  47. package/dist/wc/SvGridCellEditor-C7ios4i_.js +582 -0
  48. package/dist/wc/{SvGridChart-DrmqEen2.js → SvGridChart-DWRqlhCV.js} +549 -549
  49. package/dist/wc/{SvGridChartBuilder-XFvW1BdT.js → SvGridChartBuilder-BXW3yUR0.js} +337 -337
  50. package/dist/wc/{SvGridChartPanel-oJJtUKG6.js → SvGridChartPanel-28n4tomx.js} +354 -354
  51. package/dist/wc/{SvGridChartView-Cetuj70H.js → SvGridChartView-CbG_WrU-.js} +7 -7
  52. package/dist/wc/{SvGridDropdown-45WsObLL.js → SvGridDropdown-BVnpNU_I.js} +130 -130
  53. package/dist/wc/{SvModal-DrfOYYyX.js → SvModal-DLppAQED.js} +91 -91
  54. package/dist/wc/{client-DQIzjDBG.js → client-GWAV79ON.js} +479 -476
  55. package/dist/wc/{date-format-DS-z_h9v.js → date-format-4_QoS4zZ.js} +393 -393
  56. package/dist/wc/{grid-extension.svelte-Bufq4B4C.js → grid-extension.svelte-CucBS4FL.js} +1 -1
  57. package/dist/wc/sv-sheet-element.js +10474 -10460
  58. package/dist/wc/{svelte-virtualizer.svelte-CkZaFakp.js → svelte-virtualizer.svelte-BDcouWqw.js} +3 -3
  59. package/package.json +18 -5
  60. package/dist/designer/assets/index-DdmxO6Dd.css +0 -1
  61. package/dist/wc/GridFooter-4T29pfok.js +0 -145
  62. package/dist/wc/SvGridCellEditor-Nnl8C3Yj.js +0 -582
@@ -35,7 +35,7 @@ Contact sales@jqwidgets.com for details or visit the license page: https://svgri
35
35
  <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`+(n.size>0?`<numFmts count="${n.size}">${[...n.entries()].map(([e,t])=>`<numFmt numFmtId="${t}" formatCode="${B(e)}"/>`).join(``)}</numFmts>`:``)+`<fonts count="${a.length}">${a.join(``)}</fonts><fills count="${c.length}">${c.join(``)}</fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="${d.length}">${d.join(``)}</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`}}function Ve(e){let{header:t,rows:n}=e,r=Be(t,n),i=[],a=[`<row r="1">${t.map((e,t)=>`<c r="${V(t)}1" s="1" t="inlineStr"><is><t xml:space="preserve">${B(e)}</t></is></c>`).join(``)}</row>`];for(let e=0;e<n.length;e++){let t=e+2,o=n[e],s=[];for(let e=0;e<o.length;e++){let n=o[e],a=`${V(e)}${t}`,c=r.styleIndexOf(n),l=c?` s="${c}"`:``;if(n.link&&i.push({ref:a,url:n.link,id:`rId${i.length+1}`}),n.value==null||n.value===``)s.push(`<c r="${a}"${l}/>`);else if(n.t===`n`)s.push(`<c r="${a}"${l}><v>${Number(n.value)}</v></c>`);else if(n.t===`d`){let e=Pe(n.value);s.push(`<c r="${a}"${l}><v>${Ne(e)}</v></c>`)}else n.t===`b`?s.push(`<c r="${a}"${l} t="b"><v>${+!!n.value}</v></c>`):s.push(`<c r="${a}"${l} t="inlineStr"><is><t xml:space="preserve">${B(String(n.value))}</t></is></c>`)}a.push(`<row r="${t}">${s.join(``)}</row>`)}let o=e.widths?`<cols>${e.widths.map((e,t)=>`<col min="${t+1}" max="${t+1}" width="${Math.max(4,Math.round(e/7*100)/100)}" customWidth="1"/>`).join(``)}</cols>`:``,s=Math.max(0,Math.floor(e.freezeColumns??0)),c=+!!e.freezeHeader,l=`<sheetView workbookViewId="0"/>`;if(c>0||s>0){let e=`${V(s)}${c+1}`,t=s>0&&c>0?`bottomRight`:s>0?`topRight`:`bottomLeft`;l=`<sheetView workbookViewId="0"><pane${s>0?` xSplit="${s}"`:``}${c>0?` ySplit="${c}"`:``} topLeftCell="${e}" activePane="${t}" state="frozen"/><selection pane="${t}" activeCell="${e}" sqref="${e}"/></sheetView>`}let u=n.length>0?(e.condFormats??[]).map((e,t)=>{let r=V(e.colIdx),i=`${r}2:${r}${n.length+1}`;if(e.kind===`dataBar`){let n=H(e.color)??`FF638EC6`;return`<conditionalFormatting sqref="${i}"><cfRule type="dataBar" priority="${t+1}"><dataBar><cfvo type="min"/><cfvo type="max"/><color rgb="${n}"/></dataBar></cfRule></conditionalFormatting>`}let a=e.colors.map(e=>H(e)??`FFFFFFFF`),o=a.length>=3?`<cfvo type="min"/><cfvo type="percentile" val="50"/><cfvo type="max"/>`:`<cfvo type="min"/><cfvo type="max"/>`,s=a.map(e=>`<color rgb="${e}"/>`).join(``);return`<conditionalFormatting sqref="${i}"><cfRule type="colorScale" priority="${t+1}"><colorScale>${o}${s}</colorScale></cfRule></conditionalFormatting>`}).join(``):``,d=i.length?`<hyperlinks>${i.map(e=>`<hyperlink ref="${e.ref}" r:id="${e.id}"/>`).join(``)}</hyperlinks>`:``,f=``,p=``,m=``;if(e.table&&t.length>0){let o=e.table,s=new Set,c=t.map((e,t)=>{let n=(e??``).trim()||`Column${t+1}`,r=n,i=1;for(;s.has(r.toLowerCase());)r=`${n}${++i}`;return s.add(r.toLowerCase()),r}),l=V(t.length-1),u=n.length+1,d=u+1,h=o.totalsRow&&n.length>0,g=o.totalsFns.findIndex(e=>!e);if(h){let e=t.map((e,t)=>{let i=`${V(t)}${d}`,a=o.totalsFns[t];if(a){let e=0;for(let r of n){let n=r[t];n?.t===`n`&&typeof n.value==`number`&&(e+=n.value)}let s=n.find(e=>e[t]?.t===`n`)?.[t]?.numFmt,l=r.styleIndexOf({t:`n`,value:e,numFmt:s,bold:!0}),u=a===`average`?101:a===`count`?103:109,d=a===`count`?n.length:e;return`<c r="${i}"${l?` s="${l}"`:``}><f>SUBTOTAL(${u},${o.name}[${B(c[t])}])</f><v>${d}</v></c>`}if(t===g){let e=r.styleIndexOf({t:`s`,value:`Total`,bold:!0});return`<c r="${i}"${e?` s="${e}"`:``} t="inlineStr"><is><t>Total</t></is></c>`}return`<c r="${i}"/>`});a.push(`<row r="${d}">${e.join(``)}</row>`)}let _=c.map((e,t)=>{let n=h?o.totalsFns[t]:void 0,r=h?n?` totalsRowFunction="${n}"`:t===g?` totalsRowLabel="Total"`:``:``;return`<tableColumn id="${t+1}" name="${B(e)}"${r}/>`}).join(``);f=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
36
36
  <table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="${B(o.name)}" displayName="${B(o.name)}" ref="A1:${l}${h?d:u}"${h?` totalsRowCount="1"`:` totalsRowShown="0"`}><autoFilter ref="A1:${l}${u}"/><tableColumns count="${t.length}">${_}</tableColumns><tableStyleInfo name="${B(o.style??`TableStyleMedium2`)}" showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0"/></table>`,m=`rId${i.length+1}`,p=`<tableParts count="1"><tablePart r:id="${m}"/></tableParts>`}let h=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
37
37
  <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheetViews>${l}</sheetViews><sheetFormatPr defaultRowHeight="15"/>`+o+`<sheetData>${a.join(``)}</sheetData>`+u+d+p+`</worksheet>`,g={"[Content_Types].xml":f?Fe.replace(`</Types>`,`<Override PartName="/xl/tables/table1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"/></Types>`):Fe,"_rels/.rels":Ie,"xl/workbook.xml":Re(e.sheetName),"xl/_rels/workbook.xml.rels":ze,"xl/styles.xml":r.build(),"xl/worksheets/sheet1.xml":h};if(f&&(g[`xl/tables/table1.xml`]=f),i.length||m){let e=i.map(e=>`<Relationship Id="${e.id}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="${B(e.url)}" TargetMode="External"/>`);m&&e.push(`<Relationship Id="${m}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="../tables/table1.xml"/>`),g[`xl/worksheets/_rels/sheet1.xml.rels`]=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
38
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`+e.join(``)+`</Relationships>`}return g}async function He(e,t){let n=new t;for(let[t,r]of Object.entries(e))n.file(t,r);return n.generateAsync({type:`blob`,mimeType:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`})}function Ue(e){let t=e=>!!e&&typeof e==`object`&&Object.keys(e).some(e=>/\.(ttf|otf)$/i.test(e))&&Object.values(e).every(e=>typeof e==`string`),n=new Set,r=e=>{if(!e||typeof e!=`object`||n.has(e))return null;if(n.add(e),t(e))return e;let i=e;return r(i.pdfMake?.vfs)??r(i.vfs)??r(i.default)};return r(e)}function We(e,t){let n=Ue(t);return n?(typeof e.addVirtualFileSystem==`function`&&e.addVirtualFileSystem(n),e.vfs=n,!0):!1}function Ge(e){if(!e)return null;let t=e.trim(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t);if(n){let e=n[1];return`#`+(e.length===3?e.split(``).map(e=>e+e).join(``):e).toLowerCase()}let r=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/i.exec(t);if(!r||!((r[4]===void 0?1:r[4].endsWith(`%`)?Number(r[4].slice(0,-1))/100:Number(r[4]))>.05))return null;let i=e=>Math.max(0,Math.min(255,Math.round(Number(e)))).toString(16).padStart(2,`0`);return`#`+i(r[1])+i(r[2])+i(r[3])}function Ke(e){let t=parseInt(e.slice(1),16),n=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*n(t>>16&255)+.7152*n(t>>8&255)+.0722*n(t&255)}function qe(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=t=>e.querySelector(t),n=(e,t)=>e?Ge(getComputedStyle(e).getPropertyValue(t)):null,r=e=>{for(let t=e;t;t=t.parentElement){let e=n(t,`background-color`);if(e)return e}return null},i=`:not([class*="row-number"]):not([class*="selection"])`,a=t(`.sv-grid-head .sv-grid-column${i}`)??t(`.sv-grid-header-cell`)??t(`thead th`),o=t(`.sv-grid-body .sv-grid-row:not(.sv-grid-row-alt):not(.sv-grid-header-row) .sv-grid-cell${i}`)??t(`tbody td`),s=t(`.sv-grid-body .sv-grid-row-alt .sv-grid-cell${i}`),c=t(`.sv-grid-group-row .sv-grid-cell`),l={},u=r(a),d=n(a,`color`);u&&(l.headerColor=u),d&&(l.headerTextColor=d);let f=r(o?o.parentElement:t(`.sv-grid-container`)??e),p=n(o,`color`);if(f&&Ke(f)<.4||p&&Ke(p)>.5)return l;p&&(l.textColor=p);let m=n(o,`border-bottom-color`)??n(a,`border-bottom-color`);m&&(l.borderColor=m);let h=n(s,`background-color`);h&&h!==f&&(l.zebraColor=h);let g=n(c,`background-color`),_=n(c,`color`);return g&&g!==f&&(l.groupColor=g),_&&(l.groupTextColor=_),l}var Je={A4:[595.28,841.89],A3:[841.89,1190.55],A5:[419.53,595.28],LETTER:[612,792],LEGAL:[612,1008]};async function Ye(e,t){if(!e?.length)return[];let n=[];for(let r of e){if(`image`in r){n.push(r);continue}let e=await t(r.element),i=await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error??Error(`could not read the chart image`)),r.readAsDataURL(e)});n.push({image:i,title:r.title,caption:r.caption,width:r.width})}return n}function Xe(e){let{columns:t}=e,n=e.opts??{},r=e.styles??{},i=e.theme??{},a=e.now??new Date(0),o=n.fontSize??8,s=n.headerColor??r.headerRow?.backgroundColor??i.headerColor??`#334155`,c=n.headerTextColor??r.headerRow?.color??i.headerTextColor??`#ffffff`,l=n.zebra??!0,u=n.zebraColor??r.rowAlternate?.backgroundColor??i.zebraColor??`#f1f5f9`,d=n.groupColor??i.groupColor??`#e2e8f0`,f=n.groupTextColor??i.groupTextColor??`#0f172a`,p=n.subtotalColor??i.subtotalColor??`#f8fafc`,m=n.textColor??r.rows?.color??i.textColor,h=n.borderColor??i.borderColor??`#e2e8f0`,g=n.repeatHeader??!0,_=e=>e===`bold`||typeof e==`number`&&e>=600,v=e=>{if(e===void 0)return;let t=typeof e==`number`?e:parseFloat(e);return Number.isFinite(t)&&t>0?t:void 0},y=(e,t)=>{if(!t)return;t.backgroundColor&&(e.fillColor=t.backgroundColor),t.color&&(e.color=t.color),_(t.fontWeight)?e.bold=!0:t.fontWeight===`normal`&&(e.bold=!1),t.fontStyle===`italic`&&(e.italics=!0);let n=v(t.fontSize);n&&(e.fontSize=n),t.textAlign&&(e.alignment=t.textAlign)},b=new Map;for(let[e,t]of Object.entries(r.cells??{})){let n=/^([A-Z]+)(\d+)$/i.exec(e.trim());if(!n)continue;let r=0;for(let e of n[1].toUpperCase())r=r*26+(e.charCodeAt(0)-64);b.set(`${Number(n[2])-1}:${r-1}`,t)}let x=n.pageOrientation??(t.length>(n.autoLandscapeThreshold??8)?`landscape`:`portrait`),S=Array.isArray(n.columnWidths)?n.columnWidths:t.map(()=>n.columnWidths===`auto`?`auto`:`*`),C=t.map((e,t)=>{let n={text:e.header,bold:!0,alignment:e.align??`left`,color:c,fillColor:s};return y(n,r.headerRow?{...r.headerRow,backgroundColor:void 0,color:void 0}:void 0),y(n,b.get(`0:${t}`)),n}),w=e.body??(e.rows??[]).map(e=>({kind:`data`,cells:e})),ee=e.dataCellStyle,te=e.dataCellLink,ne=0,T=new Set,E=[C];if(w.forEach((e,n)=>{let i=n+1;if(e.kind===`group`){let n={text:e.label,bold:!0,color:f,fillColor:d,colSpan:t.length,margin:[(e.level??0)*12,2,0,2]},r=Array.from({length:Math.max(0,t.length-1)},()=>({text:``}));E.push([n,...r])}else if(e.kind===`subtotal`)E.push(t.map((t,n)=>({text:e.cells[n]??``,bold:!0,alignment:t.align??`left`,fillColor:p})));else{T.add(i);let n=ne++;E.push(t.map((t,i)=>{let a={text:e.cells[i]??``,alignment:t.align??`left`};m&&(a.color=m),y(a,r.rows?{...r.rows,backgroundColor:void 0}:void 0),l&&n%2==1&&r.rowAlternate?.color&&(a.color=r.rowAlternate.color),y(a,b.get(`${n+1}:${i}`));let o=ee?.(n,i);o&&(o.fill&&(a.fillColor=o.fill),o.color&&(a.color=o.color),o.bold&&(a.bold=!0));let s=te?.(n,i);return s&&(a.link=s,a.decoration=`underline`,o?.color||(a.color=`#2563eb`)),a}))}}),e.merges?.length&&!e.body){let n=[...T].sort((e,t)=>e-t);for(let r of e.merges){let e=Math.max(1,Math.floor(r.rowSpan??1)),i=Math.max(1,Math.floor(r.colSpan??1));if(e===1&&i===1)continue;let a=n[r.row];if(a===void 0||r.col<0||r.col>=t.length)continue;let o=E[a]?.[r.col];if(o){e>1&&(o.rowSpan=Math.min(e,E.length-a)),i>1&&(o.colSpan=Math.min(i,t.length-r.col));for(let e=0;e<(o.rowSpan??1);e+=1)for(let t=0;t<(o.colSpan??1);t+=1){if(e===0&&t===0)continue;let n=E[a+e]?.[r.col+t];n&&(n.text=``)}}}}let D={table:{headerRows:+!!g,dontBreakRows:!0,widths:S,body:E},layout:{fillColor:e=>l&&e>0&&e%2==0&&T.has(e)?u:null,hLineWidth:()=>.5,vLineWidth:()=>.5,hLineColor:()=>h,vLineColor:()=>h,paddingTop:()=>3,paddingBottom:()=>3,paddingLeft:()=>5,paddingRight:()=>5}},O=(e,t)=>(e??[]).map(e=>{if(`image`in e)return{image:e.image,...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},margin:t};if(`text`in e){let n={text:e.text};return y(n,e.style),{...n,margin:t}}return{columns:[{text:e.left??``,alignment:`left`},{text:e.center??``,alignment:`center`},{text:e.right??``,alignment:`right`}],margin:t}}),k=[];if(k.push(...O(e.headerLines,[0,0,0,4])),n.logo&&k.push({image:n.logo,width:n.logoWidth??90,margin:[0,0,0,8]}),n.title&&k.push({text:n.title,fontSize:o+8,bold:!0,margin:[0,0,0,2]}),n.subtitle&&k.push({text:n.subtitle,fontSize:o+1,color:`#64748b`,margin:[0,0,0,8]}),n.kpis?.length){let e=n.kpiColor??`#f8fafc`;k.push({table:{widths:n.kpis.map(()=>`*`),body:[n.kpis.map(t=>({fillColor:e,margin:[8,6,8,6],stack:[{text:t.label,fontSize:o,color:`#64748b`},{text:t.value,fontSize:o+10,bold:!0,margin:[0,2,0,0]},...t.delta?[{text:t.delta,fontSize:o,color:t.color??`#64748b`,margin:[0,2,0,0]}]:[]]}))]},layout:{hLineWidth:()=>0,vLineWidth:()=>4,vLineColor:()=>`#ffffff`,paddingLeft:()=>0,paddingRight:()=>0,paddingTop:()=>0,paddingBottom:()=>0},margin:[0,0,0,10]})}let A=n.margins??[28,34,28,34],[re,ie]=Je[n.pageSize??`A4`],j=(x===`landscape`?ie:re)-A[0]-A[2],M=(e.charts??(n.charts??[]).filter(e=>`image`in e)).map(e=>({stack:[...e.title?[{text:e.title,fontSize:o+3,bold:!0,margin:[0,0,0,4]}]:[],{image:e.image,width:Math.min(e.width??j,j)},...e.caption?[{text:e.caption,fontSize:o,color:`#64748b`,margin:[0,3,0,0]}]:[]],margin:[0,0,0,12],unbreakable:!0}));n.chartsPosition!==`below`&&k.push(...M),k.push(D),n.chartsPosition===`below`&&(M.length&&k.push({text:``,margin:[0,0,0,12]}),k.push(...M)),k.push(...O(e.footerLines,[0,4,0,0]));let N={pageSize:n.pageSize??`A4`,pageOrientation:x,pageMargins:n.margins??[28,34,28,34],defaultStyle:{fontSize:o},content:k};if(n.showPageNumbers??!0){let e=a.toISOString().slice(0,10);N.footer=(t,n)=>({margin:[28,6,28,0],columns:[{text:e,alignment:`left`,fontSize:7,color:`#94a3b8`},{text:`Page ${t} of ${n}`,alignment:`right`,fontSize:7,color:`#94a3b8`}]})}return N}function Ze(e,t){let n=/^#?([0-9a-f]{6})$/i.exec(e.trim());if(!n)return e;let r=parseInt(n[1],16);return`#`+[r>>16&255,r>>8&255,r&255].map(e=>Math.round(e+(255-e)*t).toString(16).padStart(2,`0`)).join(``)}function Qe(e){let t={};return e.background&&(t.fill=e.background),!t.fill&&e.dataBar&&(t.fill=Ze(e.dataBar.color,.72)),e.color&&e.color!==`transparent`&&(t.color=e.color),(e.fontWeight===`bold`||typeof e.fontWeight==`number`&&e.fontWeight>=600)&&(t.bold=!0),e.icon&&(t.icon=e.icon),Object.keys(t).length>0?t:void 0}function U(e,t,a){if(!a||a.length===0)return()=>void 0;let o=new Map;if(r(a))for(let n of e)o.set(n.field,i(t.map(e=>e[n.field])));return(r,i)=>{let s=e[i],c=t[r];if(!s||!c)return;let l=c[s.field];return Qe(n(l,c,s.field,a,o.get(s.field)??null))}}var $e=[`csv`,`tsv`,`html`,`json`,`xml`,`md`],et=null;async function tt(){if(typeof window>`u`)throw Error(`@svgrid/enterprise: export requires a browser environment`);return et||=(async()=>{De(),await h(()=>import(`./smart.export-CDCwbFH4.js`),[],import.meta.url);let e=window.Smart?.Utilities?.DataExporter;if(!e)throw Error(`@svgrid/enterprise: failed to load Smart.Utilities.DataExporter`);return e})(),et}async function W(t){let n=globalThis;if(t===`xlsx`&&n.JSZip==null){let t;try{t=await h(()=>import(`./jszip.min-CX2fPs3O.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1]),import.meta.url)}catch{throw Error(`@svgrid/enterprise: xlsx export requires the "jszip" peer dependency. Install it with: pnpm add jszip`)}n.JSZip=t.default??t}if(t===`pdf`&&n.pdfMake==null){let t,r;try{t=await h(()=>import(`./pdfmake-BpIYFHoG.js`).then(t=>e(t.default,1)),__vite__mapDeps([2,1]),import.meta.url),r=await h(()=>import(`./vfs_fonts-BV-Ul9v2.js`).then(t=>e(t.default,1)),__vite__mapDeps([3,1]),import.meta.url)}catch{throw Error(`@svgrid/enterprise: pdf export requires the "pdfmake" peer dependency. Install it with: pnpm add pdfmake`)}let i=t.default??t;if(!We(i,r))throw Error(`@svgrid/enterprise: "pdfmake/build/vfs_fonts" did not contain a font map; the installed pdfmake is not one this export knows.`);n.pdfMake=i}}function G(e,t){if(Array.isArray(t))return t;switch(t){case`selected`:return e.getSelectedRows();case`all`:return e.getData();case`displayed`:case void 0:default:return e.getDisplayedRows()}}function K(e,t,n){if(t.columns&&t.columns.length>0)return t.columns;let r=e.getColumns().filter(e=>e.visible&&e.field);return r.length>0?r.map(e=>({field:e.field,header:e.header,format:e.format,align:e.align})):n.length>0?Object.keys(n[0]).filter(e=>!e.startsWith(`_`)).map(e=>({field:e})):[]}function q(e,t,n){if(e.exportValue)return e.exportValue(t)??``;let r=t[e.field];return n?r:c(r,e.format)}async function J(e,t,n){let r=n.rawValues===!0,i={};for(let e of t)i[e.field]=e.header??e.field;let a=[i],o=e.length;for(let i=0;i<o;i++){if(n.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);let s=e[i],c={};for(let e of t)c[e.field]=q(e,s,r);a.push(c),i>0&&i%5e3==0&&(n.onProgress?.({phase:`project`,ratio:i/o,row:i,total:o}),await new Promise(e=>setTimeout(e,0)))}return n.onProgress?.({phase:`project`,ratio:1,row:o,total:o}),a}function nt(e){if(!e)return;let t={};e.headerRow&&(t.header={...e.headerRow});let n=e.rows?{...e.rows}:{};return e.rowAlternate&&(n.alternationCount=2,n.alternationStart=0,e.rowAlternate.backgroundColor&&(n.alternationIndex1BackgroundColor=e.rowAlternate.backgroundColor),e.rowAlternate.color&&(n.alternationIndex1Color=e.rowAlternate.color)),Object.keys(n).length>0&&(t.rows=n),e.cells&&(t.cells=e.cells),t}var rt=0,it=new Map;function at(e){let t=it.get(e);if(t)return t;let n=`img${++rt}`;return it.set(e,n),n}function ot(e,t=64,n=64){let r=/^data:image\/([a-zA-Z0-9+]+);/i.exec(e)?.[1]?.toLowerCase()??`png`,i=r===`jpg`?`jpeg`:r===`svg+xml`?`svg`:r;return{id:at(e),base64:e,imageType:i,width:t,height:n}}function st(e,t){if(!e||e.length===0||t.length===0)return;let n=t[0],r=[];for(let i of e){let e={},a;if(`image`in i)e[n]=i.image,a={mergeAcross:!0,textAlign:`left`};else if(`text`in i)e[n]=i.text,a={mergeAcross:!0,...i.style??{}};else{let r=t[Math.floor(t.length/2)],o=t[t.length-1];i.left!==void 0&&(e[n]=i.left),i.center!==void 0&&(e[r]=i.center),i.right!==void 0&&(e[o]=i.right),a={textAlign:`left`}}r.push({cells:e,style:a})}return r}function ct(e,t){let n=e&&e.length>0?new Set(e):null;return(e,r,i)=>typeof i!=`string`||!/^data:image\//i.test(i)?null:n&&!n.has(r)?{image:ot(i,96,96),value:``}:{image:ot(i,t.width,t.height),value:``}}function lt(e){let t={exportHeader:!0,pageOrientation:e.pageOrientation??`portrait`};e.freezeHeader!==!1&&(t.freezeHeader=!0),e.freezeColumns&&e.freezeColumns>0&&(t.freezeColumnsCount=Math.floor(e.freezeColumns));let n=nt(e.styles);if(n&&(t.style=n),e.hierarchical&&(t.hierarchical=!0),e.merges?.length&&!e.groupBy?.length&&!e.hierarchical){let n=e.merges.map(e=>({cell:[e.row,e.col],rowspan:Math.max(1,Math.floor(e.rowSpan??1)),colspan:Math.max(1,Math.floor(e.colSpan??1))})).filter(e=>e.rowspan>1||e.colspan>1);n.length&&(t.mergedCells=n)}return t}function ut(e,t,n){let r=st(t.header,n),i=st(t.footer,n);r&&(e.headerContent=r),i&&(e.footerContent=i);let a=(t.header?.some(e=>`image`in e)??!1)||(t.footer?.some(e=>`image`in e)??!1);if(t.imageFields?.length||a){let n=t.imageSize??{width:32,height:32};e.addImageToCell=ct(t.imageFields,n)}return e}function Y(e,t){return e.toLowerCase().endsWith(`.`+t)?e:`${e}.${t}`}function dt(e,t,n,r,i){return i!==!1&&p(e,t),{blob:e,filename:t,mime:n,rowCount:r,byteSize:e.size}}function ft(e,t,n,r,i){i!==!1&&u(e,t,n);let a=new Blob([e],{type:n});return{blob:a,filename:t,mime:n,rowCount:r,byteSize:a.size}}function X(e,t,n){let r=Math.min(t.length,200);return e.map(e=>{if(typeof e.width==`number`)return e.width;let i=String(e.header??e.field).length;for(let a=0;a<r;a++){let r=q(e,t[a],n),o=r==null?0:String(r).length;o>i&&(i=o)}return Math.max(48,Math.min(400,i*7+14))})}function pt(e,t,n){if(typeof t.freezeColumns==`number`)return t.freezeColumns;let r=e.getColumnPinning().left;if(!r||r.length===0)return;let i=new Set(r),a=0;for(let e of n)if(i.has(e.field))a++;else break;return a>0?a:void 0}function mt(e){let t=e,n=``;do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return n}function Z(e,t){if(e.some(e=>e.link))return(n,r)=>{let i=e[r],a=t[n];if(!(!i?.link||!a))return i.link(a)||void 0}}function ht(e){let t={};for(let n of e)n.align&&(t[n.field]=n.align);return t}async function gt(e,t,n,r,i,s){let c=n.map(e=>e.field),u={onProgress:r.onProgress,signal:r.signal};switch(e){case`html`:return{text:await d(t,c,{...u,title:(r.filename??`grid`).trim()||`grid`,align:ht(n),cellStyle:i,cellLink:s}),mime:`text/html;charset=utf-8`,ext:`html`};case`json`:return{text:await f(t,c,u),mime:`application/json;charset=utf-8`,ext:`json`};case`xml`:return{text:await l(t,c,u),mime:`application/xml;charset=utf-8`,ext:`xml`};case`md`:return{text:await o(t,c,{...u,align:ht(n)}),mime:`text/markdown;charset=utf-8`,ext:`md`};case`tsv`:return{text:await a(t,c,{...u,csv:{...r.csv,delimiter:` `}}),mime:`text/tab-separated-values;charset=utf-8`,ext:`tsv`};default:{let e=r.csv?.delimiter??`,`;return{text:await a(t,c,{...u,csv:{...r.csv,delimiter:e}}),mime:`text/csv;charset=utf-8`,ext:`csv`}}}}async function _t(e,t){if(t.sheets&&t.sheets.length>0)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx', got '${t.format}'`);let n=G(e,t.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let r=K(e,t,n),i=await J(n,r,t.format===`json`?{...t,rawValues:t.rawValues??!0}:t),a=(t.filename??`grid`).trim()||`grid`,o=t.format===`html`?U(r,n,t.conditionalFormats):void 0,s=t.format===`html`?Z(r,n):void 0,{text:c,mime:l,ext:u}=await gt(t.format,i,r,t,o,s);return ft(c,Y(a,u),l,n.length,t.download)}async function vt(e,t){if(t.sheets&&t.sheets.length>0)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx'. Use 'xls' for a single legacy sheet.`);let n=G(e,t.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let r=K(e,t,n),i=(t.filename??`grid`).trim()||`grid`,a=U(r,n,t.conditionalFormats);return ft(await Ae(i,r,n,{rawValues:t.rawValues,onProgress:t.onProgress,signal:t.signal,freezeHeader:t.freezeHeader!==!1,freezeColumns:pt(e,t,r),widths:t.autoFitColumns===!1?void 0:X(r,n,t.rawValues===!0),cellVisual:t.conditionalFormats?.length?a:void 0,precisionSafe:t.precisionSafe}),Y(i,`xls`),`application/vnd.ms-excel;charset=utf-8`,n.length,t.download)}function Q(e){return e.format?.type===`number`||e.format?.type===`currency`}function yt(e,t,n){let r=[],i=t=>e.find(e=>e.field===t)?.header??t,a=e.findIndex(e=>!Q(e)),o=(t,s)=>{if(s>=n.length){for(let n of t)r.push({kind:`data`,cells:e.map(e=>String(q(e,n,!1)??``))});return}let l=n[s],u=new Map;for(let e of t){let t=String(e[l]??``),n=u.get(t);n?n.push(e):u.set(t,[e])}for(let[t,n]of u)if(r.push({kind:`group`,label:`${i(l)}: ${t} (${n.length})`,level:s}),o(n,s+1),e.some(Q)){let i=e.map(e=>{if(!Q(e))return``;let t=n.reduce((t,n)=>t+(Number(n[e.field])||0),0);return c(t,e.format)});a>=0&&(i[a]=`Subtotal (${t})`),r.push({kind:`subtotal`,cells:i})}};return o(t,0),r}async function bt(e,t){await W(`pdf`);let n=globalThis.pdfMake;if(!n)throw Error(`@svgrid/enterprise: pdf export requires the "pdfmake" peer dependency.`);let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=i.map(e=>e.field),o=i.map(e=>({header:e.header??e.field,align:e.align})),s=t.autoGroup!==!1&&!t.groupBy?.length&&!t.hierarchical?(e.getState().grouping??[]).filter(e=>!!e).map(e=>String(e)):[],c=t.groupBy?.length?t.groupBy:s.length>0?s:void 0;if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:r.length});let l={...t.pdf,pageOrientation:t.pdf?.pageOrientation??t.pageOrientation},u=l.matchTheme===!1?{}:qe(e.getElement?.()??null),d={headerLines:t.header,footerLines:t.footer},f=await Ye(l.charts,async e=>{let{chartToPngBlob:t}=await h(async()=>{let{chartToPngBlob:e}=await import(`./src-CITpcm6b.js`).then(e=>e.t);return{chartToPngBlob:e}},__vite__mapDeps([4,1,5]),import.meta.url);return t(e,{scale:2})}),p=new Date,m;if(c?.length)m=Xe({columns:o,body:yt(i,r,c),opts:l,styles:t.styles,theme:u,...d,charts:f,now:p});else{let e=(await J(r,i,t)).slice(1).map(e=>a.map(t=>String(e[t]??``))),n=U(i,r,t.conditionalFormats);for(let t=0;t<e.length;t++)for(let r=0;r<i.length;r++){let i=n(t,r)?.icon;i&&(e[t][r]=`${i} ${e[t][r]??``}`)}m=Xe({columns:o,rows:e,dataCellStyle:(e,t)=>{let r=n(e,t);return r?{fill:r.fill,color:r.color,bold:r.bold}:void 0},dataCellLink:Z(i,r),opts:l,styles:t.styles,theme:u,...d,merges:t.merges,charts:f,now:p})}let g=(t.filename??`grid`).trim()||`grid`,_=await new Promise(e=>n.createPdf(m).getBlob(e));return t.onProgress?.({phase:`write`,ratio:1,total:r.length}),dt(_,Y(g,`pdf`),`application/pdf`,r.length,t.download)}async function xt(e,t,n,r,i,a){let o=e.map(e=>e.header??e.field),l=a?.precisionSafe===!0,u=(e,t,n)=>l&&Math.abs(e)>=0x38d7ea4c68000?{t:`s`,value:String(e),...t}:{t:`n`,value:e,numFmt:n,...t},d=(t,a,o)=>{let l=e[o],d=r(a,o),f={align:l.align,fill:d?.fill,color:d?.color,bold:d?.bold,link:i?.(a,o)};if(l.exportValue){let e=l.exportValue(t);return typeof e==`number`&&Number.isFinite(e)?u(e,f,m(l.format)):e instanceof Date?{t:`d`,value:e,numFmt:m(l.format)??`yyyy-mm-dd`,...f}:{t:`s`,value:e==null?``:String(e),...f}}let p=t[l.field];if(d?.icon){let e=n?String(p??``):c(p,l.format);return{t:`s`,value:`${d.icon} ${e}`,...f}}if(n)return typeof p==`number`&&Number.isFinite(p)?u(p,f):{t:`s`,value:p==null?``:String(p),...f};let h=s(p,l.format);return h.ok?h.value instanceof Date?{t:`d`,value:h.value,numFmt:m(l.format)??`yyyy-mm-dd`,...f}:u(h.value,f,m(l.format)):{t:`s`,value:c(p,l.format),...f}},f=[],p=t.length;for(let n=0;n<p;n++){if(a?.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);let r=t[n];f.push(e.map((e,t)=>d(r,n,t))),n>0&&n%2e3==0&&(a?.onProgress?.({phase:`project`,ratio:n/p,row:n,total:p}),await new Promise(e=>setTimeout(e,0)))}return{header:o,cells:f}}async function St(e,t){await W(`xlsx`);let n=globalThis.JSZip;if(!n)throw Error(`@svgrid/enterprise: xlsx export requires the "jszip" peer dependency.`);let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=t.rawValues===!0,o=t.conditionalFormats??[],s=U(i,r,o.filter(e=>e.type===`rule`||e.type===`iconSet`)),c=Z(i,r),l=[];for(let e of o){if(e.type!==`colorScale`&&e.type!==`dataBar`)continue;let t=e.columns&&e.columns.length>0?i.map((t,n)=>e.columns.includes(t.field)?n:-1).filter(e=>e>=0):i.map((e,t)=>t);for(let n of t)if(e.type===`dataBar`)l.push({kind:`dataBar`,colIdx:n,color:e.color});else{let t=e.min??`#ffffff`,r=e.max??`#000000`;l.push({kind:`colorScale`,colIdx:n,colors:e.mid?[t,e.mid,r]:[t,r]})}}if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:r.length});let{header:u,cells:d}=await xt(i,r,a,s,c,{onProgress:t.onProgress,signal:t.signal,precisionSafe:t.precisionSafe}),f=t.autoFitColumns===!1?void 0:X(i,r,a),p=(t.filename??`grid`).trim()||`grid`,m;t.excelTable&&(m={name:`Table1`,totalsRow:typeof t.excelTable==`object`&&t.excelTable.totalsRow===!0,style:typeof t.excelTable==`object`?t.excelTable.style:void 0,totalsFns:i.map(e=>Q(e)?`sum`:void 0)});let h=await He(Ve({sheetName:p,header:u,rows:d,widths:f,freezeHeader:t.freezeHeader!==!1,freezeColumns:pt(e,t,i),condFormats:l,table:m}),n);return t.onProgress?.({phase:`write`,ratio:1,total:r.length}),dt(h,Y(p,`xlsx`),`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,r.length,t.download)}async function Ct(e,t){if(Te(`Export`),$e.includes(t.format))return _t(e,t);if(t.format===`xls`)return vt(e,t);if(t.format===`pdf`)return bt(e,t);if(t.format===`xlsx`){let n=t.autoGroup===!1?[]:(e.getState().grouping??[]).filter(e=>!!e),r=(t.groupBy?.length??0)>0||n.length>0,i=!!t.styles&&!t.conditionalFormats?.length;if(!t.sheets?.length&&!r&&!t.hierarchical&&!t.merges?.length&&!t.header?.length&&!t.footer?.length&&!t.imageFields?.length&&!i)return St(e,t)}await W(t.format);let n=await tt();if(t.sheets&&t.sheets.length>0){if(t.format!==`xlsx`)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx', got '${t.format}'`);let r=t.rawValues===!0,i=t.sheets.map(n=>{let i=K(e,{columns:n.columns??t.columns},n.rows),a=n.rows.map(e=>{let t={};for(let n of i)t[n.field]=q(n,e,r);return t}),o=t.autoFitColumns===!1?null:X(i,n.rows,r);return{label:n.label,dataSource:a,columns:i.map((e,t)=>o?{dataField:e.field,label:e.header??e.field,width:o[t]}:{dataField:e.field,label:e.header??e.field}),dataFields:i.map(e=>e.field),style:nt(n.styles??t.styles)}}),a=(t.filename??`grid`).trim()||`grid`,o=lt(t),s=i[0],c=new n(o);c.spreadsheets=i,ut(c,t,s.dataFields);let l={};for(let e of s.columns)l[e.dataField]=e.label;let u=[l,...s.dataSource];if(t.download===!1)throw Error(`@svgrid/enterprise: download:false is not supported for multi-sheet xlsx.`);c.exportData(u,t.format,a);return}let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=await J(r,i,t),o=(t.filename??`grid`).trim()||`grid`,s=i.map(e=>e.field),c=t.autoGroup!==!1&&!t.groupBy?.length&&!t.hierarchical?(e.getState().grouping??[]).filter(e=>!!e).map(e=>String(e)):[],l=t.groupBy?.length?t.groupBy:c.length>0?c:void 0,u=!t.hierarchical&&l?.length?l:void 0,d=lt(t);if(t.conditionalFormats?.length){let e=U(i,r,t.conditionalFormats),n={};for(let t=0;t<r.length;t++)for(let r=0;r<i.length;r++){let o=e(t,r);if(!o)continue;let s={};if(o.fill&&(s.backgroundColor=o.fill),o.color&&(s.color=o.color),o.bold&&(s.fontWeight=`bold`),Object.keys(s).length&&(n[mt(r)+(t+2)]=s),o.icon){let e=a[t+1],n=i[r].field;e&&(e[n]=`${o.icon} ${e[n]??``}`)}}if(Object.keys(n).length){let e=d.style??{};d.style={...e,cells:{...e.cells??{},...n}}}}if(t.download===!1)throw Error(`@svgrid/enterprise: download:false is not supported for this xlsx export (grouped / merges / header / footer / images). Use a plain xlsx, xls, pdf, or a text format.`);if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:a.length-1});let f=new n(d,u);ut(f,t,s),f.exportData(a,t.format,o),t.onProgress?.({phase:`write`,ratio:1,total:a.length-1})}var wt={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};function $(e){return(e==null?``:String(e)).replace(/[&<>"']/g,e=>wt[e])}function Tt(e){let{columns:t,rows:n}=e,r=e.cellStyle,i=e.cellLink,a=e.opts??{},o=a.orientation??`portrait`,s=a.pageSize?`${a.pageSize} ${o}`:o,c=a.margin??`14mm`,l=a.zebra??!0,u=a.zebraColor??`#f6f8fa`,d=a.headerColor??`#f1f5f9`,f=a.headerTextColor??`#0f172a`,p=a.fontSize??9,m=e=>e&&e!==`left`?` style="text-align:${e}"`:``,h=`<thead><tr>`+t.map(e=>`<th${m(e.align)}>${$(e.header)}</th>`).join(``)+`</tr></thead>`,g=(e,t,n,a)=>{let o=[];e.align&&e.align!==`left`&&o.push(`text-align:${e.align}`);let s=r?.(n,a);s?.fill&&o.push(`background:${s.fill}`),s?.color&&o.push(`color:${s.color}`),s?.bold&&o.push(`font-weight:700`);let c=o.length?` style="${o.join(`;`)}"`:``,l=s?.icon?`${$(s.icon)} ${$(t)}`:$(t),u=i?.(n,a);return u&&(l=`<a href="${$(u)}">${l}</a>`),`<td${c}>${l}</td>`},_=`<tbody>`+n.map((e,n)=>`<tr>`+t.map((t,r)=>g(t,e[r]??``,n,r)).join(``)+`</tr>`).join(``)+`</tbody>`,v=[];return a.logo&&v.push(`<img class="logo" src="${$(a.logo)}" alt="" />`),a.title&&v.push(`<h1>${$(a.title)}</h1>`),a.subtitle&&v.push(`<p class="subtitle">${$(a.subtitle)}</p>`),`<!DOCTYPE html>
38
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`+e.join(``)+`</Relationships>`}return g}async function He(e,t){let n=new t;for(let[t,r]of Object.entries(e))n.file(t,r);return n.generateAsync({type:`blob`,mimeType:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`})}function Ue(e){let t=e=>!!e&&typeof e==`object`&&Object.keys(e).some(e=>/\.(ttf|otf)$/i.test(e))&&Object.values(e).every(e=>typeof e==`string`),n=new Set,r=e=>{if(!e||typeof e!=`object`||n.has(e))return null;if(n.add(e),t(e))return e;let i=e;return r(i.pdfMake?.vfs)??r(i.vfs)??r(i.default)};return r(e)}function We(e){return new Promise((t,n)=>{let r=e.getBlob(t);r&&typeof r.then==`function`&&r.then(t,n)})}function Ge(e,t){let n=Ue(t);return n?(typeof e.addVirtualFileSystem==`function`&&e.addVirtualFileSystem(n),e.vfs=n,!0):!1}function Ke(e){if(!e)return null;let t=e.trim(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t);if(n){let e=n[1];return`#`+(e.length===3?e.split(``).map(e=>e+e).join(``):e).toLowerCase()}let r=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/i.exec(t);if(!r||!((r[4]===void 0?1:r[4].endsWith(`%`)?Number(r[4].slice(0,-1))/100:Number(r[4]))>.05))return null;let i=e=>Math.max(0,Math.min(255,Math.round(Number(e)))).toString(16).padStart(2,`0`);return`#`+i(r[1])+i(r[2])+i(r[3])}function qe(e){let t=parseInt(e.slice(1),16),n=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*n(t>>16&255)+.7152*n(t>>8&255)+.0722*n(t&255)}function Je(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=t=>e.querySelector(t),n=(e,t)=>e?Ke(getComputedStyle(e).getPropertyValue(t)):null,r=e=>{for(let t=e;t;t=t.parentElement){let e=n(t,`background-color`);if(e)return e}return null},i=`:not([class*="row-number"]):not([class*="selection"])`,a=t(`.sv-grid-head .sv-grid-column${i}`)??t(`.sv-grid-header-cell`)??t(`thead th`),o=t(`.sv-grid-body .sv-grid-row:not(.sv-grid-row-alt):not(.sv-grid-header-row) .sv-grid-cell${i}`)??t(`tbody td`),s=t(`.sv-grid-body .sv-grid-row-alt .sv-grid-cell${i}`),c=t(`.sv-grid-group-row .sv-grid-cell`),l={},u=r(a),d=n(a,`color`);u&&(l.headerColor=u),d&&(l.headerTextColor=d);let f=r(o?o.parentElement:t(`.sv-grid-container`)??e),p=n(o,`color`);if(f&&qe(f)<.4||p&&qe(p)>.5)return l;p&&(l.textColor=p);let m=n(o,`border-bottom-color`)??n(a,`border-bottom-color`);m&&(l.borderColor=m);let h=n(s,`background-color`);h&&h!==f&&(l.zebraColor=h);let g=n(c,`background-color`),_=n(c,`color`);return g&&g!==f&&(l.groupColor=g),_&&(l.groupTextColor=_),l}var Ye={A4:[595.28,841.89],A3:[841.89,1190.55],A5:[419.53,595.28],LETTER:[612,792],LEGAL:[612,1008]};async function Xe(e,t){if(!e?.length)return[];let n=[];for(let r of e){if(`image`in r){n.push(r);continue}let e=await t(r.element),i=await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error??Error(`could not read the chart image`)),r.readAsDataURL(e)});n.push({image:i,title:r.title,caption:r.caption,width:r.width})}return n}function Ze(e){let{columns:t}=e,n=e.opts??{},r=e.styles??{},i=e.theme??{},a=e.now??new Date(0),o=n.fontSize??8,s=n.headerColor??r.headerRow?.backgroundColor??i.headerColor??`#334155`,c=n.headerTextColor??r.headerRow?.color??i.headerTextColor??`#ffffff`,l=n.zebra??!0,u=n.zebraColor??r.rowAlternate?.backgroundColor??i.zebraColor??`#f1f5f9`,d=n.groupColor??i.groupColor??`#e2e8f0`,f=n.groupTextColor??i.groupTextColor??`#0f172a`,p=n.subtotalColor??i.subtotalColor??`#f8fafc`,m=n.textColor??r.rows?.color??i.textColor,h=n.borderColor??i.borderColor??`#e2e8f0`,g=n.repeatHeader??!0,_=e=>e===`bold`||typeof e==`number`&&e>=600,v=e=>{if(e===void 0)return;let t=typeof e==`number`?e:parseFloat(e);return Number.isFinite(t)&&t>0?t:void 0},y=(e,t)=>{if(!t)return;t.backgroundColor&&(e.fillColor=t.backgroundColor),t.color&&(e.color=t.color),_(t.fontWeight)?e.bold=!0:t.fontWeight===`normal`&&(e.bold=!1),t.fontStyle===`italic`&&(e.italics=!0);let n=v(t.fontSize);n&&(e.fontSize=n),t.textAlign&&(e.alignment=t.textAlign)},b=new Map;for(let[e,t]of Object.entries(r.cells??{})){let n=/^([A-Z]+)(\d+)$/i.exec(e.trim());if(!n)continue;let r=0;for(let e of n[1].toUpperCase())r=r*26+(e.charCodeAt(0)-64);b.set(`${Number(n[2])-1}:${r-1}`,t)}let x=n.pageOrientation??(t.length>(n.autoLandscapeThreshold??8)?`landscape`:`portrait`),S=Array.isArray(n.columnWidths)?n.columnWidths:t.map(()=>n.columnWidths===`auto`?`auto`:`*`),C=t.map((e,t)=>{let n={text:e.header,bold:!0,alignment:e.align??`left`,color:c,fillColor:s};return y(n,r.headerRow?{...r.headerRow,backgroundColor:void 0,color:void 0}:void 0),y(n,b.get(`0:${t}`)),n}),w=e.body??(e.rows??[]).map(e=>({kind:`data`,cells:e})),ee=e.dataCellStyle,te=e.dataCellLink,ne=0,T=new Set,E=[C];if(w.forEach((e,n)=>{let i=n+1;if(e.kind===`group`){let n={text:e.label,bold:!0,color:f,fillColor:d,colSpan:t.length,margin:[(e.level??0)*12,2,0,2]},r=Array.from({length:Math.max(0,t.length-1)},()=>({text:``}));E.push([n,...r])}else if(e.kind===`subtotal`)E.push(t.map((t,n)=>({text:e.cells[n]??``,bold:!0,alignment:t.align??`left`,fillColor:p})));else{T.add(i);let n=ne++;E.push(t.map((t,i)=>{let a={text:e.cells[i]??``,alignment:t.align??`left`};m&&(a.color=m),y(a,r.rows?{...r.rows,backgroundColor:void 0}:void 0),l&&n%2==1&&r.rowAlternate?.color&&(a.color=r.rowAlternate.color),y(a,b.get(`${n+1}:${i}`));let o=ee?.(n,i);o&&(o.fill&&(a.fillColor=o.fill),o.color&&(a.color=o.color),o.bold&&(a.bold=!0));let s=te?.(n,i);return s&&(a.link=s,a.decoration=`underline`,o?.color||(a.color=`#2563eb`)),a}))}}),e.merges?.length&&!e.body){let n=[...T].sort((e,t)=>e-t);for(let r of e.merges){let e=Math.max(1,Math.floor(r.rowSpan??1)),i=Math.max(1,Math.floor(r.colSpan??1));if(e===1&&i===1)continue;let a=n[r.row];if(a===void 0||r.col<0||r.col>=t.length)continue;let o=E[a]?.[r.col];if(o){e>1&&(o.rowSpan=Math.min(e,E.length-a)),i>1&&(o.colSpan=Math.min(i,t.length-r.col));for(let e=0;e<(o.rowSpan??1);e+=1)for(let t=0;t<(o.colSpan??1);t+=1){if(e===0&&t===0)continue;let n=E[a+e]?.[r.col+t];n&&(n.text=``)}}}}let D={table:{headerRows:+!!g,dontBreakRows:!0,widths:S,body:E},layout:{fillColor:e=>l&&e>0&&e%2==0&&T.has(e)?u:null,hLineWidth:()=>.5,vLineWidth:()=>.5,hLineColor:()=>h,vLineColor:()=>h,paddingTop:()=>3,paddingBottom:()=>3,paddingLeft:()=>5,paddingRight:()=>5}},O=(e,t)=>(e??[]).map(e=>{if(`image`in e)return{image:e.image,...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},margin:t};if(`text`in e){let n={text:e.text};return y(n,e.style),{...n,margin:t}}return{columns:[{text:e.left??``,alignment:`left`},{text:e.center??``,alignment:`center`},{text:e.right??``,alignment:`right`}],margin:t}}),k=[];if(k.push(...O(e.headerLines,[0,0,0,4])),n.logo&&k.push({image:n.logo,width:n.logoWidth??90,margin:[0,0,0,8]}),n.title&&k.push({text:n.title,fontSize:o+8,bold:!0,margin:[0,0,0,2]}),n.subtitle&&k.push({text:n.subtitle,fontSize:o+1,color:`#64748b`,margin:[0,0,0,8]}),n.kpis?.length){let e=n.kpiColor??`#f8fafc`;k.push({table:{widths:n.kpis.map(()=>`*`),body:[n.kpis.map(t=>({fillColor:e,margin:[8,6,8,6],stack:[{text:t.label,fontSize:o,color:`#64748b`},{text:t.value,fontSize:o+10,bold:!0,margin:[0,2,0,0]},...t.delta?[{text:t.delta,fontSize:o,color:t.color??`#64748b`,margin:[0,2,0,0]}]:[]]}))]},layout:{hLineWidth:()=>0,vLineWidth:()=>4,vLineColor:()=>`#ffffff`,paddingLeft:()=>0,paddingRight:()=>0,paddingTop:()=>0,paddingBottom:()=>0},margin:[0,0,0,10]})}let A=n.margins??[28,34,28,34],[re,ie]=Ye[n.pageSize??`A4`],j=(x===`landscape`?ie:re)-A[0]-A[2],M=(e.charts??(n.charts??[]).filter(e=>`image`in e)).map(e=>({stack:[...e.title?[{text:e.title,fontSize:o+3,bold:!0,margin:[0,0,0,4]}]:[],{image:e.image,width:Math.min(e.width??j,j)},...e.caption?[{text:e.caption,fontSize:o,color:`#64748b`,margin:[0,3,0,0]}]:[]],margin:[0,0,0,12],unbreakable:!0}));n.chartsPosition!==`below`&&k.push(...M),k.push(D),n.chartsPosition===`below`&&(M.length&&k.push({text:``,margin:[0,0,0,12]}),k.push(...M)),k.push(...O(e.footerLines,[0,4,0,0]));let N={pageSize:n.pageSize??`A4`,pageOrientation:x,pageMargins:n.margins??[28,34,28,34],defaultStyle:{fontSize:o},content:k};if(n.showPageNumbers??!0){let e=a.toISOString().slice(0,10);N.footer=(t,n)=>({margin:[28,6,28,0],columns:[{text:e,alignment:`left`,fontSize:7,color:`#94a3b8`},{text:`Page ${t} of ${n}`,alignment:`right`,fontSize:7,color:`#94a3b8`}]})}return N}function Qe(e,t){let n=/^#?([0-9a-f]{6})$/i.exec(e.trim());if(!n)return e;let r=parseInt(n[1],16);return`#`+[r>>16&255,r>>8&255,r&255].map(e=>Math.round(e+(255-e)*t).toString(16).padStart(2,`0`)).join(``)}function $e(e){let t={};return e.background&&(t.fill=e.background),!t.fill&&e.dataBar&&(t.fill=Qe(e.dataBar.color,.72)),e.color&&e.color!==`transparent`&&(t.color=e.color),(e.fontWeight===`bold`||typeof e.fontWeight==`number`&&e.fontWeight>=600)&&(t.bold=!0),e.icon&&(t.icon=e.icon),Object.keys(t).length>0?t:void 0}function U(e,t,a){if(!a||a.length===0)return()=>void 0;let o=new Map;if(r(a))for(let n of e)o.set(n.field,i(t.map(e=>e[n.field])));return(r,i)=>{let s=e[i],c=t[r];if(!s||!c)return;let l=c[s.field];return $e(n(l,c,s.field,a,o.get(s.field)??null))}}var et=[`csv`,`tsv`,`html`,`json`,`xml`,`md`],tt=null;async function nt(){if(typeof window>`u`)throw Error(`@svgrid/enterprise: export requires a browser environment`);return tt||=(async()=>{De(),await h(()=>import(`./smart.export-CDCwbFH4.js`),[],import.meta.url);let e=window.Smart?.Utilities?.DataExporter;if(!e)throw Error(`@svgrid/enterprise: failed to load Smart.Utilities.DataExporter`);return e})(),tt}async function W(t){let n=globalThis;if(t===`xlsx`&&n.JSZip==null){let t;try{t=await h(()=>import(`./jszip.min-CX2fPs3O.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1]),import.meta.url)}catch{throw Error(`@svgrid/enterprise: xlsx export requires the "jszip" peer dependency. Install it with: pnpm add jszip`)}n.JSZip=t.default??t}if(t===`pdf`&&n.pdfMake==null){let t,r;try{t=await h(()=>import(`./pdfmake-BpIYFHoG.js`).then(t=>e(t.default,1)),__vite__mapDeps([2,1]),import.meta.url),r=await h(()=>import(`./vfs_fonts-BV-Ul9v2.js`).then(t=>e(t.default,1)),__vite__mapDeps([3,1]),import.meta.url)}catch{throw Error(`@svgrid/enterprise: pdf export requires the "pdfmake" peer dependency. Install it with: pnpm add pdfmake`)}let i=t.default??t;if(!Ge(i,r))throw Error(`@svgrid/enterprise: "pdfmake/build/vfs_fonts" did not contain a font map; the installed pdfmake is not one this export knows.`);n.pdfMake=i}}function G(e,t){if(Array.isArray(t))return t;switch(t){case`selected`:return e.getSelectedRows();case`all`:return e.getData();case`displayed`:case void 0:default:return e.getDisplayedRows()}}function K(e,t,n){if(t.columns&&t.columns.length>0)return t.columns;let r=e.getColumns().filter(e=>e.visible&&e.field);return r.length>0?r.map(e=>({field:e.field,header:e.header,format:e.format,align:e.align})):n.length>0?Object.keys(n[0]).filter(e=>!e.startsWith(`_`)).map(e=>({field:e})):[]}function q(e,t,n){if(e.exportValue)return e.exportValue(t)??``;let r=t[e.field];return n?r:c(r,e.format)}async function J(e,t,n){let r=n.rawValues===!0,i={};for(let e of t)i[e.field]=e.header??e.field;let a=[i],o=e.length;for(let i=0;i<o;i++){if(n.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);let s=e[i],c={};for(let e of t)c[e.field]=q(e,s,r);a.push(c),i>0&&i%5e3==0&&(n.onProgress?.({phase:`project`,ratio:i/o,row:i,total:o}),await new Promise(e=>setTimeout(e,0)))}return n.onProgress?.({phase:`project`,ratio:1,row:o,total:o}),a}function rt(e){if(!e)return;let t={};e.headerRow&&(t.header={...e.headerRow});let n=e.rows?{...e.rows}:{};return e.rowAlternate&&(n.alternationCount=2,n.alternationStart=0,e.rowAlternate.backgroundColor&&(n.alternationIndex1BackgroundColor=e.rowAlternate.backgroundColor),e.rowAlternate.color&&(n.alternationIndex1Color=e.rowAlternate.color)),Object.keys(n).length>0&&(t.rows=n),e.cells&&(t.cells=e.cells),t}var it=0,at=new Map;function ot(e){let t=at.get(e);if(t)return t;let n=`img${++it}`;return at.set(e,n),n}function st(e,t=64,n=64){let r=/^data:image\/([a-zA-Z0-9+]+);/i.exec(e)?.[1]?.toLowerCase()??`png`,i=r===`jpg`?`jpeg`:r===`svg+xml`?`svg`:r;return{id:ot(e),base64:e,imageType:i,width:t,height:n}}function ct(e,t){if(!e||e.length===0||t.length===0)return;let n=t[0],r=[];for(let i of e){let e={},a;if(`image`in i)e[n]=i.image,a={mergeAcross:!0,textAlign:`left`};else if(`text`in i)e[n]=i.text,a={mergeAcross:!0,...i.style??{}};else{let r=t[Math.floor(t.length/2)],o=t[t.length-1];i.left!==void 0&&(e[n]=i.left),i.center!==void 0&&(e[r]=i.center),i.right!==void 0&&(e[o]=i.right),a={textAlign:`left`}}r.push({cells:e,style:a})}return r}function lt(e,t){let n=e&&e.length>0?new Set(e):null;return(e,r,i)=>typeof i!=`string`||!/^data:image\//i.test(i)?null:n&&!n.has(r)?{image:st(i,96,96),value:``}:{image:st(i,t.width,t.height),value:``}}function ut(e){let t={exportHeader:!0,pageOrientation:e.pageOrientation??`portrait`};e.freezeHeader!==!1&&(t.freezeHeader=!0),e.freezeColumns&&e.freezeColumns>0&&(t.freezeColumnsCount=Math.floor(e.freezeColumns));let n=rt(e.styles);if(n&&(t.style=n),e.hierarchical&&(t.hierarchical=!0),e.merges?.length&&!e.groupBy?.length&&!e.hierarchical){let n=e.merges.map(e=>({cell:[e.row,e.col],rowspan:Math.max(1,Math.floor(e.rowSpan??1)),colspan:Math.max(1,Math.floor(e.colSpan??1))})).filter(e=>e.rowspan>1||e.colspan>1);n.length&&(t.mergedCells=n)}return t}function dt(e,t,n){let r=ct(t.header,n),i=ct(t.footer,n);r&&(e.headerContent=r),i&&(e.footerContent=i);let a=(t.header?.some(e=>`image`in e)??!1)||(t.footer?.some(e=>`image`in e)??!1);if(t.imageFields?.length||a){let n=t.imageSize??{width:32,height:32};e.addImageToCell=lt(t.imageFields,n)}return e}function Y(e,t){return e.toLowerCase().endsWith(`.`+t)?e:`${e}.${t}`}function ft(e,t,n,r,i){return i!==!1&&p(e,t),{blob:e,filename:t,mime:n,rowCount:r,byteSize:e.size}}function pt(e,t,n,r,i){i!==!1&&u(e,t,n);let a=new Blob([e],{type:n});return{blob:a,filename:t,mime:n,rowCount:r,byteSize:a.size}}function X(e,t,n){let r=Math.min(t.length,200);return e.map(e=>{if(typeof e.width==`number`)return e.width;let i=String(e.header??e.field).length;for(let a=0;a<r;a++){let r=q(e,t[a],n),o=r==null?0:String(r).length;o>i&&(i=o)}return Math.max(48,Math.min(400,i*7+14))})}function mt(e,t,n){if(typeof t.freezeColumns==`number`)return t.freezeColumns;let r=e.getColumnPinning().left;if(!r||r.length===0)return;let i=new Set(r),a=0;for(let e of n)if(i.has(e.field))a++;else break;return a>0?a:void 0}function ht(e){let t=e,n=``;do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return n}function Z(e,t){if(e.some(e=>e.link))return(n,r)=>{let i=e[r],a=t[n];if(!(!i?.link||!a))return i.link(a)||void 0}}function gt(e){let t={};for(let n of e)n.align&&(t[n.field]=n.align);return t}async function _t(e,t,n,r,i,s){let c=n.map(e=>e.field),u={onProgress:r.onProgress,signal:r.signal};switch(e){case`html`:return{text:await d(t,c,{...u,title:(r.filename??`grid`).trim()||`grid`,align:gt(n),cellStyle:i,cellLink:s}),mime:`text/html;charset=utf-8`,ext:`html`};case`json`:return{text:await f(t,c,u),mime:`application/json;charset=utf-8`,ext:`json`};case`xml`:return{text:await l(t,c,u),mime:`application/xml;charset=utf-8`,ext:`xml`};case`md`:return{text:await o(t,c,{...u,align:gt(n)}),mime:`text/markdown;charset=utf-8`,ext:`md`};case`tsv`:return{text:await a(t,c,{...u,csv:{...r.csv,delimiter:` `}}),mime:`text/tab-separated-values;charset=utf-8`,ext:`tsv`};default:{let e=r.csv?.delimiter??`,`;return{text:await a(t,c,{...u,csv:{...r.csv,delimiter:e}}),mime:`text/csv;charset=utf-8`,ext:`csv`}}}}async function vt(e,t){if(t.sheets&&t.sheets.length>0)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx', got '${t.format}'`);let n=G(e,t.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let r=K(e,t,n),i=await J(n,r,t.format===`json`?{...t,rawValues:t.rawValues??!0}:t),a=(t.filename??`grid`).trim()||`grid`,o=t.format===`html`?U(r,n,t.conditionalFormats):void 0,s=t.format===`html`?Z(r,n):void 0,{text:c,mime:l,ext:u}=await _t(t.format,i,r,t,o,s);return pt(c,Y(a,u),l,n.length,t.download)}async function yt(e,t){if(t.sheets&&t.sheets.length>0)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx'. Use 'xls' for a single legacy sheet.`);let n=G(e,t.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let r=K(e,t,n),i=(t.filename??`grid`).trim()||`grid`,a=U(r,n,t.conditionalFormats);return pt(await Ae(i,r,n,{rawValues:t.rawValues,onProgress:t.onProgress,signal:t.signal,freezeHeader:t.freezeHeader!==!1,freezeColumns:mt(e,t,r),widths:t.autoFitColumns===!1?void 0:X(r,n,t.rawValues===!0),cellVisual:t.conditionalFormats?.length?a:void 0,precisionSafe:t.precisionSafe}),Y(i,`xls`),`application/vnd.ms-excel;charset=utf-8`,n.length,t.download)}function Q(e){return e.format?.type===`number`||e.format?.type===`currency`}function bt(e,t,n){let r=[],i=t=>e.find(e=>e.field===t)?.header??t,a=e.findIndex(e=>!Q(e)),o=(t,s)=>{if(s>=n.length){for(let n of t)r.push({kind:`data`,cells:e.map(e=>String(q(e,n,!1)??``))});return}let l=n[s],u=new Map;for(let e of t){let t=String(e[l]??``),n=u.get(t);n?n.push(e):u.set(t,[e])}for(let[t,n]of u)if(r.push({kind:`group`,label:`${i(l)}: ${t} (${n.length})`,level:s}),o(n,s+1),e.some(Q)){let i=e.map(e=>{if(!Q(e))return``;let t=n.reduce((t,n)=>t+(Number(n[e.field])||0),0);return c(t,e.format)});a>=0&&(i[a]=`Subtotal (${t})`),r.push({kind:`subtotal`,cells:i})}};return o(t,0),r}async function xt(e,t){await W(`pdf`);let n=globalThis.pdfMake;if(!n)throw Error(`@svgrid/enterprise: pdf export requires the "pdfmake" peer dependency.`);let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=i.map(e=>e.field),o=i.map(e=>({header:e.header??e.field,align:e.align})),s=t.autoGroup!==!1&&!t.groupBy?.length&&!t.hierarchical?(e.getState().grouping??[]).filter(e=>!!e).map(e=>String(e)):[],c=t.groupBy?.length?t.groupBy:s.length>0?s:void 0;if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:r.length});let l={...t.pdf,pageOrientation:t.pdf?.pageOrientation??t.pageOrientation},u=l.matchTheme===!1?{}:Je(e.getElement?.()??null),d={headerLines:t.header,footerLines:t.footer},f=await Xe(l.charts,async e=>{let{chartToPngBlob:t}=await h(async()=>{let{chartToPngBlob:e}=await import(`./src-CITpcm6b.js`).then(e=>e.t);return{chartToPngBlob:e}},__vite__mapDeps([4,1,5]),import.meta.url);return t(e,{scale:2})}),p=new Date,m;if(c?.length)m=Ze({columns:o,body:bt(i,r,c),opts:l,styles:t.styles,theme:u,...d,charts:f,now:p});else{let e=(await J(r,i,t)).slice(1).map(e=>a.map(t=>String(e[t]??``))),n=U(i,r,t.conditionalFormats);for(let t=0;t<e.length;t++)for(let r=0;r<i.length;r++){let i=n(t,r)?.icon;i&&(e[t][r]=`${i} ${e[t][r]??``}`)}m=Ze({columns:o,rows:e,dataCellStyle:(e,t)=>{let r=n(e,t);return r?{fill:r.fill,color:r.color,bold:r.bold}:void 0},dataCellLink:Z(i,r),opts:l,styles:t.styles,theme:u,...d,merges:t.merges,charts:f,now:p})}let g=(t.filename??`grid`).trim()||`grid`,_=await We(n.createPdf(m));return t.onProgress?.({phase:`write`,ratio:1,total:r.length}),ft(_,Y(g,`pdf`),`application/pdf`,r.length,t.download)}async function St(e,t,n,r,i,a){let o=e.map(e=>e.header??e.field),l=a?.precisionSafe===!0,u=(e,t,n)=>l&&Math.abs(e)>=0x38d7ea4c68000?{t:`s`,value:String(e),...t}:{t:`n`,value:e,numFmt:n,...t},d=(t,a,o)=>{let l=e[o],d=r(a,o),f={align:l.align,fill:d?.fill,color:d?.color,bold:d?.bold,link:i?.(a,o)};if(l.exportValue){let e=l.exportValue(t);return typeof e==`number`&&Number.isFinite(e)?u(e,f,m(l.format)):e instanceof Date?{t:`d`,value:e,numFmt:m(l.format)??`yyyy-mm-dd`,...f}:{t:`s`,value:e==null?``:String(e),...f}}let p=t[l.field];if(d?.icon){let e=n?String(p??``):c(p,l.format);return{t:`s`,value:`${d.icon} ${e}`,...f}}if(n)return typeof p==`number`&&Number.isFinite(p)?u(p,f):{t:`s`,value:p==null?``:String(p),...f};let h=s(p,l.format);return h.ok?h.value instanceof Date?{t:`d`,value:h.value,numFmt:m(l.format)??`yyyy-mm-dd`,...f}:u(h.value,f,m(l.format)):{t:`s`,value:c(p,l.format),...f}},f=[],p=t.length;for(let n=0;n<p;n++){if(a?.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);let r=t[n];f.push(e.map((e,t)=>d(r,n,t))),n>0&&n%2e3==0&&(a?.onProgress?.({phase:`project`,ratio:n/p,row:n,total:p}),await new Promise(e=>setTimeout(e,0)))}return{header:o,cells:f}}async function Ct(e,t){await W(`xlsx`);let n=globalThis.JSZip;if(!n)throw Error(`@svgrid/enterprise: xlsx export requires the "jszip" peer dependency.`);let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=t.rawValues===!0,o=t.conditionalFormats??[],s=U(i,r,o.filter(e=>e.type===`rule`||e.type===`iconSet`)),c=Z(i,r),l=[];for(let e of o){if(e.type!==`colorScale`&&e.type!==`dataBar`)continue;let t=e.columns&&e.columns.length>0?i.map((t,n)=>e.columns.includes(t.field)?n:-1).filter(e=>e>=0):i.map((e,t)=>t);for(let n of t)if(e.type===`dataBar`)l.push({kind:`dataBar`,colIdx:n,color:e.color});else{let t=e.min??`#ffffff`,r=e.max??`#000000`;l.push({kind:`colorScale`,colIdx:n,colors:e.mid?[t,e.mid,r]:[t,r]})}}if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:r.length});let{header:u,cells:d}=await St(i,r,a,s,c,{onProgress:t.onProgress,signal:t.signal,precisionSafe:t.precisionSafe}),f=t.autoFitColumns===!1?void 0:X(i,r,a),p=(t.filename??`grid`).trim()||`grid`,m;t.excelTable&&(m={name:`Table1`,totalsRow:typeof t.excelTable==`object`&&t.excelTable.totalsRow===!0,style:typeof t.excelTable==`object`?t.excelTable.style:void 0,totalsFns:i.map(e=>Q(e)?`sum`:void 0)});let h=await He(Ve({sheetName:p,header:u,rows:d,widths:f,freezeHeader:t.freezeHeader!==!1,freezeColumns:mt(e,t,i),condFormats:l,table:m}),n);return t.onProgress?.({phase:`write`,ratio:1,total:r.length}),ft(h,Y(p,`xlsx`),`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,r.length,t.download)}async function wt(e,t){if(Te(`Export`),et.includes(t.format))return vt(e,t);if(t.format===`xls`)return yt(e,t);if(t.format===`pdf`)return xt(e,t);if(t.format===`xlsx`){let n=t.autoGroup===!1?[]:(e.getState().grouping??[]).filter(e=>!!e),r=(t.groupBy?.length??0)>0||n.length>0,i=!!t.styles&&!t.conditionalFormats?.length;if(!t.sheets?.length&&!r&&!t.hierarchical&&!t.merges?.length&&!t.header?.length&&!t.footer?.length&&!t.imageFields?.length&&!i)return Ct(e,t)}await W(t.format);let n=await nt();if(t.sheets&&t.sheets.length>0){if(t.format!==`xlsx`)throw Error(`@svgrid/enterprise: multi-sheet export requires format 'xlsx', got '${t.format}'`);let r=t.rawValues===!0,i=t.sheets.map(n=>{let i=K(e,{columns:n.columns??t.columns},n.rows),a=n.rows.map(e=>{let t={};for(let n of i)t[n.field]=q(n,e,r);return t}),o=t.autoFitColumns===!1?null:X(i,n.rows,r);return{label:n.label,dataSource:a,columns:i.map((e,t)=>o?{dataField:e.field,label:e.header??e.field,width:o[t]}:{dataField:e.field,label:e.header??e.field}),dataFields:i.map(e=>e.field),style:rt(n.styles??t.styles)}}),a=(t.filename??`grid`).trim()||`grid`,o=ut(t),s=i[0],c=new n(o);c.spreadsheets=i,dt(c,t,s.dataFields);let l={};for(let e of s.columns)l[e.dataField]=e.label;let u=[l,...s.dataSource];if(t.download===!1)throw Error(`@svgrid/enterprise: download:false is not supported for multi-sheet xlsx.`);c.exportData(u,t.format,a);return}let r=G(e,t.rows);if(r.length===0)throw Error(`@svgrid/enterprise: nothing to export - the grid has no rows`);let i=K(e,t,r),a=await J(r,i,t),o=(t.filename??`grid`).trim()||`grid`,s=i.map(e=>e.field),c=t.autoGroup!==!1&&!t.groupBy?.length&&!t.hierarchical?(e.getState().grouping??[]).filter(e=>!!e).map(e=>String(e)):[],l=t.groupBy?.length?t.groupBy:c.length>0?c:void 0,u=!t.hierarchical&&l?.length?l:void 0,d=ut(t);if(t.conditionalFormats?.length){let e=U(i,r,t.conditionalFormats),n={};for(let t=0;t<r.length;t++)for(let r=0;r<i.length;r++){let o=e(t,r);if(!o)continue;let s={};if(o.fill&&(s.backgroundColor=o.fill),o.color&&(s.color=o.color),o.bold&&(s.fontWeight=`bold`),Object.keys(s).length&&(n[ht(r)+(t+2)]=s),o.icon){let e=a[t+1],n=i[r].field;e&&(e[n]=`${o.icon} ${e[n]??``}`)}}if(Object.keys(n).length){let e=d.style??{};d.style={...e,cells:{...e.cells??{},...n}}}}if(t.download===!1)throw Error(`@svgrid/enterprise: download:false is not supported for this xlsx export (grouped / merges / header / footer / images). Use a plain xlsx, xls, pdf, or a text format.`);if(t.signal?.aborted)throw new DOMException(`Export aborted`,`AbortError`);t.onProgress?.({phase:`write`,ratio:0,total:a.length-1});let f=new n(d,u);dt(f,t,s),f.exportData(a,t.format,o),t.onProgress?.({phase:`write`,ratio:1,total:a.length-1})}var Tt={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`};function $(e){return(e==null?``:String(e)).replace(/[&<>"']/g,e=>Tt[e])}function Et(e){let{columns:t,rows:n}=e,r=e.cellStyle,i=e.cellLink,a=e.opts??{},o=a.orientation??`portrait`,s=a.pageSize?`${a.pageSize} ${o}`:o,c=a.margin??`14mm`,l=a.zebra??!0,u=a.zebraColor??`#f6f8fa`,d=a.headerColor??`#f1f5f9`,f=a.headerTextColor??`#0f172a`,p=a.fontSize??9,m=e=>e&&e!==`left`?` style="text-align:${e}"`:``,h=`<thead><tr>`+t.map(e=>`<th${m(e.align)}>${$(e.header)}</th>`).join(``)+`</tr></thead>`,g=(e,t,n,a)=>{let o=[];e.align&&e.align!==`left`&&o.push(`text-align:${e.align}`);let s=r?.(n,a);s?.fill&&o.push(`background:${s.fill}`),s?.color&&o.push(`color:${s.color}`),s?.bold&&o.push(`font-weight:700`);let c=o.length?` style="${o.join(`;`)}"`:``,l=s?.icon?`${$(s.icon)} ${$(t)}`:$(t),u=i?.(n,a);return u&&(l=`<a href="${$(u)}">${l}</a>`),`<td${c}>${l}</td>`},_=`<tbody>`+n.map((e,n)=>`<tr>`+t.map((t,r)=>g(t,e[r]??``,n,r)).join(``)+`</tr>`).join(``)+`</tbody>`,v=[];return a.logo&&v.push(`<img class="logo" src="${$(a.logo)}" alt="" />`),a.title&&v.push(`<h1>${$(a.title)}</h1>`),a.subtitle&&v.push(`<p class="subtitle">${$(a.subtitle)}</p>`),`<!DOCTYPE html>
39
39
  <html><head><meta charset="utf-8"><title>${$(a.title??`Grid`)}</title>
40
40
  <style>
41
41
  @page { size: ${s}; margin: ${c}; }
@@ -55,4 +55,4 @@ Contact sales@jqwidgets.com for details or visit the license page: https://svgri
55
55
  ${v.join(`
56
56
  `)}
57
57
  <table>${h}${_}</table>
58
- </body></html>`}async function Et(e,t){if(Te(`Print`),typeof window>`u`)throw Error(`@svgrid/enterprise: print requires a browser environment`);let n=G(e,t?.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to print - the grid has no rows`);let r=K(e,{columns:t?.columns},n),i=r.map(e=>e.field),a=(await J(n,r,{rawValues:t?.rawValues})).slice(1).map(e=>i.map(t=>String(e[t]??``))),o=r.map(e=>({header:e.header??e.field,align:e.align})),s={title:t?.title??`Grid`,subtitle:t?.subtitle,logo:t?.logo,orientation:t?.orientation??`portrait`,pageSize:t?.pageSize,margin:t?.margin,zebra:t?.zebra,headerColor:t?.headerColor},c=U(r,n,t?.conditionalFormats),l=Tt({columns:o,rows:a,cellStyle:(e,t)=>c(e,t),cellLink:Z(r,n),opts:s}),u=window.open(``,`_blank`,`width=900,height=700`);if(!u)throw Error(`@svgrid/enterprise: print() could not open a window - the browser blocked the popup`);u.document.open(),u.document.write(l),u.document.close(),u.focus(),u.addEventListener(`load`,()=>{setTimeout(()=>u.print(),50)}),setTimeout(()=>{try{u.print()}catch{}},300)}var Dt=t({ALL_VALUES:()=>ALL_VALUES,DATA_BAR_COLOR:()=>DATA_BAR_COLOR,DATA_BAR_NEGATIVE_COLOR:()=>DATA_BAR_NEGATIVE_COLOR,DEFAULT_ALERT_MESSAGE:()=>DEFAULT_ALERT_MESSAGE,DEFAULT_TABLE_STYLE:()=>DEFAULT_TABLE_STYLE,GRAND_TOTAL_ROW_ID:()=>GRAND_TOTAL_ROW_ID,GROUP_TOTAL_ROW_ID_PREFIX:()=>GROUP_TOTAL_ROW_ID_PREFIX,NO_TABLE_STYLE:()=>NO_TABLE_STYLE,PROTECTED_MESSAGE:()=>PROTECTED_MESSAGE,countReducer:()=>countReducer,exportGrid:()=>Ct,printGrid:()=>Et});export{O as a,we as i,be as n,xe as r,Dt as t};
58
+ </body></html>`}async function Dt(e,t){if(Te(`Print`),typeof window>`u`)throw Error(`@svgrid/enterprise: print requires a browser environment`);let n=G(e,t?.rows);if(n.length===0)throw Error(`@svgrid/enterprise: nothing to print - the grid has no rows`);let r=K(e,{columns:t?.columns},n),i=r.map(e=>e.field),a=(await J(n,r,{rawValues:t?.rawValues})).slice(1).map(e=>i.map(t=>String(e[t]??``))),o=r.map(e=>({header:e.header??e.field,align:e.align})),s={title:t?.title??`Grid`,subtitle:t?.subtitle,logo:t?.logo,orientation:t?.orientation??`portrait`,pageSize:t?.pageSize,margin:t?.margin,zebra:t?.zebra,headerColor:t?.headerColor},c=U(r,n,t?.conditionalFormats),l=Et({columns:o,rows:a,cellStyle:(e,t)=>c(e,t),cellLink:Z(r,n),opts:s}),u=window.open(``,`_blank`,`width=900,height=700`);if(!u)throw Error(`@svgrid/enterprise: print() could not open a window - the browser blocked the popup`);u.document.open(),u.document.write(l),u.document.close(),u.focus(),u.addEventListener(`load`,()=>{setTimeout(()=>u.print(),50)}),setTimeout(()=>{try{u.print()}catch{}},300)}var Ot=t({ALL_VALUES:()=>ALL_VALUES,DATA_BAR_COLOR:()=>DATA_BAR_COLOR,DATA_BAR_NEGATIVE_COLOR:()=>DATA_BAR_NEGATIVE_COLOR,DEFAULT_ALERT_MESSAGE:()=>DEFAULT_ALERT_MESSAGE,DEFAULT_TABLE_STYLE:()=>DEFAULT_TABLE_STYLE,GRAND_TOTAL_ROW_ID:()=>GRAND_TOTAL_ROW_ID,GROUP_TOTAL_ROW_ID_PREFIX:()=>GROUP_TOTAL_ROW_ID_PREFIX,NO_TABLE_STYLE:()=>NO_TABLE_STYLE,PROTECTED_MESSAGE:()=>PROTECTED_MESSAGE,countReducer:()=>countReducer,exportGrid:()=>wt,printGrid:()=>Dt});export{O as a,we as i,be as n,xe as r,Ot as t};
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>SvGrid Studio - Designer</title>
7
- <script type="module" crossorigin src="./assets/index-C1Ujg62Z.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-DA9jVAjf.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-Dd_uD5pT.js">
9
9
  <link rel="modulepreload" crossorigin href="./assets/disclose-version-CIm4S9xS.js">
10
10
  <link rel="modulepreload" crossorigin href="./assets/cell-formatting-JoxA0t65.js">
@@ -35,7 +35,7 @@
35
35
  <link rel="modulepreload" crossorigin href="./assets/server-block-cache-CXJKkJpy.js">
36
36
  <link rel="modulepreload" crossorigin href="./assets/conditional-formatting-MDWbF8_Y.js">
37
37
  <link rel="modulepreload" crossorigin href="./assets/export-format-BCuqcexA.js">
38
- <link rel="modulepreload" crossorigin href="./assets/src-hO8VnnI5.js">
38
+ <link rel="modulepreload" crossorigin href="./assets/src-fddEt37f.js">
39
39
  <link rel="stylesheet" crossorigin href="./assets/date-format-DKS-z0xS.css">
40
40
  <link rel="stylesheet" crossorigin href="./assets/SvListBox-BXfyqy4a.css">
41
41
  <link rel="stylesheet" crossorigin href="./assets/SvGridDropdown-CcidB3rm.css">
@@ -45,7 +45,7 @@
45
45
  <link rel="stylesheet" crossorigin href="./assets/SvMenuList-DJ47ba1h.css">
46
46
  <link rel="stylesheet" crossorigin href="./assets/SvGridChart-BgLuPO7I.css">
47
47
  <link rel="stylesheet" crossorigin href="./assets/SvGridChartPanel-4Pc8y5yO.css">
48
- <link rel="stylesheet" crossorigin href="./assets/index-DdmxO6Dd.css">
48
+ <link rel="stylesheet" crossorigin href="./assets/index-WCxj6WfJ.css">
49
49
  </head>
50
50
  <body>
51
51
  <div id="app"></div>
@@ -44,6 +44,14 @@ export type PdfMakeLike = {
44
44
  * `vfs` property as well, which older versions read. Returns whether a map
45
45
  * was found to register.
46
46
  */
47
+ /**
48
+ * The PDF as a Blob from either pdfmake line. 0.2 hands it to a callback; 0.3
49
+ * made `getBlob` async and never calls one, so waiting on the callback alone
50
+ * hung every export once pnpm or yarn installed 0.3 for `pnpm add pdfmake`.
51
+ */
52
+ export declare function pdfBlob(doc: {
53
+ getBlob(cb?: (b: Blob) => void): unknown;
54
+ }): Promise<Blob>;
47
55
  export declare function registerPdfFonts(pdfMake: PdfMakeLike, vfsModule: unknown): boolean;
48
56
  export type PdfExportOptions = {
49
57
  pageSize?: PdfPageSize;
@@ -50,6 +50,20 @@ export function resolvePdfVfs(mod) {
50
50
  * `vfs` property as well, which older versions read. Returns whether a map
51
51
  * was found to register.
52
52
  */
53
+ /**
54
+ * The PDF as a Blob from either pdfmake line. 0.2 hands it to a callback; 0.3
55
+ * made `getBlob` async and never calls one, so waiting on the callback alone
56
+ * hung every export once pnpm or yarn installed 0.3 for `pnpm add pdfmake`.
57
+ */
58
+ export function pdfBlob(doc) {
59
+ return new Promise((resolve, reject) => {
60
+ const returned = doc.getBlob(resolve);
61
+ if (returned && typeof returned.then === 'function') {
62
+ ;
63
+ returned.then(resolve, reject);
64
+ }
65
+ });
66
+ }
53
67
  export function registerPdfFonts(pdfMake, vfsModule) {
54
68
  const vfs = resolvePdfVfs(vfsModule);
55
69
  if (!vfs)
package/dist/export.js CHANGED
@@ -6,7 +6,7 @@ import { installSmartShim } from './smart-shim.js';
6
6
  import { downloadBlobFile, downloadTextFile, serializeDelimited, serializeHtml, serializeJson, serializeMarkdown, serializeXml, } from './export-serialize.js';
7
7
  import { serializeSpreadsheetML } from './export-xls.js';
8
8
  import { buildXlsxParts, packageXlsx } from './export-ooxml.js';
9
- import { buildPdfDocDefinition, readGridPdfTheme, registerPdfFonts, resolvePdfCharts } from './export-pdf.js';
9
+ import { buildPdfDocDefinition, pdfBlob, readGridPdfTheme, registerPdfFonts, resolvePdfCharts } from './export-pdf.js';
10
10
  import { buildConditionalResolver } from './export-conditional.js';
11
11
  /** Formats served by the native, dependency-free, streaming serializers. */
12
12
  const NATIVE_TEXT_FORMATS = [
@@ -686,7 +686,7 @@ async function exportPdf(api, opts) {
686
686
  });
687
687
  }
688
688
  const filename = (opts.filename ?? 'grid').trim() || 'grid';
689
- const blob = await new Promise((resolve) => pdfMake.createPdf(def).getBlob(resolve));
689
+ const blob = await pdfBlob(pdfMake.createPdf(def));
690
690
  opts.onProgress?.({ phase: 'write', ratio: 1, total: sourceRows.length });
691
691
  return deliver(blob, ensureExt(filename, 'pdf'), 'application/pdf', sourceRows.length, opts.download);
692
692
  }
@@ -525,11 +525,12 @@
525
525
  })
526
526
  </script>
527
527
 
528
- {#if tables && current}
528
+ <!-- An empty list still gets the tabs, so "Add table" is there. -->
529
+ {#if tables}
529
530
  <div class="sv-fbase-tables" style:height>
530
531
  <BaseTabs
531
532
  {tables}
532
- activeId={current.id}
533
+ activeId={current?.id ?? ''}
533
534
  onSwitch={switchTo}
534
535
  onAdd={addTable}
535
536
  onRename={renameTable}
@@ -539,37 +540,39 @@
539
540
  status={syncLine}
540
541
  />
541
542
  <div class="sv-fbase-slot">
542
- {#key current.id}
543
- <BaseTableView
544
- {...gridProps}
545
- bare
546
- data={gridData}
547
- columns={current.columns}
548
- views={current.views ?? GRID_ONLY}
549
- bind:activeView={viewOf[current.id]}
550
- onViewsChange={(v: FieldView[]) => commit(pulled({ views: v }))}
551
- table={current}
552
- tables={() => pulled()}
553
- runner={automations ? runner : undefined}
554
- {serverRuns}
555
- onAutomationsChange={(list: BaseAutomation[]) => commit(pulled({ automations: list }))}
556
- onFormSubmit={(row: Row, viewId: string) => void runner.handle({ type: 'form', table: current!.id, record: row, view: viewId })}
557
- newRecord={() => ({ id: newRecordId() })}
558
- {viewTypes}
559
- {rowHeights}
560
- containerHeight="100%"
561
- onApiReady={(a: any) => {
562
- api = a
563
- onApiReady?.(a)
564
- const rowId = pendingOpen
565
- pendingOpen = null
566
- if (rowId) queueMicrotask(() => {
567
- const ctrl = gridOf(a)
568
- if (ctrl) openRecord({ ctrl, rowId })
569
- })
570
- }}
571
- />
572
- {/key}
543
+ {#if current}
544
+ {#key current.id}
545
+ <BaseTableView
546
+ {...gridProps}
547
+ bare
548
+ data={gridData}
549
+ columns={current.columns}
550
+ views={current.views ?? GRID_ONLY}
551
+ bind:activeView={viewOf[current.id]}
552
+ onViewsChange={(v: FieldView[]) => commit(pulled({ views: v }))}
553
+ table={current}
554
+ tables={() => pulled()}
555
+ runner={automations ? runner : undefined}
556
+ {serverRuns}
557
+ onAutomationsChange={(list: BaseAutomation[]) => commit(pulled({ automations: list }))}
558
+ onFormSubmit={(row: Row, viewId: string) => void runner.handle({ type: 'form', table: current!.id, record: row, view: viewId })}
559
+ newRecord={() => ({ id: newRecordId() })}
560
+ {viewTypes}
561
+ {rowHeights}
562
+ containerHeight="100%"
563
+ onApiReady={(a: any) => {
564
+ api = a
565
+ onApiReady?.(a)
566
+ const rowId = pendingOpen
567
+ pendingOpen = null
568
+ if (rowId) queueMicrotask(() => {
569
+ const ctrl = gridOf(a)
570
+ if (ctrl) openRecord({ ctrl, rowId })
571
+ })
572
+ }}
573
+ />
574
+ {/key}
575
+ {/if}
573
576
  </div>
574
577
  </div>
575
578
  {:else}
@@ -5,7 +5,7 @@ import { createSupabaseDataSource } from '../sources/supabase.js';
5
5
  import { createSupabaseRealtime } from '../sources/realtime-supabase.js';
6
6
  import { introspectSupabaseTable, listSupabaseTables } from '../sources/introspect-supabase.js';
7
7
  import { applyBaseComments, baseSpecFromSchemas, baseTablesFromSpec, withInverses } from './base-schema.js';
8
- import { SQL_COMMENT_PREFIX } from './base-sql.js';
8
+ import { BASE_ORDER_COLUMN, SQL_COMMENT_PREFIX } from './base-sql.js';
9
9
  const SQL_DIALECT = {
10
10
  postgres: { placeholders: '$', ilike: true },
11
11
  supabase: { placeholders: '$', ilike: true },
@@ -13,6 +13,41 @@ const SQL_DIALECT = {
13
13
  sqlite: { placeholders: '?' },
14
14
  mssql: { placeholders: '@' },
15
15
  };
16
+ // ---- The order column (BASE_ORDER_COLUMN) -----------------------------------
17
+ // A table made by baseToSql numbers its records in insertion order. The base
18
+ // reads in that order while nothing is sorted, but the column is not a field:
19
+ // it is left out of what the base shows and validates, out of the rows it
20
+ // gets, and out of every write (generated always, so writing it would fail).
21
+ const hasOrder = (s) => s.fields.some((f) => f.field === BASE_ORDER_COLUMN);
22
+ const ORDER = [{ field: BASE_ORDER_COLUMN }];
23
+ /** The schema the base shows: without the order column. */
24
+ function shown(s) {
25
+ return hasOrder(s) ? { ...s, fields: s.fields.filter((f) => f.field !== BASE_ORDER_COLUMN) } : s;
26
+ }
27
+ function dropOrder(row) {
28
+ if (!row || typeof row !== 'object' || !(BASE_ORDER_COLUMN in row))
29
+ return row;
30
+ const copy = { ...row };
31
+ delete copy[BASE_ORDER_COLUMN];
32
+ return copy;
33
+ }
34
+ /** A source that never hands out or writes the order column. */
35
+ function hideOrder(source) {
36
+ return {
37
+ ...source,
38
+ getRows: async (request) => {
39
+ const result = await source.getRows(request);
40
+ return { ...result, rows: result.rows.map(dropOrder) };
41
+ },
42
+ createRow: async (input) => dropOrder(await source.createRow(dropOrder(input))),
43
+ updateRow: async (id, patch) => dropOrder(await source.updateRow(id, dropOrder(patch))),
44
+ };
45
+ }
46
+ /** A table on SQL, in insertion order when it has the order column. */
47
+ function sqlSource(schema, table, dialect, execute) {
48
+ const source = createSqlDataSource({ schema, table, dialect: SQL_DIALECT[dialect], execute, ...(hasOrder(schema) ? { defaultOrder: ORDER } : {}) });
49
+ return hasOrder(schema) ? hideOrder(source) : source;
50
+ }
16
51
  const quote = (dialect, name) => dialect === 'mysql' ? `\`${name.replace(/`/g, '``')}\`` : dialect === 'mssql' ? `[${name.replace(/]/g, ']]')}]` : `"${name.replace(/"/g, '""')}"`;
17
52
  const param = (dialect, i) => (dialect === 'postgres' || dialect === 'supabase' ? `$${i}` : dialect === 'mssql' ? `@p${i}` : '?');
18
53
  /** The values each text column repeats, most used first (at most 13 per column). */
@@ -130,9 +165,10 @@ async function makesKeys(o, dialect, s) {
130
165
  async function readDatabase(o) {
131
166
  const dialect = o.dialect ?? 'postgres';
132
167
  const names = o.tables ?? (await listDatabaseTables(dialect, o.execute));
133
- const list = [];
168
+ const all = [];
134
169
  for (const table of names)
135
- list.push(await introspectDatabase({ dialect, table, execute: o.execute }));
170
+ all.push(await introspectDatabase({ dialect, table, execute: o.execute }));
171
+ const list = all.map(shown);
136
172
  // A junction table the list leaves out still carries a link to many.
137
173
  const values = o.choices === false ? {} : await readValues(o, dialect, list);
138
174
  const keys = new Map();
@@ -143,7 +179,8 @@ async function readDatabase(o) {
143
179
  let specs = baseSpecFromSchemas(list, { values, serverIds: (s) => keys.get(s.name) ?? false, order: o.tables ? 'given' : 'links', inverses: !kept });
144
180
  if (kept)
145
181
  specs = withComments(specs, comments, !!o.tables);
146
- return { specs, schemas: new Map(list.map((s) => [s.name, s])) };
182
+ // The sources read with the order column; the base never sees it.
183
+ return { specs, schemas: new Map(all.map((s) => [s.name, s])) };
147
184
  }
148
185
  /** The tables of a database, described as a base: plain JSON (what an endpoint sends). */
149
186
  export async function describeDatabase(options) {
@@ -159,7 +196,7 @@ export async function describeDatabase(options) {
159
196
  export async function baseFromDatabase(options) {
160
197
  const dialect = options.dialect ?? 'postgres';
161
198
  const { specs, schemas } = await readDatabase(options);
162
- return baseTablesFromSpec(specs, (table) => createSqlDataSource({ schema: schemas.get(table), table, dialect: SQL_DIALECT[dialect], execute: options.execute }));
199
+ return baseTablesFromSpec(specs, (table) => sqlSource(schemas.get(table), table, dialect, options.execute));
163
200
  }
164
201
  /**
165
202
  * The server half of `baseFromEndpoint`, as a SvelteKit route:
@@ -194,8 +231,8 @@ export function createBaseEndpoint(options) {
194
231
  let h = handlers.get(table);
195
232
  if (!h) {
196
233
  h = createKitHandlers({
197
- schema,
198
- source: createSqlDataSource({ schema, table, dialect: SQL_DIALECT[dialect], execute: options.execute }),
234
+ schema: shown(schema),
235
+ source: sqlSource(schema, table, dialect, options.execute),
199
236
  ...(options.authorize ? { authorize: options.authorize(table) } : {}),
200
237
  ...(options.audit ? { audit: options.audit(table) } : {}),
201
238
  });
@@ -262,10 +299,14 @@ export async function baseFromSupabase(options) {
262
299
  const comments = await readSupabaseComments(options);
263
300
  const kept = hasComments(comments);
264
301
  // Supabase makes the keys: its source inserts without the page's id.
265
- let specs = baseSpecFromSchemas(schemas, { values, serverIds: () => true, order: options.tables ? 'given' : 'links', inverses: !kept });
302
+ let specs = baseSpecFromSchemas(schemas.map(shown), { values, serverIds: () => true, order: options.tables ? 'given' : 'links', inverses: !kept });
266
303
  if (kept)
267
304
  specs = withComments(specs, comments, !!options.tables);
268
- return baseTablesFromSpec(specs, (table) => createSupabaseDataSource({ client: options.client, table, schema: byName.get(table) }), (s) => options.realtime === false
305
+ return baseTablesFromSpec(specs, (table) => {
306
+ const schema = byName.get(table);
307
+ const source = createSupabaseDataSource({ client: options.client, table, schema, ...(hasOrder(schema) ? { defaultOrder: ORDER } : {}) });
308
+ return (hasOrder(schema) ? hideOrder(source) : source);
309
+ }, (s) => options.realtime === false
269
310
  ? {}
270
311
  : { realtime: (onChange) => createSupabaseRealtime({ client: options.client, table: s.id, onChange }) });
271
312
  }
@@ -39,6 +39,14 @@ export type BaseJunctionComment = {
39
39
  };
40
40
  };
41
41
  export declare const SQL_COMMENT_PREFIX = "svgrid:";
42
+ /**
43
+ * A column baseToSql gives every table: an identity that numbers the records
44
+ * in the order they were written. Text keys (seed ids, UUIDs) do not sort that
45
+ * way, so the base reads rows in this order while nothing is sorted. It is not
46
+ * a field: baseFromDatabase, createBaseEndpoint and baseFromSupabase leave it
47
+ * out of the base and never write it.
48
+ */
49
+ export declare const BASE_ORDER_COLUMN = "svgrid_order";
42
50
  /** `fixedOn` -> `fixed_on`, `Key results` -> `key_results`. */
43
51
  export declare function sqlName(s: string): string;
44
52
  export type BaseToSqlOptions = {
@@ -14,6 +14,14 @@
14
14
  import { colId, primaryOf, rowIdOf } from './base-tables.js';
15
15
  import { fillFieldColumn } from './registry.svelte.js';
16
16
  export const SQL_COMMENT_PREFIX = 'svgrid:';
17
+ /**
18
+ * A column baseToSql gives every table: an identity that numbers the records
19
+ * in the order they were written. Text keys (seed ids, UUIDs) do not sort that
20
+ * way, so the base reads rows in this order while nothing is sorted. It is not
21
+ * a field: baseFromDatabase, createBaseEndpoint and baseFromSupabase leave it
22
+ * out of the base and never write it.
23
+ */
24
+ export const BASE_ORDER_COLUMN = 'svgrid_order';
17
25
  /** `fixedOn` -> `fixed_on`, `Key results` -> `key_results`. */
18
26
  export function sqlName(s) {
19
27
  const out = String(s)
@@ -115,7 +123,7 @@ export function baseToSql(tables, options = {}) {
115
123
  const name = nameOf.get(t.id);
116
124
  const columns = [];
117
125
  const extra = [];
118
- const taken = new Set(['id']);
126
+ const taken = new Set(['id', BASE_ORDER_COLUMN]);
119
127
  const column = (base) => {
120
128
  let c = sqlName(base);
121
129
  while (taken.has(c))
@@ -153,8 +161,9 @@ export function baseToSql(tables, options = {}) {
153
161
  columns.push({ def: d, column: column(field) });
154
162
  }
155
163
  // The database makes the key of a record added later: a Supabase insert
156
- // carries no id. The records below bring their own.
157
- const lines = [` "id" text primary key default gen_random_uuid()::text`, ...columns.map((c) => ` ${quote(c.column)} ${c.fk ? 'text' : sqlType(c.def)}`)];
164
+ // carries no id. The records below bring their own. The order column
165
+ // numbers them as they are inserted, so the records keep the order below.
166
+ const lines = [` "id" text primary key default gen_random_uuid()::text`, ` ${quote(BASE_ORDER_COLUMN)} bigint generated always as identity`, ...columns.map((c) => ` ${quote(c.column)} ${c.fk ? 'text' : sqlType(c.def)}`)];
158
167
  plans.push({ table: t, columns, extra, sql: `create table ${quote(name)} (\n${lines.join(',\n')}\n);` });
159
168
  }
160
169
  const out = [];
package/dist/install.js CHANGED
@@ -14,7 +14,7 @@ import { enableGanttView } from './gantt/gantt.js';
14
14
  import { enableSelectionBar } from './selection-bar.js';
15
15
  import { enableAdvancedFilter } from './advanced-filter-enable.js';
16
16
  import { enablePivot } from './pivot-enable.js';
17
- import { enableSheet } from './sheet-enable.js';
17
+ import { registerSheetKeymap } from './sheet-enable.js';
18
18
  import { enableServerRowModel } from './server/enable.js';
19
19
  /**
20
20
  * Augment a SvGridApi instance with Pro methods (`exportData`, `print`,
@@ -59,8 +59,8 @@ export function installEnterprise(api) {
59
59
  enableAdvancedFilter();
60
60
  // Register the Excel keymap (Ctrl+Arrow, Ctrl+D, Ctrl+A and the rest). The
61
61
  // grid interprets a key itself only when nothing claims it, so a free grid
62
- // is unaffected.
63
- enableSheet();
62
+ // is unaffected. No spreadsheet nudge: this app may only export or pivot.
63
+ registerSheetKeymap();
64
64
  // Raise the unlicensed nudge for the server-side row model. No registry to fill -
65
65
  // the model hands the grid ordinary rows - so this only nudges when unlicensed.
66
66
  enableServerRowModel();