@object-ui/plugin-report 6.2.3 → 7.1.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/dist/DatasetReportRenderer.d.ts +95 -0
  3. package/dist/{packages/plugin-report/src/LiveReportExporter.d.ts → LiveReportExporter.d.ts} +1 -1
  4. package/dist/{packages/plugin-report/src/ReportExportEngine.d.ts → ReportExportEngine.d.ts} +1 -1
  5. package/dist/ReportRenderer.d.ts +45 -0
  6. package/dist/{packages/plugin-report/src/ReportViewer.d.ts → ReportViewer.d.ts} +1 -1
  7. package/dist/{packages/plugin-report/src/formatValue.d.ts → formatValue.d.ts} +1 -1
  8. package/dist/index.d.ts +13 -2
  9. package/dist/index.js +586 -3685
  10. package/dist/index.umd.cjs +18 -18
  11. package/dist/mergeFilters.d.ts +10 -0
  12. package/package.json +15 -15
  13. package/dist/packages/plugin-report/src/ChartConfig.d.ts +0 -8
  14. package/dist/packages/plugin-report/src/ColumnsEditor.d.ts +0 -16
  15. package/dist/packages/plugin-report/src/FieldPickerDialog.d.ts +0 -36
  16. package/dist/packages/plugin-report/src/GroupingsBuilder.d.ts +0 -8
  17. package/dist/packages/plugin-report/src/JoinedBlocksEditor.d.ts +0 -31
  18. package/dist/packages/plugin-report/src/JoinedReportRenderer.d.ts +0 -47
  19. package/dist/packages/plugin-report/src/MatrixRenderer.d.ts +0 -51
  20. package/dist/packages/plugin-report/src/MatrixRenderer.stories.d.ts +0 -24
  21. package/dist/packages/plugin-report/src/ReportBuilder.d.ts +0 -10
  22. package/dist/packages/plugin-report/src/ReportConfigPanel.d.ts +0 -24
  23. package/dist/packages/plugin-report/src/ReportRenderer.d.ts +0 -44
  24. package/dist/packages/plugin-report/src/ScheduleConfig.d.ts +0 -7
  25. package/dist/packages/plugin-report/src/SpecReportGrid.d.ts +0 -49
  26. package/dist/packages/plugin-report/src/SpecReportGrid.stories.d.ts +0 -31
  27. package/dist/packages/plugin-report/src/buildChartData.d.ts +0 -38
  28. package/dist/packages/plugin-report/src/drill.d.ts +0 -63
  29. package/dist/packages/plugin-report/src/editorTypes.d.ts +0 -20
  30. package/dist/packages/plugin-report/src/hooks/useReportData.d.ts +0 -131
  31. package/dist/packages/plugin-report/src/index.d.ts +0 -26
  32. package/dist/packages/plugin-report/src/specFilterAdapter.d.ts +0 -38
  33. /package/dist/{packages/plugin-report/src/LegacyReportRenderer.d.ts → LegacyReportRenderer.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/types"),require("@object-ui/react"),require("@object-ui/components"),require("react/jsx-runtime"),require("react-i18next"),require("@object-ui/plugin-grid"),require("@object-ui/i18n"),require("lucide-react"),require("@object-ui/fields")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/types`,`@object-ui/react`,`@object-ui/components`,`react/jsx-runtime`,`react-i18next`,`@object-ui/plugin-grid`,`@object-ui/i18n`,`lucide-react`,`@object-ui/fields`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUITypes,e.ObjectUIReact,e.ObjectUIComponents,e.react_jsx_runtime,e.react_i18next,e._object_ui_plugin_grid,e._object_ui_i18n,e.lucide_react,e._object_ui_fields))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var f=Object.create,p=Object.defineProperty,m=Object.getOwnPropertyDescriptor,h=Object.getOwnPropertyNames,g=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,v=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=h(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_.call(e,s)&&s!==n&&p(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=m(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:f(g(e)),v(t||!e||!e.__esModule?p(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var y=({schema:e})=>{let{title:n,description:r,data:i,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,o.jsxs)(a.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,o.jsxs)(a.CardHeader,{children:[n&&(0,o.jsx)(a.CardTitle,{children:n}),r&&(0,o.jsx)(a.CardDescription,{children:r})]}),(0,o.jsxs)(a.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[c&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,o.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,o.jsx)(r,{schema:{...e.chart,data:e.chart.data||i}})}):(0,o.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),i&&i.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`grid`)||t.ComponentRegistry.get(`table`);return e?(0,o.jsx)(e,{schema:{type:`grid`,rowData:i,columnDefs:s,domLayout:`autoHeight`}}):(0,o.jsx)(`div`,{className:`overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,o.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,o.jsx)(`tr`,{children:s?.map(e=>(0,o.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,o.jsx)(`tbody`,{children:i.map((e,t)=>(0,o.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,o.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function b(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function x(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function S(e,t){let n=e[t.field];return t.dateGranularity?x(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function C(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[b(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[b(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[b(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[b(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[b(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[b(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[b(r)]=e;break}default:n[b(r)]=null}}return n}function w(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=S(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=C(t,n),d=o.length>0?w(t,o,n,s,l):void 0;c.push({groupKey:s,groupPath:l,values:u,count:t.length,children:d})}let l=a.sort===`desc`?-1:1;return c.sort((e,t)=>{let n=String(e.groupPath[e.groupPath.length-1]),r=String(t.groupPath[t.groupPath.length-1]);return n.localeCompare(r)*l}),typeof a.limit==`number`&&a.limit>0?c.slice(0,a.limit):c}function T(e,t,n,r){let i=E(e,n),a=E(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=D(e,c.key,n);s[c.id]=C(i,t);for(let e of a){let n=D(i,e.key,r);n.length!==0&&(o[c.id][e.id]=C(n,t))}}for(let n of a){let i=D(e,n.key,r);c[n.id]=C(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:C(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function E(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=S(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function D(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?S(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function O(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=b(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function k(e,t,n,r){let i=A(e,n),a=A(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>j(e,n.key));s[n.id]=O(r,t);for(let e of a){let i=r.filter(t=>j(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=b(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>j(e,n.key));c[n.id]=O(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:O(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function A(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=r[n.field],a=t==null?`(null)`:String(t);e.push(a),i[n.field]=a}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());return r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0}),r}function j(e,t){for(let[n,r]of Object.entries(t))if((e[n]==null?`(null)`:String(e[n]))!==String(r))return!1;return!0}function M(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function N(e){let t=new Set;for(let n of e.groupingsDown??[])t.add(n.field);for(let n of e.groupingsAcross??[])t.add(n.field);for(let n of e.columns??[])t.add(n.field);for(let n of e.sort??[])t.add(n.field);return Array.from(t)}function P(e,t,n){let r=[...e.groupingsDown??[],...e.groupingsAcross??[]],i=(e.columns??[]).filter(e=>!!e.aggregate);if(r.length===0&&i.length===0)return null;let a=r.map(e=>e.dateGranularity?{field:e.field,dateGranularity:e.dateGranularity}:e.field),o=i.map(e=>({function:e.aggregate===`unique`?`count_distinct`:e.aggregate,field:e.field,alias:b(e)})),s=M(e.filter,t),c={object:e.objectName,limit:n};return a.length>0&&(c.groupBy=a),o.length>0&&(c.aggregations=o),s&&(c.where=s),c}function F(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?S(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var I=[];function L(e,t={}){let{dataSource:r,runtimeFilter:i,maxRows:a=5e3,enabled:o=!0,rows:s,preferServerAggregation:c=!0}=t,[l,u]=(0,n.useState)(s??I),[d,f]=(0,n.useState)(!1),[p,m]=(0,n.useState)(()=>s?!1:!!(e&&o&&r)),[h,g]=(0,n.useState)(null),_=(0,n.useRef)(0),v=(0,n.useCallback)(async()=>{if(!e||!o)return;if(s){u(s),f(!1);return}if(!r){u(I);return}let t=++_.current;m(!0),g(null);try{let n=c?P(e,i,a):null;if(n&&typeof r.aggregate==`function`)try{let i=R(await r.aggregate(e.objectName,n));if(t!==_.current)return;u(i),f(!0);return}catch(e){typeof console<`u`&&console.warn&&console.warn(`[useReportData] dataSource.aggregate() failed, falling back to find():`,e)}if(typeof r.find!=`function`){u(I),f(!1);return}let o=M(e.filter,i),s=N(e),l={$top:a};o&&(l.$filter=o),s.length>0&&(l.$select=s),e.sort&&e.sort.length>0&&(l.$orderBy=e.sort.map(e=>`${e.field} ${e.direction??`asc`}`).join(`,`));let d=R(await r.find(e.objectName,l));if(t!==_.current)return;u(d),f(!1)}catch(e){if(t!==_.current)return;g(e instanceof Error?e:Error(String(e))),u(I),f(!1)}finally{t===_.current&&m(!1)}},[e,o,s,r,i,a,c]);(0,n.useEffect)(()=>{v()},[v]);let{rows:y,totals:b,pivot:x}=(0,n.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(d){let e=[...t,...n],a=l.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=O(l,r),s=i?k(l,r,t,n):null;return{rows:i&&s?s.rowHeaders.map(e=>({groupKey:e.key,groupPath:e.path,values:s.rowTotals[e.id]??{},count:1})):a,totals:o,pivot:s}}let a=i?t:[...t,...n];return{rows:a.length>0?w(l,a,r):l.map(e=>({groupKey:{},groupPath:[],values:r.length>0?C([e],r):{...e},count:1})),totals:C(l,r),pivot:i?T(l,r,t,n):null}},[e,l,d]);return{rows:y,rawRows:l,totals:b,pivot:x,serverAggregated:d,loading:p,error:h,refetch:v,drillDown:(0,n.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return l.filter(e=>F(e,t,n))},[e,l])}}function R(e){if(Array.isArray(e))return e;if(e&&typeof e==`object`){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.records))return t.records;if(Array.isArray(t.results))return t.results;if(Array.isArray(t.value))return t.value}return I}function ee(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function te(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function ne({report:e,rows:t,labels:n}){let r=e.chart;if(!r||!r.type)return{schema:null};let i=e.groupingsDown??[],a=r.xAxis||(i.length>0?i[0]?.field:void 0);if(!a)return{schema:null,diagnostic:`chart.xAxis missing and no groupingsDown[0] to default to.`};let o=e.columns??[],s=r.yAxis,c=`count`,l=`Count`,u=!0;if(s){let e=o.find(e=>e.field===s&&e.aggregate);e?(c=ee(e),l=n?.resolveColumnLabel?.(e)??(typeof e.label==`string`?e.label:`${e.aggregate}(${e.field})`),u=!1):(c=`count`,l=n?.resolveCountLabel?.(s)??`Count of ${s}`)}let d=te(t),f=new Map;for(let e of d){let t=e.groupKey[a];if(t===void 0)continue;let n=String(t??``),r=u?e.count:Number(e.values[c]??0),i=f.get(n);i?i.measure+=Number.isFinite(r)?r:0:f.set(n,{x:t,measure:Number.isFinite(r)?r:0})}let p=Array.from(f.values()).map(e=>{let t=n?.resolveAxisValue?.(a,e.x)??e.x??`(null)`;return{[a]:t,[c]:e.measure}});return(r.type===`pie`||r.type===`donut`||r.type===`funnel`)&&(p=[...p].sort((e,t)=>Number(t[c]??0)-Number(e[c]??0))),{schema:{type:`chart`,chartType:r.type,data:p,xAxisKey:a,series:[{dataKey:c,label:l}],title:r.title,showLegend:r.showLegend??!0,showDataLabels:r.showDataLabels??!1,className:`w-full h-[320px]`}}}function z(e,t,n={}){let r=M(M(e.filter,n.runtimeFilter),Object.keys(t).length>0?t:void 0);return{type:`drill`,name:`drill-${e.name}`,objectName:e.objectName,...r?{filter:r}:{},view:n.view??`list`,...n.recordId===void 0?{}:{recordId:n.recordId},openIn:n.openIn??`current`}}function re(e){return!!e&&e.type===`drill`}function ie(e){return async t=>{if(!re(t))return{success:!1,error:`drill handler invoked with non-drill action`};try{return await e.navigate({objectName:t.objectName,filter:t.filter,view:t.view,recordId:t.recordId,openIn:t.openIn}),{success:!0}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}}function ae(e,t){return e.registerHandler(`drill`,ie(t)),()=>e.unregisterHandler(`drill`)}function oe(e){return e?e===`unique`?`count_distinct`:e:null}function se(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function ce(e){return(e.columns??[]).map(e=>{let t={field:e.field};return e.label&&(t.label=typeof e.label==`string`?e.label:String(e.label)),e.format&&(t.format=e.format),e.width&&(t.width=e.width),t})}var le={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},B=({report:e,dataSource:t,rows:r,runtimeFilter:a,onDrillDown:u,actionRunner:d,drillView:f,drillOpenIn:p,className:m})=>{let h=e.type??`tabular`,{t:g}=(0,s.useTranslation)(),{fieldLabel:_,translateOptions:v}=(0,l.useSafeFieldLabel)(),[y,x]=n.useState(null);n.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||x(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let S=n.useCallback(t=>{if(t.label)return String(t.label);let n=y?.fields?.[t.field]?.label??t.field,r=_(e.objectName,t.field,n);return t.aggregate?`${r} · ${g(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[y,e.objectName,_,g]),C=n.useCallback((t,n)=>{if(n==null)return;let r=y?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=v(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[y,e.objectName,v]),{rawRows:w,rows:T,totals:E,serverAggregated:D,loading:O,error:k,drillDown:A}=L(e,{dataSource:t,rows:r,runtimeFilter:a});if(h===`matrix`||h===`joined`)return(0,o.jsxs)(`div`,{className:m,style:le,children:[`Report type `,(0,o.jsx)(`code`,{children:h}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let j=n.useMemo(()=>{if(D){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:b(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=h===`summary`?se(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=oe(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:ce(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,h,D]),M=w,N=n.useCallback(t=>{let n=e.groupingsDown??[],r={};for(let e of n)r[e.field]=t[e.field];if(d){let t=z(e,r,{runtimeFilter:a,view:f,openIn:p});d.execute(t)}u&&u(r,A(r))},[d,A,p,f,u,e,a]),P=!!u||!!d,F=(e.columns??[]).filter(e=>e.aggregate),I=F.length>0&&E&&Object.keys(E).length>0,R=n.useMemo(()=>h!==`summary`||!e.chart||!e.chart.type?null:ne({report:e,rows:T,labels:{resolveColumnLabel:S,resolveCountLabel:t=>{let n=y?.fields?.[t]?.label??t;return`${_(e.objectName,t,n)} · ${g(`report.aggregate.count`,`Count`)}`},resolveAxisValue:C}}).schema,[e,T,h,S,C,y,_,g]);return(0,o.jsxs)(`div`,{className:m,"data-testid":`spec-report-grid`,"aria-busy":O||void 0,children:[k?(0,o.jsx)(`div`,{role:`alert`,style:{...le,color:`rgb(190 18 60)`},children:k.message}):null,I?(0,o.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,o.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:g(`report.totals`,`Totals`)}),F.map(e=>{let t=b(e),n=E[t],r=S(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,o.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,o.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,o.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,R?(0,o.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,o.jsx)(i.SchemaRenderer,{schema:R})}):null,(0,o.jsx)(c.ObjectGrid,{schema:j,data:M,dataSource:t,onRowClick:P?N:void 0})]})};B.displayName=`SpecReportGrid`;var V=`—`;function ue(e){return e==null?V:typeof e==`number`?e.toLocaleString():String(e)}function de(e,t,n){if(e==null||e===``||e===`(null)`)return n;let r=t?.options;if(r){let t=r.get(e);if(t!==void 0&&t!==``)return t}return e}function fe({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,o.jsx)(o.Fragment,{children:r}):(0,o.jsx)(o.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return de(e,a?n.get(a):void 0,i)}).join(` / `)})}var pe=({report:e,dataSource:t,rows:r,runtimeFilter:i,onCellClick:c,actionRunner:u,drillView:d,drillOpenIn:f,className:p,emptyCellText:m=V})=>{let{pivot:h,loading:g,error:_}=L(e,{dataSource:t,rows:r,runtimeFilter:i}),v=e.columns??[],y=v.length>1,{fieldLabel:x,translateOptions:S}=(0,l.useSafeFieldLabel)(),{t:C}=(0,s.useTranslation)(),w=C(`report.emptyLabel`,`(Empty)`),T=C(`report.allLabel`,`(All)`),[E,D]=n.useState(null);n.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||D(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let O=e.groupingsDown??[],k=e.groupingsAcross??[],A=n.useMemo(()=>{let t=new Map,n=E?.fields??{},r=[...O,...k];for(let i of r){let r=n[i.field],a=r?.label??i.field,o=x(e.objectName,i.field,a),s=r?.type===`select`||r?.type===`status`,c;if(s&&Array.isArray(r?.options)&&r.options.length>0){let t=S(e.objectName,i.field,r.options);c=new Map;for(let e of t)e&&e.value!==void 0&&e.value!==null&&c.set(String(e.value),e.label==null?String(e.value):String(e.label))}t.set(i.field,{fieldLabel:o,options:c})}return t},[E,O,k,e.objectName,x,S]),j=n.useMemo(()=>{let t=new Map,n=E?.fields??{};for(let r of v){let i=b(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=x(e.objectName,r.field,a);if(r.aggregate){let e=C(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[v,E,e.objectName,x,C]),M=n.useCallback((t,n,r)=>{let a={...t.key,...n.key};if(u){let t=z(e,a,{runtimeFilter:i,view:d,openIn:f});u.execute(t)}c&&c({rowKey:t.key,colKey:n.key,combinedKey:a,values:r})},[u,f,d,c,e,i]);if(_)return(0,o.jsx)(`div`,{className:(0,a.cn)(`rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive`,p),role:`alert`,"data-testid":`matrix-error`,children:C(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:_.message})});if(!h)return(0,o.jsx)(`div`,{className:(0,a.cn)(`rounded-md border border-dashed border-border bg-muted/30 px-4 py-6 text-center text-sm text-muted-foreground`,p),"aria-busy":g||void 0,"data-testid":`matrix-empty`,children:g?C(`report.loading`,`Loading…`):C(`report.needsAcross`,"Matrix report requires at least one `groupingsAcross` field.")});let N=!!c||!!u,P=O.map(e=>A.get(e.field)?.fieldLabel??e.field).join(` / `)||C(`report.rowsLabel`,`Row`),F=k.map(e=>A.get(e.field)?.fieldLabel??e.field).join(` / `)||C(`report.columnsLabel`,`Column`),I=v.length>0?b(v[0]):null,R=0;if(I)for(let e of h.rowHeaders)for(let t of h.colHeaders){let n=h.cells[e.id]?.[t.id]?.[I];typeof n==`number`&&n>R&&(R=n)}let ee=e=>{if(!I||R<=0||!e)return 0;let t=e[I];return typeof t!=`number`||t<=0?0:Math.min(1,t/R)};return(0,o.jsx)(`div`,{className:(0,a.cn)(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,p),"data-testid":`matrix-renderer`,"aria-busy":g||void 0,children:(0,o.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsxs)(`th`,{scope:`col`,className:(0,a.cn)(`sticky left-0 top-0 z-30 border-b border-r border-border bg-muted/60`,`px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-muted-foreground`),"aria-label":`${P} \u2192 ${F}`,children:[(0,o.jsx)(`span`,{className:`text-muted-foreground/70`,children:P}),(0,o.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,o.jsx)(`span`,{className:`text-foreground/80`,children:F})]}),h.colHeaders.map(e=>(0,o.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-border bg-muted/60 px-3 py-2 text-right text-xs font-semibold text-foreground`,children:(0,o.jsx)(fe,{header:e,groupings:k,metaByField:A,fallback:T,emptyLabel:w})},`col-${e.id}`)),(0,o.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-l border-border bg-muted px-3 py-2 text-right text-xs font-semibold uppercase tracking-wide text-foreground`,children:C(`report.rowTotal`,`Row Total`)})]})}),(0,o.jsx)(`tbody`,{children:h.rowHeaders.map((e,t)=>(0,o.jsxs)(`tr`,{className:`group`,children:[(0,o.jsx)(`th`,{scope:`row`,className:(0,a.cn)(`sticky left-0 z-10 whitespace-nowrap border-b border-r border-border bg-card px-3 py-2 text-left text-sm font-medium text-foreground`,`group-hover:bg-muted/50`,t===0&&`border-t-0`),children:(0,o.jsx)(fe,{header:e,groupings:O,metaByField:A,fallback:T,emptyLabel:w})}),h.colHeaders.map(t=>{let n=h.cells[e.id]?.[t.id],r=!n,i=ee(n);return(0,o.jsx)(`td`,{className:(0,a.cn)(`border-b border-border px-3 py-2 text-right tabular-nums transition-colors`,r?`text-muted-foreground/40`:`text-foreground`,N&&!r&&`cursor-pointer hover:outline hover:outline-2 hover:-outline-offset-2 hover:outline-primary/50`,`group-hover:bg-muted/30`),style:i>0?{backgroundColor:`rgba(59, 130, 246, ${.06+i*.28})`}:void 0,onClick:N&&!r?()=>M(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?m:H(v,n,y,j)},`cell-${e.id}-${t.id}`)}),(0,o.jsx)(`td`,{className:(0,a.cn)(`border-b border-l border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,`group-hover:bg-muted/60`),children:H(v,h.rowTotals[e.id]??{},y,j)})]},`row-${e.id}`))}),(0,o.jsx)(`tfoot`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{scope:`row`,className:`sticky left-0 z-10 whitespace-nowrap border-t-2 border-r border-border bg-muted px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-foreground`,children:C(`report.columnTotal`,`Column Total`)}),h.colHeaders.map(e=>(0,o.jsx)(`td`,{className:`border-t-2 border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,children:H(v,h.colTotals[e.id]??{},y,j)},`coltotal-${e.id}`)),(0,o.jsx)(`td`,{className:`border-l border-t-2 border-border bg-primary/10 px-3 py-2 text-right text-sm font-bold tabular-nums text-foreground`,children:H(v,h.grandTotal,y,j)})]})})]})})};function H(e,t,n,r){return e.length?n?(0,o.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=b(e);return(0,o.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,o.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,o.jsx)(`span`,{className:`tabular-nums`,children:ue(t[n])})]},n)})}):ue(t[b(e[0])]):V}function me(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function he(e,t){if(!t||Object.keys(t).length===0)return e;let n=M(t,e.filter);return{...e,filter:n}}var ge=({report:e,dataSource:t,runtimeFilter:n,actionRunner:i,drillView:a,drillOpenIn:s,className:c,renderBlock:l})=>{if(!(0,r.isJoinedSpecReport)(e))return(0,o.jsxs)(`div`,{className:c,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,o.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,o.jsx)(`code`,{children:`blocks`}),` array.`]});let u=e.blocks??[],d=e.filter,f=e.objectName;return(0,o.jsx)(`div`,{className:c,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:u.map((e,r)=>{let c=e.objectName??f??``,u=he({...e,objectName:c,type:e.type??`tabular`,columns:e.columns??[]},d),p=me(e.label,e.name),m=e.description?me(e.description,``):``,h=e.name??`block-${r}`,g=(0,o.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":h,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,o.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,o.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:p}),m?(0,o.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:m}):null]}),(0,o.jsx)(U,{schema:u,dataSource:t,runtimeFilter:n,actionRunner:i,drillView:a,drillOpenIn:s})]},h);return l?l(e,r,g):g})})},_e={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},U=e=>{let{dataSource:t,rows:a,runtimeFilter:s,actionRunner:c,drillView:l,drillOpenIn:u,className:d}=e,f=n.useContext(i.SchemaRendererContext),p=t??f?.dataSource,m=e.schema;if(m&&typeof m==`object`&&m.type===`spec-report`&&m.report&&typeof m.report==`object`&&(m=m.report),(0,r.isSpecReport)(m)){let e=m.type??`tabular`;return e===`matrix`?(0,o.jsx)(pe,{report:m,dataSource:p,rows:a,runtimeFilter:s,actionRunner:c,drillView:l,drillOpenIn:u,className:d}):e===`joined`?(0,r.isJoinedSpecReport)(m)?(0,o.jsx)(ge,{report:m,dataSource:p,runtimeFilter:s,actionRunner:c,drillView:l,drillOpenIn:u,className:d}):(0,o.jsxs)(`div`,{className:d,style:_e,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,o.jsx)(`code`,{children:m.name}),`) is missing a `,(0,o.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,o.jsx)(B,{report:m,dataSource:p,rows:a,runtimeFilter:s,actionRunner:c,drillView:l,drillOpenIn:u,className:d})}return(0,o.jsx)(y,{schema:m})};function ve(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=Se(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
- `))?`"${n.replace(/"/g,`""`)}"`:n??``}));q([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
- `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function ye(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};q(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function W(e,t,n){let r=e.fields||[],i=we(n?.orientation),a=Ce(n?.pageSize);q(`<!DOCTYPE html>
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("react"),require("@object-ui/types"),require("@object-ui/react"),require("@object-ui/components"),require("react/jsx-runtime"),require("lucide-react"),require("@object-ui/fields"),require("@object-ui/i18n")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/types`,`@object-ui/react`,`@object-ui/components`,`react/jsx-runtime`,`lucide-react`,`@object-ui/fields`,`@object-ui/i18n`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUITypes,e.ObjectUIReact,e.ObjectUIComponents,e.react_jsx_runtime,e.lucide_react,e._object_ui_fields,e._object_ui_i18n))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var _=({schema:e})=>{let{title:n,description:r,data:i,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,o.jsxs)(a.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,o.jsxs)(a.CardHeader,{children:[n&&(0,o.jsx)(a.CardTitle,{children:n}),r&&(0,o.jsx)(a.CardDescription,{children:r})]}),(0,o.jsxs)(a.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[c&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,o.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,o.jsx)(r,{schema:{...e.chart,data:e.chart.data||i}})}):(0,o.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),i&&i.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`grid`)||t.ComponentRegistry.get(`table`);return e?(0,o.jsx)(e,{schema:{type:`grid`,rowData:i,columnDefs:s,domLayout:`autoHeight`}}):(0,o.jsx)(`div`,{className:`overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,o.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,o.jsx)(`tr`,{children:s?.map(e=>(0,o.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,o.jsx)(`tbody`,{children:i.map((e,t)=>(0,o.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,o.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function v(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
+ `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
+ `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function y(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};O(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function b(e,t,n){let r=e.fields||[],i=D(n?.orientation),a=E(n?.pageSize);O(`<!DOCTYPE html>
4
4
  <html>
5
5
  <head>
6
6
  <meta charset="utf-8">
7
- <title>${K(e.title||`Report`)}</title>
7
+ <title>${w(e.title||`Report`)}</title>
8
8
  <style>
9
9
  @page { size: ${a} ${i}; margin: 20mm; }
10
10
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
@@ -18,19 +18,19 @@
18
18
  </style>
19
19
  </head>
20
20
  <body>
21
- <h1>${K(e.title||`Report`)}</h1>
22
- ${e.description?`<p class="description">${K(e.description)}</p>`:``}
21
+ <h1>${w(e.title||`Report`)}</h1>
22
+ ${e.description?`<p class="description">${w(e.description)}</p>`:``}
23
23
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
24
24
  <table>
25
- <thead><tr>${r.map(e=>`<th>${K(e.label||e.name)}</th>`).join(``)}</tr></thead>
26
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${K(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
25
+ <thead><tr>${r.map(e=>`<th>${w(e.label||e.name)}</th>`).join(``)}</tr></thead>
26
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${w(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
27
27
  </table>
28
28
  </body>
29
- </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function be(e,t,n){let r=e.fields||[],i=we(n?.orientation),a=Ce(n?.pageSize),o=window.open(``,`_blank`);if(!o){W(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
29
+ </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function x(e,t,n){let r=e.fields||[],i=D(n?.orientation),a=E(n?.pageSize),o=window.open(``,`_blank`);if(!o){b(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
30
30
  <html>
31
31
  <head>
32
32
  <meta charset="utf-8">
33
- <title>${K(e.title||`Report`)}</title>
33
+ <title>${w(e.title||`Report`)}</title>
34
34
  <style>
35
35
  @page { size: ${a} ${i}; margin: 20mm; }
36
36
  @media print { .no-print { display: none; } }
@@ -45,15 +45,15 @@ ${e.description?`<p class="description">${K(e.description)}</p>`:``}
45
45
  </style>
46
46
  </head>
47
47
  <body>
48
- <h1>${K(e.title||`Report`)}</h1>
49
- ${e.description?`<p class="description">${K(e.description)}</p>`:``}
48
+ <h1>${w(e.title||`Report`)}</h1>
49
+ ${e.description?`<p class="description">${w(e.description)}</p>`:``}
50
50
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
51
51
  <table>
52
- <thead><tr>${r.map(e=>`<th>${K(e.label||e.name)}</th>`).join(``)}</tr></thead>
53
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${K(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
52
+ <thead><tr>${r.map(e=>`<th>${w(e.label||e.name)}</th>`).join(``)}</tr></thead>
53
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${w(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
54
54
  </table>
55
55
  </body>
56
- </html>`),o.document.close(),o.onload=()=>{o.print()}}function xe(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=Se(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
- `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));q(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
- `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function G(e,t,n,r){switch(e){case`csv`:ve(t,n,r);break;case`json`:ye(t,n,r);break;case`html`:W(t,n,r);break;case`pdf`:be(t,n,r);break;case`excel`:xe(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function K(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function Se(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function Ce(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function we(e){return e===`landscape`?`landscape`:`portrait`}function q(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function J(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||Te(e))return Ee(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function Te(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function Ee(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function De(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var Y=({schema:e,onRefresh:r})=>{let{report:s,data:c,showToolbar:l=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!s){console.warn(`ReportViewer: Cannot export, no report defined`);return}G(e,s,c||[],s.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!c)return 0;let n=c.map(t=>Number(t[e])||0);switch(t){case`count`:return c.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=s?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return J(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,d.getCellRenderer)((0,d.resolveCellRendererType)(n)),{value:e,field:n})}return J(e,t)};return s?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[l&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:s.title}),s.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(u.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(u.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&s.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(u.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!l&&s.title&&(0,o.jsx)(a.CardTitle,{children:s.title}),!l&&s.description&&(0,o.jsx)(a.CardDescription,{children:s.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&s.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:s.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:J(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:c||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=De(c||[],s.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):c?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!s.sections&&c&&c.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:s.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:c.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:s.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},Oe=({schedule:e,onChange:t})=>{let[r,i]=(0,n.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),s=e=>{let n={...r,...e};i(n),t?.(n)};return(0,o.jsxs)(a.Card,{children:[(0,o.jsx)(a.CardHeader,{children:(0,o.jsxs)(a.CardTitle,{className:`flex items-center gap-2`,children:[(0,o.jsx)(u.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,o.jsxs)(a.CardContent,{className:`space-y-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,o.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:r.enabled||!1,onChange:e=>s({enabled:e.target.checked}),className:`rounded`}),(0,o.jsx)(a.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),r.enabled&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Frequency`}),(0,o.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:r.frequency||`weekly`,onChange:e=>s({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.frequency===`weekly`&&(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Day of Week`}),(0,o.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:r.dayOfWeek??1,onChange:e=>s({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.frequency===`monthly`&&(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Day of Month`}),(0,o.jsx)(a.Input,{type:`number`,min:1,max:31,value:r.dayOfMonth??1,onChange:e=>s({dayOfMonth:Number(e.target.value)})})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsxs)(a.Label,{className:`flex items-center gap-2`,children:[(0,o.jsx)(u.Clock,{className:`h-4 w-4`}),`Time`]}),(0,o.jsx)(a.Input,{type:`time`,value:r.time||`09:00`,onChange:e=>s({time:e.target.value})})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Timezone`}),(0,o.jsx)(a.Input,{value:r.timezone||``,onChange:e=>s({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Export Formats`}),(0,o.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,o.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:r.formats?.includes(e.value)||!1,onChange:t=>{let n=r.formats||[];s({formats:t.target.checked?[...n,e.value]:n.filter(t=>t!==e.value)})},className:`rounded`}),(0,o.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsxs)(a.Label,{className:`flex items-center gap-2`,children:[(0,o.jsx)(u.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,o.jsx)(a.Input,{placeholder:`email1@example.com, email2@example.com`,value:r.recipients?.join(`, `)||``,onChange:e=>s({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Email Subject`}),(0,o.jsx)(a.Input,{value:r.subject||``,onChange:e=>s({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},ke=({schema:e})=>{let{report:t,dataSources:r=[],availableFields:i=[],showPreview:s=!0,onSave:c,onCancel:l}=e,[d,f]=(0,n.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[p,m]=(0,n.useState)(d.fields||[]),[h,g]=(0,n.useState)(d.filters||[]),[_,v]=(0,n.useState)(d.groupBy||[]),[y,b]=(0,n.useState)(d.sections||[]),x=()=>{if(i.length>0&&p.length<i.length){let e=i.find(e=>!p.some(t=>t.name===e.name));if(e){let t=[...p,e];m(t),f({...d,fields:t})}}},S=e=>{let t=p.filter((t,n)=>n!==e);m(t),f({...d,fields:t})},C=(e,t)=>{let n=[...p];n[e]=t,m(n),f({...d,fields:n})},w=()=>{let e={field:i[0]?.name||``,operator:`equals`,value:``},t=[...h,e];g(t),f({...d,filters:t})},T=e=>{let t=h.filter((t,n)=>n!==e);g(t),f({...d,filters:t})},E=(e,t)=>{let n=[...h];n[e]=t,g(n),f({...d,filters:n})},D=()=>{let e={field:i[0]?.name||``,sort:`asc`},t=[..._,e];v(t),f({...d,groupBy:t})},O=e=>{let t=_.filter((t,n)=>n!==e);v(t),f({...d,groupBy:t})},k=(e,t)=>{let n=[..._];n[e]=t,v(n),f({...d,groupBy:n})},A=e=>{let t={type:e,title:`New ${e} Section`},n=[...y,t];b(n),f({...d,sections:n})},j=e=>{let t=y.filter((t,n)=>n!==e);b(t),f({...d,sections:t})},M=(e,t)=>{let n=[...y];n[e]=t,b(n),f({...d,sections:n})};return(0,o.jsxs)(`div`,{className:`space-y-4`,children:[(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[(0,o.jsx)(a.CardTitle,{children:`Report Builder`}),(0,o.jsx)(a.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,o.jsxs)(a.CardContent,{children:[(0,o.jsxs)(a.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,o.jsxs)(a.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,o.jsxs)(a.TabsTrigger,{value:`basic`,children:[(0,o.jsx)(u.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,o.jsxs)(a.TabsTrigger,{value:`fields`,children:[(0,o.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,o.jsxs)(a.TabsTrigger,{value:`filters`,children:[(0,o.jsx)(u.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,o.jsxs)(a.TabsTrigger,{value:`grouping`,children:[(0,o.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,o.jsxs)(a.TabsTrigger,{value:`sections`,children:[(0,o.jsx)(u.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,o.jsxs)(a.TabsTrigger,{value:`schedule`,children:[(0,o.jsx)(u.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,o.jsx)(a.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,o.jsxs)(`div`,{className:`space-y-4`,children:[(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,o.jsx)(a.Input,{id:`report-title`,value:d.title||``,onChange:e=>f({...d,title:e.target.value}),placeholder:`Enter report title`})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{htmlFor:`report-description`,children:`Description`}),(0,o.jsx)(a.Input,{id:`report-description`,value:d.description||``,onChange:e=>f({...d,description:e.target.value}),placeholder:`Enter report description`})]}),r.length>0&&(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Data Source`}),(0,o.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,o.jsx)(`option`,{value:``,children:`Select a data source`}),r.map((e,t)=>(0,o.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{children:`Export Options`}),(0,o.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,o.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:d.showExportButtons||!1,onChange:e=>f({...d,showExportButtons:e.target.checked})}),(0,o.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,o.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:d.showPrintButton||!1,onChange:e=>f({...d,showPrintButton:e.target.checked})}),(0,o.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,o.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:d.defaultExportFormat||`pdf`,onChange:e=>f({...d,defaultExportFormat:e.target.value}),children:[(0,o.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,o.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,o.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,o.jsx)(`option`,{value:`json`,children:`JSON`}),(0,o.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,o.jsxs)(a.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsx)(a.Label,{children:`Report Fields`}),(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:p.length>=i.length,children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,o.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,o.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Field Name`}),(0,o.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Label`}),(0,o.jsx)(a.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Aggregation`}),(0,o.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,o.jsx)(`option`,{value:``,children:`None`}),(0,o.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,o.jsx)(`option`,{value:`count`,children:`Count`}),(0,o.jsx)(`option`,{value:`avg`,children:`Average`}),(0,o.jsx)(`option`,{value:`min`,children:`Min`}),(0,o.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,o.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,o.jsx)(a.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,o.jsx)(u.Trash2,{className:`h-4 w-4`})})})]})},t)),p.length===0&&(0,o.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,o.jsxs)(a.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsx)(a.Label,{children:`Report Filters`}),(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[h.map((e,t)=>(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,o.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Field`}),(0,o.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:i.map((e,t)=>(0,o.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Operator`}),(0,o.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,o.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,o.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,o.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,o.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,o.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Value`}),(0,o.jsx)(a.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,o.jsx)(a.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,o.jsx)(u.Trash2,{className:`h-4 w-4`})})]},t)),h.length===0&&(0,o.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,o.jsxs)(a.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsx)(a.Label,{children:`Grouping Rules`}),(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,o.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Field`}),(0,o.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:i.map((e,t)=>(0,o.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Sort Order`}),(0,o.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,o.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,o.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,o.jsx)(a.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,o.jsx)(u.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,o.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,o.jsxs)(a.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsx)(a.Label,{children:`Report Sections`}),(0,o.jsxs)(`div`,{className:`flex gap-2`,children:[(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`header`),children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`chart`),children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,o.jsxs)(a.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`table`),children:[(0,o.jsx)(u.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,o.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,o.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,o.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,o.jsx)(a.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>j(t),children:(0,o.jsx)(u.Trash2,{className:`h-4 w-4`})})]}),(0,o.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Title`}),(0,o.jsx)(a.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>M(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,o.jsxs)(`div`,{className:`col-span-2`,children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Content`}),(0,o.jsx)(a.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>M(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,o.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,o.jsx)(`div`,{className:`col-span-2`,children:(0,o.jsx)(a.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Chart Type`}),(0,o.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,o.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,o.jsx)(`option`,{value:`line`,children:`Line`}),(0,o.jsx)(`option`,{value:`area`,children:`Area`}),(0,o.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,o.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,o.jsx)(`option`,{value:``,children:`Select Field...`}),i.map(e=>(0,o.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),i.length===0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`option`,{value:`name`,children:`Name`}),(0,o.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,o.jsxs)(`div`,{className:`col-span-2`,children:[(0,o.jsx)(a.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,o.jsx)(a.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,o.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,o.jsx)(a.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,o.jsx)(Oe,{schedule:d.schedule,onChange:e=>f({...d,schedule:e})})})]}),(0,o.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,o.jsx)(a.Button,{variant:`outline`,onClick:()=>{l&&console.log(`Report cancelled:`,l)},children:`Cancel`}),(0,o.jsxs)(a.Button,{onClick:()=>{console.log(`Saving report:`,d),c&&alert(`Report saved! (Handler: `+c+`)`)},children:[(0,o.jsx)(u.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),s&&(0,o.jsxs)(a.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,o.jsx)(a.CardHeader,{className:`bg-blue-50/50`,children:(0,o.jsx)(a.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,o.jsx)(a.CardContent,{className:`pt-6`,children:(0,o.jsx)(Y,{schema:{type:`report-viewer`,report:{...d,fields:p,filters:h,groupBy:_,sections:y},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},Ae=[`tabular`,`summary`,`matrix`];function je(e){let t=e.length+1,n=new Set(e.map(e=>e.name).filter(Boolean)),r=`block_${t}`;for(;n.has(r);)t+=1,r=`block_${t}`;return{name:r,type:`tabular`,columns:[]}}function Me(e){return typeof e.label==`string`?e.label:e.label&&typeof e.label==`object`?e.label.default??``:``}function Ne(e){return typeof e.description==`string`?e.description:e.description&&typeof e.description==`object`?e.description.default??``:``}function Pe({block:e,index:t,total:r,availableFields:i,t:s,duplicateName:c,onChange:l,onRemove:d,onMove:f}){let[p,m]=n.useState(t===0),h=e.type??`tabular`,g=h===`summary`,_=h===`matrix`,v=g||_,y=!e.name||!e.name.trim(),b=y||c,x=t=>l({...e,...t});return(0,o.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,o.jsx)(a.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0`,onClick:()=>m(e=>!e),"aria-label":p?`Collapse block`:`Expand block`,"aria-expanded":p,"data-testid":`joined-block-toggle-${t}`,children:p?(0,o.jsx)(u.ChevronDown,{className:`h-3.5 w-3.5`}):(0,o.jsx)(u.ChevronRight,{className:`h-3.5 w-3.5`})}),(0,o.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background flex-1 min-w-0 ${b?`border-destructive`:``}`,value:e.name??``,onChange:e=>x({name:e.target.value}),placeholder:s(`report.editor.blockNamePlaceholder`),"aria-label":s(`report.editor.blockName`),"aria-invalid":b,"data-testid":`joined-block-name-${t}`}),(0,o.jsx)(`select`,{className:`h-6 text-xs border rounded px-1 bg-background shrink-0`,value:h,onChange:e=>x({type:e.target.value}),"aria-label":s(`report.editor.type`),"data-testid":`joined-block-type-${t}`,children:Ae.map(e=>(0,o.jsx)(`option`,{value:e,children:s(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,o.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>f(-1),"aria-label":`Move block up`,children:(0,o.jsx)(u.ArrowUp,{className:`h-2.5 w-2.5`})}),(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===r-1,onClick:()=>f(1),"aria-label":`Move block down`,children:(0,o.jsx)(u.ArrowDown,{className:`h-2.5 w-2.5`})})]}),(0,o.jsx)(a.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive`,onClick:d,"aria-label":s(`report.editor.removeBlock`),"data-testid":`joined-block-remove-${t}`,children:(0,o.jsx)(u.Trash2,{className:`h-3 w-3`})})]}),b&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,o.jsx)(u.AlertTriangle,{className:`h-3 w-3`}),s(y?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),p&&(0,o.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,o.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,o.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:s(`report.editor.blockLabel`)}),(0,o.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:Me(e),onChange:e=>x({label:e.target.value||void 0}),placeholder:s(`report.editor.blockLabelPlaceholder`),"data-testid":`joined-block-label-${t}`})]}),(0,o.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:s(`report.editor.objectName`)}),(0,o.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:e.objectName??``,onChange:e=>x({objectName:e.target.value||void 0}),placeholder:s(`report.editor.objectNamePlaceholder`),"data-testid":`joined-block-object-${t}`})]})]}),(0,o.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:s(`report.editor.blockDescription`)}),(0,o.jsx)(`textarea`,{className:`text-xs border rounded px-1.5 py-1 bg-background resize-y min-h-[2rem]`,rows:2,value:Ne(e),onChange:e=>x({description:e.target.value||void 0}),placeholder:s(`report.editor.blockDescriptionPlaceholder`),"data-testid":`joined-block-description-${t}`})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:s(`report.editor.columns`)}),(0,o.jsx)(Q,{availableFields:i,value:e.columns,onChange:e=>x({columns:e}),t:s})]}),(g||_)&&(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:s(`report.editor.rows`)}),(0,o.jsx)($,{availableFields:i,value:e.groupingsDown,onChange:e=>x({groupingsDown:e}),t:s})]}),_&&(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:s(`report.editor.columnsAxis`)}),(0,o.jsx)($,{availableFields:i,value:e.groupingsAcross,onChange:e=>x({groupingsAcross:e}),t:s})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:s(`report.editor.filters`)}),(0,o.jsx)(Ge,{availableFields:i,value:e.filter,onChange:e=>x({filter:e}),t:s})]}),v&&(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:s(`report.editor.chart`)}),(0,o.jsx)(Qe,{availableFields:i,columns:Ze(e.columns),value:e.chart,onChange:e=>x({chart:e}),t:s})]})]})]})}function Fe(e){return Array.isArray(e)?e.map(e=>{let t=e??{};return{name:t.name??``,type:t.type??`tabular`,columns:Array.isArray(t.columns)?t.columns:[],...t}}):[]}function Ie({value:e,onChange:t,availableFields:n,getFieldsForObject:r,containerObjectName:i,t:s}){let c=Fe(e),l=e=>r?r(e.objectName??i)??n:n,d={};for(let e of c)e.name&&(d[e.name]=(d[e.name]??0)+1);let f=(e,n)=>{t(c.map((t,r)=>r===e?n:t))},p=e=>{t(c.filter((t,n)=>n!==e))},m=(e,n)=>{let r=e+n;if(r<0||r>=c.length)return;let i=[...c];[i[e],i[r]]=[i[r],i[e]],t(i)};return(0,o.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[c.length===0&&(0,o.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:s(`report.editor.validationJoinedNeedsBlocks`)}),c.map((e,t)=>(0,o.jsx)(Pe,{block:e,index:t,total:c.length,availableFields:l(e),t:s,duplicateName:!!e.name&&(d[e.name]??0)>1,onChange:e=>f(t,e),onRemove:()=>p(t),onMove:e=>m(t,e)},t)),(0,o.jsxs)(a.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs w-full`,onClick:()=>{t([...c,je(c)])},"data-testid":`joined-block-add`,children:[(0,o.jsx)(u.Plus,{className:`h-3 w-3 mr-1`}),s(`report.editor.addBlock`)]})]})}function Le(e,t){let n=[];if(!Array.isArray(e)||e.length===0)return n.push(t(`report.editor.validationJoinedNeedsBlocks`)),n;let r=new Map,i=!1,a=!1,o=!1;for(let t of e){let e=t??{};if(!e.name||!String(e.name).trim())i=!0;else{let t=(r.get(e.name)??0)+1;r.set(e.name,t),t===2&&(a=!0)}(!Array.isArray(e.columns)||e.columns.length===0)&&(o=!0)}return i&&n.push(t(`report.editor.validationBlockNameRequired`)),a&&n.push(t(`report.editor.validationBlockNameDuplicate`)),o&&n.push(t(`report.editor.validationBlockNeedsColumns`)),n}var Re={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$in:`in`,$nin:`notIn`,$contains:`contains`,$notContains:`notContains`,$exists:`isNotEmpty`},ze={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,in:`$in`,notIn:`$nin`,contains:`$contains`,notContains:`$notContains`},X=()=>({id:`root`,logic:`and`,conditions:[]});function Be(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Z(){return Math.random().toString(36).slice(2,10)}function Ve(e,t){if(typeof t!=`object`||!t||Array.isArray(t))return[{id:Z(),field:e,operator:Array.isArray(t)?`in`:`equals`,value:t}];let n=[];for(let[r,i]of Object.entries(t)){if(r===`$exists`){n.push({id:Z(),field:e,operator:i===!1?`isEmpty`:`isNotEmpty`,value:``});continue}if(r===`$null`){n.push({id:Z(),field:e,operator:i===!1?`isNotEmpty`:`isEmpty`,value:``});continue}let t=Re[r];if(!t||Be(i)&&`$field`in i)return null;n.push({id:Z(),field:e,operator:t,value:i})}return n.length>0?n:null}function He(e){if(e==null)return{group:X(),complex:!1};if(!Be(e))return{group:X(),complex:!0};let t=Object.keys(e);if(t.length===1&&(t[0]===`$and`||t[0]===`$or`)){let n=t[0]===`$or`?`or`:`and`,r=e[t[0]];if(!Array.isArray(r))return{group:X(),complex:!0};let i=[],a=!1;for(let e of r){if(!Be(e)){a=!0;continue}if(Object.keys(e).some(e=>e===`$and`||e===`$or`||e===`$not`)){a=!0;continue}for(let[t,n]of Object.entries(e)){let e=Ve(t,n);e?i.push(...e):a=!0}}return{group:{id:`root`,logic:n,conditions:i},complex:a}}if(t.includes(`$not`)||t.includes(`$and`)||t.includes(`$or`))return{group:X(),complex:!0};let n=[],r=!1;for(let[t,i]of Object.entries(e)){let e=Ve(t,i);e?n.push(...e):r=!0}return{group:{id:`root`,logic:`and`,conditions:n},complex:r}}function Ue(e){if(!e||!Array.isArray(e.conditions)||e.conditions.length===0)return;let t=e.conditions.filter(e=>e.field).map(e=>We(e));if(t.length!==0)return t.length===1?t[0]:{[e.logic===`or`?`$or`:`$and`]:t}}function We(e){let{field:t,operator:n,value:r}=e;if(n===`isEmpty`)return{[t]:{$exists:!1}};if(n===`isNotEmpty`)return{[t]:{$exists:!0}};if(n===`equals`)return{[t]:r};let i=ze[n];return i?{[t]:{[i]:r}}:{[t]:r}}function Ge({availableFields:e,value:t,onChange:r,t:i}){let s=n.useMemo(()=>JSON.stringify(t??null),[t]),c=n.useMemo(()=>He(t),[s]),[l,d]=n.useState(c.group),f=n.useRef(s);n.useEffect(()=>{f.current!==s&&(d(c.group),f.current=s)},[s,c.group]);let p=e=>{d(e);let t=Ue(e);f.current=JSON.stringify(t??null),r(t)};if(c.complex)return(0,o.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-[11px]`,children:[(0,o.jsx)(u.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{children:i(`report.editor.filtersComplex`)})]});let m=()=>{p({...l,conditions:[...l.conditions,{id:Z(),field:e[0]?.value??``,operator:`equals`,value:``}]})},h=e=>{p({...l,conditions:l.conditions.filter(t=>t.id!==e)})},g=(e,t)=>{p({...l,conditions:l.conditions.map(n=>n.id===e?{...n,...t}:n)})},_=[{value:`equals`,label:`=`},{value:`notEquals`,label:`≠`},{value:`greaterThan`,label:`>`},{value:`greaterOrEqual`,label:`≥`},{value:`lessThan`,label:`<`},{value:`lessOrEqual`,label:`≤`},{value:`contains`,label:i(`report.editor.opContains`,`contains`)},{value:`in`,label:`in`},{value:`notIn`,label:`not in`},{value:`isEmpty`,label:i(`report.editor.opIsEmpty`,`is empty`)},{value:`isNotEmpty`,label:i(`report.editor.opIsNotEmpty`,`is not empty`)}];return(0,o.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[l.conditions.length>1&&(0,o.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,o.jsx)(`span`,{children:i(`report.editor.combineLogic`,`Combine with`)}),(0,o.jsxs)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:l.logic,onChange:e=>p({...l,logic:e.target.value}),"data-testid":`filter-logic-select`,children:[(0,o.jsx)(`option`,{value:`and`,children:`AND`}),(0,o.jsx)(`option`,{value:`or`,children:`OR`})]})]}),l.conditions.map(t=>(0,o.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,o.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:t.field,onChange:e=>g(t.id,{field:e.target.value}),"data-testid":`filter-field-${t.id}`,children:e.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,o.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-20 shrink-0`,value:t.operator,onChange:e=>g(t.id,{operator:e.target.value}),"data-testid":`filter-op-${t.id}`,children:_.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,o.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-24 shrink-0`,value:Array.isArray(t.value)?t.value.join(`,`):(t.value??``).toString(),placeholder:`value`,onChange:e=>{let n=e.target.value,r=t.operator===`in`||t.operator===`notIn`?n.split(`,`).map(e=>e.trim()).filter(Boolean):n;g(t.id,{value:r})},"data-testid":`filter-value-${t.id}`}),(0,o.jsx)(a.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>h(t.id),"data-testid":`filter-remove-${t.id}`,children:(0,o.jsx)(u.Trash2,{className:`h-3 w-3`})})]},t.id)),(0,o.jsxs)(a.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:m,disabled:e.length===0,"data-testid":`filter-add`,children:[(0,o.jsx)(u.Plus,{className:`h-3 w-3 mr-1`}),i(`report.editor.addCondition`,`Add condition`)]})]})}var Ke=new Set([`date`,`datetime`,`time`]),qe=new Set([`number`,`currency`,`percent`,`rating`,`integer`]);function Je({availableFields:e,selectedValues:t,onAdd:r,t:i,triggerLabel:s,title:c,description:l,testIdPrefix:d=`field-picker`,singleSelect:f=!1,commitOnSelect:p=!1,disabled:m=!1,triggerClassName:h,trigger:g}){let[_,v]=n.useState(!1),[y,b]=n.useState(``),[x,S]=n.useState(new Set),C=n.useMemo(()=>new Set(t),[t]);n.useEffect(()=>{_&&(b(``),S(new Set))},[_]);let w=y.trim().toLowerCase(),T=e.filter(e=>!C.has(e.value)),E=w?T.filter(e=>e.label.toLowerCase().includes(w)||e.value.toLowerCase().includes(w)):T,D=e=>{if(f&&p){r([e]),v(!1);return}S(t=>{let n=new Set(f?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},O=()=>{if(x.size===0){v(!1);return}r(T.map(e=>e.value).filter(e=>x.has(e))),v(!1)},k=()=>{v(!1)},A=e.length===0,j=!A&&T.length===0,M=s??i(`report.editor.addColumns`,`Add fields`),N=c??i(`report.editor.fieldPickerTitle`,`Select fields`),P=l??i(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,o.jsxs)(a.Dialog,{open:_,onOpenChange:v,children:[(0,o.jsx)(a.DialogTrigger,{asChild:!0,children:g??(0,o.jsxs)(a.Button,{type:`button`,variant:`outline`,size:`sm`,className:h??`h-8 gap-1.5`,disabled:m||A||j,"data-testid":`${d}-trigger`,children:[(0,o.jsx)(u.Plus,{className:`h-3.5 w-3.5`}),(0,o.jsx)(`span`,{children:M})]})}),(0,o.jsxs)(a.DialogContent,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${d}-dialog`,children:[(0,o.jsxs)(a.DialogHeader,{children:[(0,o.jsx)(a.DialogTitle,{children:N}),(0,o.jsx)(a.DialogDescription,{children:P})]}),(0,o.jsxs)(`div`,{className:`relative`,children:[(0,o.jsx)(u.Search,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,o.jsx)(`input`,{type:`text`,className:`h-9 w-full text-sm border rounded pl-7 pr-2 bg-background`,placeholder:i(`report.editor.searchFields`,`Search fields…`),value:y,onChange:e=>b(e.target.value),"data-testid":`${d}-search`,autoFocus:!0})]}),(0,o.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,o.jsxs)(`span`,{children:[E.length,`/`,T.length,x.size>0?` · ${i(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(x.size))}`:``]}),x.size>0&&(0,o.jsx)(`button`,{type:`button`,className:`text-[11px] underline-offset-2 hover:underline text-muted-foreground`,onClick:()=>S(new Set),"data-testid":`${d}-clear`,children:i(`report.editor.fieldPickerClear`,`Clear selection`)})]}),(0,o.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${d}-list`,children:A?(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:i(`report.editor.noFields`,`No fields available — pick a data source first.`)}):j?(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:i(`report.editor.noFieldsAvailable`,`All fields already added.`)}):E.length===0?(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:i(`report.editor.noMatchingFields`,`No fields match your search.`)}):E.map(e=>{let t=x.has(e.value);return(0,o.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/50 text-sm cursor-pointer`,"data-testid":`${d}-row-${e.value}`,children:[(0,o.jsx)(a.Checkbox,{checked:t,onCheckedChange:()=>D(e.value),"data-testid":`${d}-toggle-${e.value}`}),(0,o.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(f&&p)&&(0,o.jsxs)(a.DialogFooter,{className:`gap-2 sm:gap-2`,children:[(0,o.jsx)(a.Button,{type:`button`,variant:`ghost`,size:`sm`,onClick:k,"data-testid":`${d}-cancel`,children:i(`common.cancel`,`Cancel`)}),(0,o.jsx)(a.Button,{type:`button`,size:`sm`,onClick:O,disabled:x.size===0,"data-testid":`${d}-confirm`,children:x.size>0?i(`report.editor.fieldPickerAddN`,`Add {n}`).replace(`{n}`,String(x.size)):i(`report.editor.fieldPickerAdd`,`Add`)})]})]})]})}function Ye(e){return[{value:``,label:e(`report.editor.noneOption`)},{value:`sum`,label:e(`report.aggregate.sum`)},{value:`count`,label:e(`report.aggregate.count`)},{value:`unique`,label:e(`report.aggregate.countDistinct`)},{value:`avg`,label:e(`report.aggregate.avg`)},{value:`min`,label:e(`report.aggregate.min`)},{value:`max`,label:e(`report.aggregate.max`)}]}function Xe(e){return[{value:``,label:e(`report.editor.formatAuto`,`Auto`)},{value:`currency`,label:e(`report.editor.formatCurrency`,`Currency`)},{value:`percent`,label:e(`report.editor.formatPercent`,`Percent`)},{value:`integer`,label:e(`report.editor.formatInteger`,`Integer`)},{value:`date`,label:e(`report.editor.formatDate`,`Date`)},{value:`datetime`,label:e(`report.editor.formatDatetime`,`Date & time`)}]}function Ze(e){return Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label,type:e.type||`string`,aggregate:e.aggregate??e.aggregation,format:e.format}):[]}function Q({availableFields:e,value:t,onChange:n,t:r}){let i=Ze(t),s=new Set(i.map(e=>e.field)),c=Ye(r),l=Xe(r),d=t=>{if(t.length===0)return;let r=t.filter(e=>!s.has(e)).map(t=>{let n=e.find(e=>e.value===t);return{field:t,label:n?.label,type:n?.type||`string`}});r.length!==0&&n([...i,...r])},f=e=>{n(i.filter(t=>t.field!==e))},p=(e,t)=>{n(i.map(n=>n.field===e?{...n,...t}:n))},m=(e,t)=>{let r=[...i],a=e+t;a<0||a>=r.length||([r[e],r[a]]=[r[a],r[e]],n(r))};return e.length===0?(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`columns-editor-empty`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):(0,o.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,o.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`columns-selected`,children:i.map((t,n)=>{let s=e.find(e=>e.value===t.field);return(0,o.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-1.5 p-1.5 border rounded bg-muted/30 text-xs`,"data-testid":`column-row-${t.field}`,children:[(0,o.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>m(n,-1),"aria-label":`Move up`,"data-testid":`column-up-${t.field}`,children:(0,o.jsx)(u.ArrowUp,{className:`h-3 w-3`})}),(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===i.length-1,onClick:()=>m(n,1),"aria-label":`Move down`,"data-testid":`column-down-${t.field}`,children:(0,o.jsx)(u.ArrowDown,{className:`h-3 w-3`})})]}),(0,o.jsx)(`input`,{className:`h-7 text-xs border rounded px-2 bg-background min-w-0 w-full`,value:t.label??``,placeholder:s?.label??t.field,onChange:e=>p(t.field,{label:e.target.value||void 0}),"data-testid":`column-label-${t.field}`,title:s?.label??t.field}),(0,o.jsx)(a.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`row-span-2 h-7 w-7 p-0 shrink-0 self-start`,onClick:()=>f(t.field),"data-testid":`column-remove-${t.field}`,"aria-label":`Remove column`,children:(0,o.jsx)(u.Trash2,{className:`h-3.5 w-3.5`})}),(0,o.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,o.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,o.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.aggregate??``,onChange:e=>p(t.field,{aggregate:e.target.value===``?void 0:e.target.value}),"data-testid":`column-agg-${t.field}`,children:c.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,o.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,o.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,o.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.format??``,onChange:e=>p(t.field,{format:e.target.value===``?void 0:e.target.value}),"data-testid":`column-fmt-${t.field}`,children:l.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,o.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i.length>0?r(`report.editor.columnsCount`,`{n} column(s) selected`).replace(`{n}`,String(i.length)):r(`report.editor.columnsEmpty`,`No columns selected yet.`)}),(0,o.jsx)(Je,{availableFields:e,selectedValues:i.map(e=>e.field),onAdd:d,t:r,testIdPrefix:`columns-picker`,triggerLabel:r(`report.editor.addColumns`,`Add fields`)})]})]})}function $({availableFields:e,value:t,onChange:n,t:r,testIdPrefix:i=`grouping`}){let s=Array.isArray(t)?t.map(e=>({field:e.field??``,sortOrder:e.sortOrder??e.sort??`asc`,dateGranularity:e.dateGranularity})):[],c=[{value:``,label:r(`report.editor.dateGranularityNone`)},{value:`day`,label:r(`report.editor.day`)},{value:`week`,label:r(`report.editor.week`)},{value:`month`,label:r(`report.editor.month`)},{value:`quarter`,label:r(`report.editor.quarter`)},{value:`year`,label:r(`report.editor.year`)}],l=s.map(e=>e.field).filter(Boolean),d=e=>{n(s.filter((t,n)=>n!==e))},f=(e,t)=>{n(s.map((n,r)=>r===e?{...n,...t}:n))},p=(e,t)=>{let r=[...s],i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],n(r))},m=e=>{if(e.length===0)return;let t=e.map(e=>({field:e,sortOrder:`asc`}));n([...s,...t])},h=(t,n)=>{let r=n[0];if(!r)return;let i=e.find(e=>e.value===r);f(t,{field:r,dateGranularity:i&&Ke.has(i.type??``)?s[t]?.dateGranularity:void 0})};return(0,o.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`${i}s-builder`,children:[s.map((t,n)=>{let m=e.find(e=>e.value===t.field),g=m&&Ke.has(m.type??``),_=m?.label??t.field??r(`report.editor.fieldPickerEmpty`,`(pick field)`);return(0,o.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5 border rounded bg-muted/20 text-xs`,"data-testid":`${i}-row-${n}`,children:[(0,o.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>p(n,-1),"aria-label":`Move up`,"data-testid":`${i}-up-${n}`,children:(0,o.jsx)(u.ArrowUp,{className:`h-3 w-3`})}),(0,o.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===s.length-1,onClick:()=>p(n,1),"aria-label":`Move down`,"data-testid":`${i}-down-${n}`,children:(0,o.jsx)(u.ArrowDown,{className:`h-3 w-3`})})]}),(0,o.jsx)(Je,{availableFields:e,selectedValues:l.filter(e=>e!==t.field),onAdd:e=>h(n,e),t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-field-picker-${n}`,title:r(`report.editor.fieldPickerChangeTitle`,`Change field`),trigger:(0,o.jsxs)(`button`,{type:`button`,className:`h-7 flex-1 min-w-0 text-left text-xs border rounded px-2 bg-background hover:bg-muted/40 inline-flex items-center justify-between gap-1.5`,"data-testid":`${i}-field-${n}`,title:_,children:[(0,o.jsx)(`span`,{className:`truncate`,children:_}),(0,o.jsx)(u.ChevronDown,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,o.jsxs)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-20 shrink-0`,value:t.sortOrder??`asc`,onChange:e=>f(n,{sortOrder:e.target.value}),"data-testid":`${i}-sort-${n}`,children:[(0,o.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,o.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),g&&(0,o.jsx)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-24 shrink-0`,value:t.dateGranularity??``,onChange:e=>f(n,{dateGranularity:e.target.value||void 0}),"data-testid":`${i}-granularity-${n}`,children:c.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,o.jsx)(a.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 shrink-0`,onClick:()=>d(n),"aria-label":`Remove grouping`,"data-testid":`${i}-remove-${n}`,children:(0,o.jsx)(u.Trash2,{className:`h-3.5 w-3.5`})})]},n)}),(0,o.jsx)(Je,{availableFields:e,selectedValues:l,onAdd:m,t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-add-picker`,triggerLabel:r(`report.editor.addGrouping`),title:r(`report.editor.fieldPickerAddGroupingTitle`,`Add grouping`),triggerClassName:`h-8 w-full justify-center gap-1.5`})]})}function Qe({availableFields:e,columns:t,value:n,onChange:r,t:i}){let s=n||{},c=s.type??s.chartType??``,l=s.xAxis??s.xAxisField??``,u=s.yAxis??s.yAxisFields?.[0]??``,d=e=>{let t={...s,...e};if(`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,!e.type&&e.type===``)return r(void 0);r(t)},f=()=>r(void 0),p=[{value:``,label:i(`report.editor.chartNone`)},{value:`bar`,label:i(`report.editor.chartBar`)},{value:`line`,label:i(`report.editor.chartLine`)},{value:`area`,label:i(`report.editor.chartArea`)},{value:`pie`,label:i(`report.editor.chartPie`)},{value:`donut`,label:i(`report.editor.chartDonut`)},{value:`funnel`,label:i(`report.editor.chartFunnel`)}],m=t.filter(e=>e.aggregate).map(e=>e.field),h=e.filter(e=>qe.has(e.type??``)).map(e=>e.value),g=new Set([...m,...h]),_=e.filter(e=>g.has(e.value));return(0,o.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartType`)}),(0,o.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:c,onChange:e=>{let t=e.target.value;t?d({type:t}):f()},"data-testid":`chart-type-select`,children:p.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),c&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,o.jsx)(`input`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s.title??``,placeholder:i(`report.editor.chartTitlePlaceholder`),onChange:e=>d({title:e.target.value||void 0}),"data-testid":`chart-title`})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,o.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:l,onChange:e=>d({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,o.jsx)(`option`,{value:``,children:`—`}),e.map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartYAxis`)}),(0,o.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:u,onChange:e=>d({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,o.jsx)(`option`,{value:``,children:`—`}),(_.length>0?_:e).map(e=>(0,o.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,o.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,o.jsx)(a.Checkbox,{checked:s.showLegend!==!1,onCheckedChange:e=>d({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,o.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,o.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,o.jsx)(a.Checkbox,{checked:!!s.showDataLabels,onCheckedChange:e=>d({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,o.jsx)(`span`,{children:i(`report.editor.chartShowDataLabels`)})]})]})]})}function $e(e,t,n){let r=e=>e.type===`summary`,i=e=>e.type===`matrix`,a=e=>e.type===`summary`||e.type===`matrix`,s=[{key:`basic`,title:t(`report.editor.basic`),fields:[{key:`label`,label:t(`report.editor.title`),type:`input`,placeholder:t(`report.editor.titlePlaceholder`)},{key:`description`,label:t(`report.editor.description`),type:`textarea`,placeholder:t(`report.editor.descriptionPlaceholder`)},{key:`type`,label:t(`report.editor.type`),type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:t(`report.editor.typeTabular`)},{value:`summary`,label:t(`report.editor.typeSummary`)},{value:`matrix`,label:t(`report.editor.typeMatrix`)},{value:`joined`,label:t(`report.editor.typeJoined`)}],helpText:t(`report.editor.typeHelp`)}]},{key:`data`,title:t(`report.editor.data`),collapsible:!0,fields:[{key:`objectName`,label:t(`report.editor.objectName`),type:`input`,placeholder:t(`report.editor.objectNamePlaceholder`),helpText:t(`report.editor.objectNameHelp`)},{key:`limit`,label:t(`report.editor.limit`),type:`input`,placeholder:t(`report.editor.limitPlaceholder`)}]},{key:`rows`,title:t(`report.editor.rows`),collapsible:!0,hint:t(`report.editor.rowsHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`groupingsDown`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,o.jsx)($,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`rows-grouping`})}]},{key:`columnsAxis`,title:t(`report.editor.columnsAxis`),collapsible:!0,hint:t(`report.editor.columnsAxisHint`),visibleWhen:e=>i(e),fields:[{key:`groupingsAcross`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,o.jsx)($,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`cols-grouping`})}]},{key:`tabular-columns`,title:t(`report.editor.columns`),collapsible:!0,hint:t(`report.editor.columnsHint`),visibleWhen:e=>e.type!==`joined`&&!r(e)&&!i(e),fields:[{key:`columns`,label:t(`report.editor.columns`),type:`custom`,render:(n,r)=>(0,o.jsx)(Q,{availableFields:e,value:n,onChange:r,t})}]},{key:`values`,title:t(`report.editor.values`),collapsible:!0,hint:t(`report.editor.valuesHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`columns`,label:t(`report.editor.values`),type:`custom`,render:(n,r)=>(0,o.jsx)(Q,{availableFields:e,value:n,onChange:r,t})}]},{key:`filters`,title:t(`report.editor.filters`),collapsible:!0,hint:t(`report.editor.filtersHint`),visibleWhen:e=>e.type!==`joined`,fields:[{key:`filter`,label:t(`report.editor.filters`),type:`custom`,render:(n,r)=>(0,o.jsx)(Ge,{availableFields:e,value:n,onChange:r,t})}]},{key:`blocks`,title:t(`report.editor.blocks`),collapsible:!0,hint:t(`report.editor.blocksHint`),visibleWhen:e=>e.type===`joined`,fields:[{key:`blocks`,label:t(`report.editor.blocks`),type:`custom`,render:(r,i,a)=>(0,o.jsx)(Ie,{value:r,onChange:i,availableFields:e,getFieldsForObject:n,containerObjectName:a?.objectName,t})}]},{key:`chart`,title:t(`report.editor.chart`),collapsible:!0,defaultCollapsed:!0,hint:t(`report.editor.chartHint`),visibleWhen:e=>a(e),fields:[{key:`chart`,label:t(`report.editor.chart`),type:`custom`,render:(n,r,i)=>(0,o.jsx)(Qe,{availableFields:e,columns:Ze(i.columns),value:n,onChange:r,t})}]}];return{breadcrumb:[t(`report.editor.breadcrumb`,`Configuration`)],sections:s}}function et(e,t){let n=[],r=e.type??`tabular`,i=Array.isArray(e.groupingsDown)?e.groupingsDown.length:0,a=Array.isArray(e.groupingsAcross)?e.groupingsAcross.length:0,o=Array.isArray(e.columns)?e.columns.length:0;if(e.objectName||n.push({level:o>0?`error`:`warning`,message:t(`report.editor.validationNeedsObject`)}),r===`matrix`&&(i===0||a===0)&&n.push({level:`error`,message:t(`report.editor.validationMatrixNeedsRowsCols`)}),r===`summary`&&i===0&&n.push({level:`error`,message:t(`report.editor.validationSummaryNeedsRows`)}),r===`joined`)for(let r of Le(e.blocks,t))n.push({level:`error`,message:r});return n}function tt({problems:e}){return e.length===0?null:(0,o.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,o.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] rounded px-2 py-1 `+(e.level===`error`?`bg-red-50 border border-red-200 text-red-900`:`bg-amber-50 border border-amber-200 text-amber-900`),children:[(0,o.jsx)(u.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{children:e.message})]},t))})}function nt({open:e,onClose:t,config:r,onSave:i,onFieldChange:c,availableFields:l,getFieldsForObject:u}){let{t:d}=(0,s.useTranslation)(),f=n.useCallback((e,t,n)=>t===void 0?d(e,n):d(e,{defaultValue:t,...n||{}}),[d]),p=l??[],m=n.useMemo(()=>$e(p,f,u),[p,f,u]),{draft:h,isDirty:g,updateField:_,discard:v}=(0,a.useConfigDraft)(n.useMemo(()=>r??{},[r])),y=n.useCallback((e,t)=>{_(e,t),c?.(e,t,{...h,[e]:t})},[_,c,h]),b=n.useCallback(()=>{i(h),t()},[h,i,t]),x=n.useMemo(()=>et(h,f),[h,f]);return e?(0,o.jsx)(a.ConfigPanelRenderer,{open:e,onClose:t,schema:m,draft:h,isDirty:g,onFieldChange:y,onSave:b,onDiscard:v,headerExtra:(0,o.jsx)(tt,{problems:x}),style:{"--config-panel-width":`440px`}}):null}async function rt(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return G(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function it(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(ot),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return st(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=lt(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}dt(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
- `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function at(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await rt(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function ot(e){return{name:e.name,header:e.label||e.name}}function st(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,ct(t)):ut(String(e))}function ct(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function lt(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ut(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function dt(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,U,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`spec-report`,U,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,Y,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),t.ComponentRegistry.register(`report-builder`,ke,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]}),e.JoinedBlocksEditor=Ie,e.JoinedReportRenderer=ge,e.LegacyReportRenderer=y,e.MatrixRenderer=pe,e.ReportBuilder=ke,e.ReportConfigPanel=nt,e.ReportRenderer=U,e.ReportViewer=Y,e.ScheduleConfig=Oe,e.SpecReportGrid=B,e.aggregateRows=C,e.bucketDate=x,e.buildAggregateQuery=P,e.buildDrillAction=z,e.collectFields=N,e.columnKey=b,e.createDrillHandler=ie,e.createScheduleTrigger=at,e.exportAsCSV=ve,e.exportAsExcel=xe,e.exportAsHTML=W,e.exportAsJSON=ye,e.exportAsPDF=be,e.exportExcelWithFormulas=it,e.exportReport=G,e.exportWithLiveData=rt,e.formatValue=J,e.groupAndAggregate=w,e.groupingValue=S,e.isDrillAction=re,e.mergeFilters=M,e.pivotRows=T,e.registerDrillHandler=ae,e.useReportData=L,e.validateJoinedBlocks=Le});
56
+ </html>`),o.document.close(),o.onload=()=>{o.print()}}function S(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
+ `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
+ `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function T(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function A(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function j(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function M(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var N=({schema:e,onRefresh:r})=>{let{report:l,data:u,showToolbar:d=!0,allowExport:f=!0,allowPrint:p=!0,loading:m=!1}=e,h=e=>{if(!l){console.warn(`ReportViewer: Cannot export, no report defined`);return}C(e,l,u||[],l.exportConfigs?.[e])},g=()=>{window.print()},_=()=>{r?.()},v=(e,t)=>{if(!u)return 0;let n=u.map(t=>Number(t[e])||0);switch(t){case`count`:return u.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},y=(e,t)=>{let n=l?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},b=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,o.jsx)(a.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return k(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,o.jsx)((0,c.getCellRenderer)((0,c.resolveCellRendererType)(n)),{value:e,field:n})}return k(e,t)};return l?(0,o.jsxs)(`div`,{className:`space-y-4`,children:[d&&(0,o.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`h2`,{className:`text-lg font-semibold`,children:l.title}),l.description&&(0,o.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l.description})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l.refreshInterval&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:_,children:[(0,o.jsx)(s.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),p&&(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,o.jsx)(s.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),f&&l.showExportButtons&&(0,o.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`pdf`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`excel`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,o.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:()=>h(`csv`),children:[(0,o.jsx)(s.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,o.jsxs)(a.Card,{children:[(0,o.jsxs)(a.CardHeader,{children:[!d&&l.title&&(0,o.jsx)(a.CardTitle,{children:l.title}),!d&&l.description&&(0,o.jsx)(a.CardDescription,{children:l.description})]}),(0,o.jsxs)(a.CardContent,{className:`space-y-6`,children:[m&&(0,o.jsxs)(`div`,{className:`space-y-6`,children:[(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4 space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-4 w-20`}),(0,o.jsx)(a.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,o.jsxs)(`div`,{className:`space-y-2`,children:[(0,o.jsx)(a.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,o.jsx)(a.Skeleton,{className:`h-8 w-full`},e))]})]}),!m&&l.sections?.map((e,r)=>e.visible===!1?null:(0,o.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,o.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,o.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,o.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:l.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,o.jsx)(a.Card,{children:(0,o.jsxs)(a.CardContent,{className:`p-4`,children:[(0,o.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,o.jsx)(`div`,{className:`text-2xl font-bold`,children:k(v(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,o.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,o.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:u||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:(()=>{let t=M(u||[],l.groupBy||[]);return t?t.map(t=>(0,o.jsxs)(n.default.Fragment,{children:[(0,o.jsx)(`tr`,{className:`bg-muted/60`,children:(0,o.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))]},t.key)):u?.map((t,n)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:y(e.name,t[e.name]),children:b(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,o.jsx)(`div`,{className:`prose max-w-none`,children:(0,o.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,o.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,o.jsx)(i.SchemaRenderer,{schema:e.content})]},r)),!l.sections&&u&&u.length>0&&(0,o.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,o.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,o.jsx)(`thead`,{className:`bg-muted`,children:(0,o.jsx)(`tr`,{children:l.fields?.map((e,t)=>(0,o.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,o.jsx)(`tbody`,{children:u.map((e,t)=>(0,o.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:l.fields?.map((t,n)=>(0,o.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:y(t.name,e[t.name]),children:b(e[t.name],t)},n))},t))})]})})]})]})]}):(0,o.jsx)(a.Card,{children:(0,o.jsx)(a.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})};function P(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function F(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0?!0:t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function I(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function R(e,t,r,i,a,o){let[s,c]=n.useState({status:`idle`,rows:[]}),l=JSON.stringify(i??null),u=JSON.stringify(o??null),d=`${e}|${t.join(`,`)}|${r.join(`,`)}|${l}|${u}`;return n.useEffect(()=>{let n=a;if(!n||typeof n.queryDataset!=`function`){c({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||r.length===0){c({status:`idle`,rows:[]});return}let s=!1;return c({status:`loading`,rows:[]}),n.queryDataset(e,{dimensions:t,measures:r,...i&&Object.keys(i).length>0?{runtimeFilter:i}:{},...o?{totals:{groupings:o}}:{}}).then(e=>{s||c({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{s||c({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[d]),s}function z({dataset:e}){return(0,o.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]})}function B({status:e,error:t}){return e===`error`?(0,o.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,o.jsx)(s.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,o.jsx)(`span`,{className:`break-words`,children:t})]}):(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Running report…`]})}function V(){return(0,o.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Table2,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]})}var H=`cursor-pointer hover:bg-accent/40`;function U({dataset:e,rows:n,values:r,runtimeFilter:i,dataSource:a,onDrill:s}){let c=R(e,n,r,i,a),{fieldLabel:u}=(0,l.useSafeFieldLabel)();if(r.length===0)return(0,o.jsx)(z,{dataset:e});if(c.status===`loading`||c.status===`idle`)return(0,o.jsx)(B,{status:c.status});if(c.status===`error`)return(0,o.jsx)(B,{status:`error`,error:c.error});if(c.rows.length===0)return(0,o.jsx)(V,{});let d=!!s&&n.length>0,f=c.dimensionFields?n.filter(e=>e in c.dimensionFields):[],p=(r,a)=>{let o={};for(let e of n)o[e]=r[e];let l=c.object&&c.dimensionFields&&f.length>0?(0,t.buildDatasetDrillFilter)(c.drillRawRows?.[a],f,c.dimensionFields,i):void 0;s({dataset:e,groupKey:o,runtimeFilter:i,object:c.object,objectFilter:l})},{measureField:m,headerLabel:h}=(0,t.buildDatasetFieldHelpers)(c.fields,c.object,u),g=[...n,...r];return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsx)(`tr`,{children:g.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:h(e)},e))})}),(0,o.jsx)(`tbody`,{children:c.rows.map((e,n)=>(0,o.jsx)(`tr`,{className:`border-t${d?` ${H}`:``}`,"data-testid":d?`dataset-drill-row`:void 0,onClick:d?()=>p(e,n):void 0,children:g.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:r.includes(n)?(0,t.formatMeasure)(e[n],m(n)?.format,m(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]})})}function W(e){switch(e){case`line`:return`line`;case`area`:return`area`;case`pie`:return`pie`;case`donut`:return`donut`;case`radar`:return`radar`;case`scatter`:return`scatter`;default:return`bar`}}function G(e){let[,r]=n.useReducer(e=>e+1,0);return n.useEffect(()=>{if(t.ComponentRegistry.get(e))return;let n=typeof t.ComponentRegistry.subscribe==`function`?t.ComponentRegistry.subscribe(()=>{t.ComponentRegistry.get(e)&&r()}):void 0,i=t.ComponentRegistry.loadLazy?.(e);return i&&typeof i.then==`function`&&i.then(()=>r()).catch(()=>{}),n},[e]),t.ComponentRegistry.get(e)}function K({dataset:e,chart:t,runtimeFilter:n,dataSource:r}){let i=typeof t.xAxis==`string`?t.xAxis:``,a=typeof t.yAxis==`string`?t.yAxis:``,c=R(e,i?[i]:[],a?[a]:[],n,r),l=G(`chart`);if(!i||!a)return null;if(c.status===`loading`||c.status===`idle`)return(0,o.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,o.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin`}),` Loading chart…`]});if(c.status===`error`||c.rows.length===0||!l)return null;let u=typeof t.title==`string`?t.title:void 0;return(0,o.jsxs)(`div`,{className:`rounded-md border bg-card p-3`,"data-testid":`dataset-report-chart`,children:[u?(0,o.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:u}):null,(0,o.jsx)(l,{schema:{chartType:W(t.type),data:c.rows,xAxisKey:i,series:[{dataKey:a}],height:typeof t.height==`number`?t.height:280,isAnimationActive:!1}})]})}function q(e,t){return e.map(e=>String(t[e]??`∅`)).join(``)}function J(e,n){return e.map(e=>(0,t.formatDimensionValue)(n[e])).join(` / `)}function Y({dataset:e,rows:r,columnsAcross:i,values:a,runtimeFilter:s,dataSource:c,onDrill:u}){let d=R(e,[...r,...i],a,s,c,[r,i,[]]),f=(0,l.useSafeTranslate)(),{fieldLabel:p}=(0,l.useSafeFieldLabel)(),m=n.useMemo(()=>{if(d.status!==`ok`)return null;let e=[],t=[],n=new Set,a=new Set,o=new Map;return d.rows.forEach((s,c)=>{let l=q(r,s),u=q(i,s);if(!n.has(l)){n.add(l);let t={};for(let e of r)t[e]=s[e];e.push({id:l,label:J(r,s),key:t})}if(!a.has(u)){a.add(u);let e={};for(let t of i)e[t]=s[t];t.push({id:u,label:J(i,s),key:e})}o.set(`${l} ${u}`,{row:s,index:c})}),{rowHeaders:e,colHeaders:t,cells:o}},[d,r,i]);if(a.length===0)return(0,o.jsx)(z,{dataset:e});if(d.status===`loading`||d.status===`idle`)return(0,o.jsx)(B,{status:d.status});if(d.status===`error`)return(0,o.jsx)(B,{status:`error`,error:d.error});if(!m||m.rowHeaders.length===0)return(0,o.jsx)(V,{});let{measureField:h,headerLabel:g}=(0,t.buildDatasetFieldHelpers)(d.fields,d.object,p),_=f(`report.total`,`Total`),v=!!u,y=d.dimensionFields?[...r,...i].filter(e=>e in d.dimensionFields):[],b=(n,r,i)=>{let a=d.object&&d.dimensionFields&&y.length>0?(0,t.buildDatasetDrillFilter)(d.drillRawRows?.[i],y,d.dimensionFields,s):void 0;u({dataset:e,groupKey:{...n,...r},runtimeFilter:s,object:d.object,objectFilter:a})},x=m.colHeaders.flatMap(e=>a.map(t=>({col:e,measure:t,header:a.length===1?e.label:`${e.label} · ${g(t)}`}))),S=e=>d.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,C=new Map;for(let e of S(r)??[])C.set(q(r,e),e);let w=new Map;for(let e of S(i)??[])w.set(q(i,e),e);let T=S([])?.[0],E=C.size>0,D=w.size>0;return(0,o.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,"data-testid":`dataset-matrix`,children:(0,o.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,o.jsx)(`thead`,{className:`bg-muted/40`,children:(0,o.jsxs)(`tr`,{children:[r.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e)),x.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:a.length===1?_:`${_} · ${g(e)}`},`total-${e}`))]})}),(0,o.jsxs)(`tbody`,{children:[m.rowHeaders.map(e=>(0,o.jsxs)(`tr`,{className:`border-t`,children:[r.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:(0,t.formatDimensionValue)(e.key[n])},n)),x.map(n=>{let r=m.cells.get(`${e.id} ${n.col.id}`),i=r?.row[n.measure],a=v&&r!=null;return(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap${a?` ${H}`:``}`,"data-testid":a?`dataset-drill-cell`:void 0,onClick:a?()=>b(e.key,n.col.key,r.index):void 0,children:(0,t.formatMeasure)(i,h(n.measure)?.format,h(n.measure)?.currency)},`${n.col.id}-${n.measure}`)}),E&&a.map(n=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:(0,t.formatMeasure)(C.get(e.id)?.[n],h(n)?.format,h(n)?.currency)},`total-${n}`))]},e.id)),D&&(0,o.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[r.length>0&&(0,o.jsx)(`td`,{colSpan:r.length,className:`px-2 py-1 whitespace-nowrap`,children:_}),x.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:(0,t.formatMeasure)(w.get(e.col.id)?.[e.measure],h(e.measure)?.format,h(e.measure)?.currency)},`${e.col.id}-${e.measure}`)),E&&a.map(e=>(0,o.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:(0,t.formatMeasure)(T?.[e],h(e)?.format,h(e)?.currency)},`grand-${e}`))]})]})]})})}var X=({report:e,dataSource:t,runtimeFilter:n,onDrill:r,className:i})=>{let a=P(e.runtimeFilter??e.filter,n),s=e.drilldown===!1?void 0:r;if(e.type===`joined`&&Array.isArray(e.blocks))return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=P(a,e.runtimeFilter??e.filter),i=L(e.columns),c=e.type===`matrix`&&i.length>0?(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:i,values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s}):(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:r,dataSource:t,onDrill:s});return(0,o.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,o.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,o.jsx)(`h3`,{className:`text-sm font-semibold`,children:I(e.label,e.name??`Block ${n+1}`)}),e.description?(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:I(e.description,``)}):null]}),c]},e.name??`block-${n}`)})});let c=L(e.columns);if(e.type===`matrix`&&c.length>0)return(0,o.jsx)(`div`,{className:i,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,o.jsx)(Y,{dataset:String(e.dataset??``),rows:L(e.rows),columnsAcross:c,values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})});let l=e.chart&&typeof e.chart==`object`&&e.chart.type?e.chart:null;return(0,o.jsxs)(`div`,{className:`${i??``} flex flex-col gap-3`,"data-testid":`dataset-report`,"data-report-name":e.name,children:[l?(0,o.jsx)(K,{dataset:String(e.dataset??``),chart:l,runtimeFilter:a,dataSource:t}):null,(0,o.jsx)(U,{dataset:String(e.dataset??``),rows:L(e.rows),values:L(e.values),runtimeFilter:a,dataSource:t,onDrill:s})]})},Z=e=>{let{dataSource:t,rows:a,runtimeFilter:s,onDrill:c,className:l}=e,u=n.useContext(i.SchemaRendererContext),d=t??u?.dataSource,f=e.schema;return f&&typeof f==`object`&&f.type===`spec-report`&&f.report&&typeof f.report==`object`&&(f=f.report),F(f)?(0,o.jsx)(X,{report:f,dataSource:d,runtimeFilter:s,onDrill:c,className:l}):(0,r.isSpecReport)(f)?(0,o.jsx)(`div`,{className:l,"data-testid":`report-presentation-bridge`,children:(0,o.jsx)(N,{schema:{type:`report-viewer`,report:(0,r.specReportToPresentation)(f),data:a??[],showToolbar:!1}})}):(0,o.jsx)(_,{schema:f})};async function Q(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return C(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function $(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(te),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return ne(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=ie(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}oe(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
+ `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ee(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Q(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function te(e){return{name:e.name,header:e.label||e.name}}function ne(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,re(t)):ae(String(e))}function re(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function ie(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function ae(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function oe(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,Z,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`spec-report`,Z,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`dataset`,type:`string`,label:`Dataset`},{name:`type`,type:`string`,label:`Report Type`}]}),t.ComponentRegistry.register(`report-viewer`,N,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),e.DatasetReportRenderer=X,e.LegacyReportRenderer=_,e.ReportRenderer=Z,e.ReportViewer=N,e.createScheduleTrigger=ee,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=$,e.exportReport=C,e.exportWithLiveData=Q,e.formatValue=k,e.isDatasetReport=F,e.mergeFilters=P});
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Combine two `FilterCondition` objects via `$and`, dropping empty ones.
3
+ *
4
+ * The scope-filter combinator shared by the dataset report path: a report's
5
+ * own `runtimeFilter`/`filter` is intersected with a host-supplied runtime
6
+ * filter (and, for joined reports, the container filter is folded into every
7
+ * block). Returns `undefined` when nothing meaningful remains so callers can
8
+ * omit the key entirely.
9
+ */
10
+ export declare function mergeFilters(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-report",
3
- "version": "6.2.3",
3
+ "version": "7.1.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -20,29 +20,29 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "clsx": "^2.1.1",
23
- "lucide-react": "^1.16.0",
24
- "react-i18next": "^17.0.7",
23
+ "lucide-react": "^1.21.0",
24
+ "react-i18next": "^17.0.8",
25
25
  "tailwind-merge": "^3.6.0",
26
- "@object-ui/components": "6.2.3",
27
- "@object-ui/core": "6.2.3",
28
- "@object-ui/fields": "6.2.3",
29
- "@object-ui/i18n": "6.2.3",
30
- "@object-ui/plugin-grid": "6.2.3",
31
- "@object-ui/react": "6.2.3",
32
- "@object-ui/types": "6.2.3"
26
+ "@object-ui/components": "7.1.0",
27
+ "@object-ui/core": "7.1.0",
28
+ "@object-ui/fields": "7.1.0",
29
+ "@object-ui/i18n": "7.1.0",
30
+ "@object-ui/plugin-grid": "7.1.0",
31
+ "@object-ui/react": "7.1.0",
32
+ "@object-ui/types": "7.1.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^18.0.0",
36
36
  "react-dom": "^18.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/node": "^25.9.1",
40
- "@types/react": "19.2.15",
39
+ "@types/node": "^26.0.0",
40
+ "@types/react": "19.2.17",
41
41
  "@types/react-dom": "19.2.3",
42
42
  "@vitejs/plugin-react": "^6.0.2",
43
- "vite": "^8.0.14",
44
- "vite-plugin-dts": "^5.0.1",
45
- "vitest": "^4.1.7"
43
+ "vite": "^8.0.16",
44
+ "vite-plugin-dts": "^5.0.2",
45
+ "vitest": "^4.1.9"
46
46
  },
47
47
  "description": "Report plugin for Object UI — schema-driven pivot tables, grouped aggregations and printable report layouts",
48
48
  "keywords": [
@@ -1,8 +0,0 @@
1
- import { AvailableField, Translator } from './editorTypes';
2
- export declare function ChartConfig({ availableFields, columns, value, onChange, t, }: {
3
- availableFields: AvailableField[];
4
- columns: ColumnDraft[];
5
- value: any;
6
- onChange: (v: any) => void;
7
- t: Translator;
8
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +0,0 @@
1
- import { AvailableField, Translator } from './editorTypes';
2
- type ColumnDraft = {
3
- field: string;
4
- label?: string;
5
- type?: string;
6
- aggregate?: string;
7
- format?: string;
8
- };
9
- export declare function normalizeColumns(value: unknown): ColumnDraft[];
10
- export declare function ColumnsEditor({ availableFields, value, onChange, t, }: {
11
- availableFields: AvailableField[];
12
- value: any;
13
- onChange: (v: any) => void;
14
- t: Translator;
15
- }): import("react/jsx-runtime").JSX.Element;
16
- export {};
@@ -1,36 +0,0 @@
1
- import { AvailableField, Translator } from './editorTypes';
2
- /**
3
- * ObjectUI
4
- * Copyright (c) 2024-present ObjectStack Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
- import * as React from 'react';
10
- export interface FieldPickerDialogProps {
11
- availableFields: AvailableField[];
12
- /** Field values already selected (will be disabled in the picker). */
13
- selectedValues: string[];
14
- /** Invoked with the *new* field values picked (does not include already-selected). */
15
- onAdd: (fieldValues: string[]) => void;
16
- t: Translator;
17
- /** Trigger button label override. */
18
- triggerLabel?: string;
19
- /** Dialog title override. */
20
- title?: string;
21
- /** Dialog description override. */
22
- description?: string;
23
- /** Test-id namespace for buttons / inputs. */
24
- testIdPrefix?: string;
25
- /** Allow only a single selection at a time (e.g. picking a single grouping field). */
26
- singleSelect?: boolean;
27
- /** When true (+singleSelect), clicking a row immediately commits and closes. */
28
- commitOnSelect?: boolean;
29
- /** Disable the trigger button. */
30
- disabled?: boolean;
31
- /** Extra trigger className. */
32
- triggerClassName?: string;
33
- /** Custom trigger element (e.g. a button showing the currently picked field). */
34
- trigger?: React.ReactElement;
35
- }
36
- export declare function FieldPickerDialog({ availableFields, selectedValues, onAdd, t, triggerLabel, title, description, testIdPrefix, singleSelect, commitOnSelect, disabled, triggerClassName, trigger, }: FieldPickerDialogProps): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +0,0 @@
1
- import { AvailableField, Translator } from './editorTypes';
2
- export declare function GroupingsBuilder({ availableFields, value, onChange, t, testIdPrefix, }: {
3
- availableFields: AvailableField[];
4
- value: any;
5
- onChange: (v: any) => void;
6
- t: Translator;
7
- testIdPrefix?: string;
8
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,31 +0,0 @@
1
- import { JoinedReportBlock } from '../../types/src';
2
- import { AvailableField } from './ReportConfigPanel';
3
- type Translator = (key: string, fallback?: string) => string;
4
- export interface JoinedBlocksEditorProps {
5
- value: unknown;
6
- onChange: (next: JoinedReportBlock[]) => void;
7
- /** Default field list — used when a block has no `objectName` override. */
8
- availableFields: AvailableField[];
9
- /**
10
- * Optional resolver returning the field list for a given object name.
11
- * Used to source the correct fields when a block overrides `objectName`.
12
- * If omitted or returns `undefined`, the block uses `availableFields`.
13
- */
14
- getFieldsForObject?: (objectName: string | undefined) => AvailableField[] | undefined;
15
- /**
16
- * The container report's `objectName`. When a block omits its own
17
- * `objectName`, the editor resolves fields against this name (when a
18
- * resolver is provided) so the field list matches the runtime behaviour
19
- * of `JoinedReportRenderer` (which inherits the container's object).
20
- */
21
- containerObjectName?: string;
22
- t: Translator;
23
- }
24
- export declare function JoinedBlocksEditor({ value, onChange, availableFields, getFieldsForObject, containerObjectName, t, }: JoinedBlocksEditorProps): import("react/jsx-runtime").JSX.Element;
25
- /**
26
- * Static validation for the `blocks` array of a joined report.
27
- * Returns an array of i18n keys (already-translated strings) describing problems,
28
- * suitable for direct rendering in the validation banner.
29
- */
30
- export declare function validateJoinedBlocks(blocks: unknown, t: Translator): string[];
31
- export {};
@@ -1,47 +0,0 @@
1
- import { ActionRunner } from '../../core/src';
2
- import { DataSource, JoinedReportBlock, JoinedSpecReport } from '../../types/src';
3
- import { DrillOpenIn, DrillView } from './drill';
4
- /**
5
- * JoinedReportRenderer
6
- *
7
- * Renders a spec `Report` of `type: 'joined'` as a vertical stack of
8
- * self-contained `ReportRenderer` blocks. Each block is its own `SpecReport`
9
- * with its own data fetch, aggregations, and drill — they are independent
10
- * widgets composed on a single page.
11
- *
12
- * Filter inheritance
13
- * ------------------
14
- * The outer (joined) report can carry a top-level `filter`. It is merged into
15
- * each block's `filter` as a logical `$and`, so a report-wide constraint
16
- * (e.g. "owner = me") propagates to every block without repetition. Block
17
- * filters keep precedence on key collisions because they are by convention
18
- * the more specific constraint.
19
- *
20
- * Drill & runtime propagation
21
- * ---------------------------
22
- * `dataSource`, `actionRunner`, `drillView`, `drillOpenIn` and `runtimeFilter`
23
- * flow uniformly into every block so any block's drill behaves identically to
24
- * a standalone report. Each block calls its own {@link useReportData} hook —
25
- * there is no shared cache, by design (blocks may query different objects).
26
- *
27
- * Layout
28
- * ------
29
- * Blocks render vertically. The block label/description renders above the
30
- * block content. We intentionally avoid imposing a column layout: composition
31
- * (e.g. a 2×2 grid of blocks) is a host concern handled by a parent layout
32
- * component.
33
- */
34
- import * as React from 'react';
35
- export interface JoinedReportRendererProps {
36
- report: JoinedSpecReport;
37
- dataSource?: DataSource;
38
- /** Runtime filter (e.g. global toolbar filter) merged into every block. */
39
- runtimeFilter?: Record<string, unknown>;
40
- actionRunner?: ActionRunner;
41
- drillView?: DrillView;
42
- drillOpenIn?: DrillOpenIn;
43
- className?: string;
44
- /** Override rendering of an individual block (advanced). */
45
- renderBlock?: (block: JoinedReportBlock, index: number, content: React.ReactNode) => React.ReactNode;
46
- }
47
- export declare const JoinedReportRenderer: React.FC<JoinedReportRendererProps>;