@object-ui/plugin-report 0.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1001 -491
- package/dist/index.umd.cjs +62 -4
- package/dist/plugin-report/src/LiveReportExporter.d.ts +105 -0
- package/dist/{src → plugin-report/src}/ReportBuilder.d.ts +0 -1
- package/dist/plugin-report/src/ReportExportEngine.d.ts +30 -0
- package/dist/{src → plugin-report/src}/ReportRenderer.d.ts +0 -1
- package/dist/{src → plugin-report/src}/ReportViewer.d.ts +2 -1
- package/dist/plugin-report/src/ScheduleConfig.d.ts +8 -0
- package/dist/plugin-report/src/index.d.ts +9 -0
- package/package.json +15 -15
- package/dist/src/ReportBuilder.d.ts.map +0 -1
- package/dist/src/ReportRenderer.d.ts.map +0 -1
- package/dist/src/ReportViewer.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +0 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(C,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("@object-ui/core"),require("react"),require("@object-ui/components"),require("@object-ui/react"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","@object-ui/core","react","@object-ui/components","@object-ui/react","lucide-react"],_):(C=typeof globalThis<"u"?globalThis:C||self,_(C.ObjectUIPluginReport={},C.ObjectUICore,C.React,C.ObjectUIComponents,C.ObjectUIReact,C.lucideReact))})(this,function(C,_,B,r,ne,w){"use strict";var Q={exports:{}},U={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ie;function ge(){if(ie)return U;ie=1;var s=Symbol.for("react.transitional.element"),d=Symbol.for("react.fragment");function a(c,u,p){var j=null;if(p!==void 0&&(j=""+p),u.key!==void 0&&(j=""+u.key),"key"in u){p={};for(var i in u)i!=="key"&&(p[i]=u[i])}else p=u;return u=p.ref,{$$typeof:s,type:c,key:j,ref:u!==void 0?u:null,props:p}}return U.Fragment=d,U.jsx=a,U.jsxs=a,U}var G={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,67 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var de;function ye(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){function s(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===ae?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case N:return"Fragment";case g:return"Profiler";case k:return"StrictMode";case P:return"Suspense";case V:return"SuspenseList";case W:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case v:return"Portal";case D:return t.displayName||"Context";case L:return(t._context.displayName||"Context")+".Consumer";case I:var f=t.render;return t=t.displayName,t||(t=f.displayName||f.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Y:return f=t.displayName||null,f!==null?f:s(t.type)||"Memo";case z:f=t._payload,t=t._init;try{return s(t(f))}catch{}}return null}function d(t){return""+t}function a(t){try{d(t);var f=!1}catch{f=!0}if(f){f=console;var T=f.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return T.call(f,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),d(t)}}function c(t){if(t===N)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===z)return"<...>";try{var f=s(t);return f?"<"+f+">":"<...>"}catch{return"<...>"}}function u(){var t=$.A;return t===null?null:t.getOwner()}function p(){return Error("react-stack-top-frame")}function j(t){if(X.call(t,"key")){var f=Object.getOwnPropertyDescriptor(t,"key").get;if(f&&f.isReactWarning)return!1}return t.key!==void 0}function i(t,f){function T(){o||(o=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",f))}T.isReactWarning=!0,Object.defineProperty(t,"key",{get:T,configurable:!0})}function x(){var t=s(this.type);return h[t]||(h[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function n(t,f,T,R,Z,se){var F=T.ref;return t={$$typeof:m,type:t,key:f,props:T,_owner:R},(F!==void 0?F:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:x}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:se}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function b(t,f,T,R,Z,se){var F=f.children;if(F!==void 0)if(R)if(re(F)){for(R=0;R<F.length;R++)y(F[R]);Object.freeze&&Object.freeze(F)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else y(F);if(X.call(f,"key")){F=s(t);var M=Object.keys(f).filter(function(Fe){return Fe!=="key"});R=0<M.length?"{key: someKey, "+M.join(": ..., ")+": ...}":"{key: someKey}",H[F+R]||(M=0<M.length?"{"+M.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,b,N,G,N),W[N+b]=!0)}if(N=null,p!==void 0&&(h(p),N=""+p),A(i)&&(h(i.key),N=""+i.key),"key"in i){p={};for(var re in i)re!=="key"&&(p[re]=i[re])}else p=i;return N&&d(p,typeof r=="function"?r.displayName||r.name||"Unknown":r),j(r,N,p,m(),q,ee)}function w(r){n(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===D&&(r._payload.status==="fulfilled"?n(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function n(r){return typeof r=="object"&&r!==null&&r.$$typeof===_}var C=I,_=Symbol.for("react.transitional.element"),E=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),P=Symbol.for("react.consumer"),B=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),L=Symbol.for("react.suspense"),X=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),D=Symbol.for("react.lazy"),U=Symbol.for("react.activity"),K=Symbol.for("react.client.reference"),O=C.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H=Object.prototype.hasOwnProperty,Q=Array.isArray,t=console.createTask?console.createTask:function(){return null};C={react_stack_bottom_frame:function(r){return r()}};var a,l={},T=C.react_stack_bottom_frame.bind(C,y)(),V=t(u(y)),W={};Y.Fragment=c,Y.jsx=function(r,i,p){var b=1e4>O.recentlyCreatedOwnerStacks++;return f(r,i,p,!1,b?Error("react-stack-top-frame"):T,b?t(u(r)):V)},Y.jsxs=function(r,i,p){var b=1e4>O.recentlyCreatedOwnerStacks++;return f(r,i,p,!0,b?Error("react-stack-top-frame"):T,b?t(u(r)):V)}}()),Y}process.env.NODE_ENV==="production"?$.exports=ie():$.exports=de();var e=$.exports;const le=({schema:v})=>{var x;const{title:o,description:h,data:u,columns:m}=v;(x=v.chart)!=null&&x.type;const y=!!v.chart,d=!(process.env.NODE_ENV==="test");return e.jsxs(s.Card,{className:`h-full flex flex-col ${v.className||""}`,children:[e.jsxs(s.CardHeader,{children:[o&&e.jsx(s.CardTitle,{children:o}),h&&e.jsx(s.CardDescription,{children:h})]}),e.jsxs(s.CardContent,{className:"flex-1 overflow-auto space-y-4",children:[y&&(()=>{var w;const j=(w=v.chart)==null?void 0:w.type;let f=j?S.ComponentRegistry.get(j):null;return f||(f=S.ComponentRegistry.get("chart")),f?e.jsx("div",{className:"min-h-[300px] border rounded-md p-4 bg-white/50",children:e.jsx(f,{schema:{...v.chart,data:v.chart.data||u}})}):e.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: ",j||"chart"]})})(),u&&u.length>0&&e.jsx("div",{className:"border rounded-md",children:(()=>{const j=d?S.ComponentRegistry.get("aggrid")||S.ComponentRegistry.get("table"):null;return j?e.jsx(j,{schema:{type:"aggrid",rowData:u,columnDefs:m,domLayout:"autoHeight"}}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs uppercase bg-gray-50",children:e.jsx("tr",{children:m==null?void 0:m.map(f=>e.jsx("th",{className:"px-6 py-3",children:f.headerName||f.label||f.field},f.field))})}),e.jsx("tbody",{children:u.map((f,w)=>e.jsx("tr",{className:"bg-white border-b",children:m==null?void 0:m.map(n=>e.jsx("td",{className:"px-6 py-4",children:f[n.field]},n.field))},w))})]})})})()})]})]})},J=({schema:v})=>{var f,w;const{report:o,data:h,showToolbar:u=!0,allowExport:m=!0,allowPrint:y=!0,loading:A=!1}=v,d=n=>{console.log("Export report as:",n),alert(`Export to ${n.toUpperCase()} - Feature coming soon!`)},x=()=>{console.log("Print report"),window.print()},j=()=>{console.log("Refresh report")};return o?e.jsxs("div",{className:"space-y-4",children:[u&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:o.title}),o.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:o.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o.refreshInterval&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:j,children:[e.jsx(g.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),y&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:x,children:[e.jsx(g.Printer,{className:"h-4 w-4 mr-2"}),"Print"]}),m&&o.showExportButtons&&e.jsx(e.Fragment,{children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>d(o.defaultExportFormat||"pdf"),children:[e.jsx(g.Download,{className:"h-4 w-4 mr-2"}),"Export"]})})]})]}),e.jsxs(s.Card,{children:[e.jsxs(s.CardHeader,{children:[!u&&o.title&&e.jsx(s.CardTitle,{children:o.title}),!u&&o.description&&e.jsx(s.CardDescription,{children:o.description})]}),e.jsxs(s.CardContent,{className:"space-y-6",children:[A&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading report data..."}),!A&&((f=o.sections)==null?void 0:f.map((n,C)=>{var _,E;return n.visible===!1?null:e.jsxs("div",{className:"space-y-2",children:[n.title&&e.jsx("h3",{className:"text-lg font-semibold border-b pb-2",children:n.title}),n.type==="header"&&n.title&&e.jsx("div",{className:"text-2xl font-bold py-4",children:n.title}),n.type==="summary"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:(_=o.fields)==null?void 0:_.filter(c=>c.showInSummary).map((c,k)=>e.jsx(s.Card,{children:e.jsxs(s.CardContent,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:c.label||c.name}),e.jsxs("div",{className:"text-2xl font-bold",children:[c.aggregation==="count"&&(h==null?void 0:h.length),c.aggregation==="sum"&&(h==null?void 0:h.reduce((F,P)=>F+(P[c.name]||0),0))]})]})},k))}),n.type==="chart"&&n.chart&&e.jsx("div",{className:"min-h-[300px]",children:(()=>{let c=n.chart.type;const k=!!n.chart.chartType;!c&&k&&(c="chart"),c&&!!S.ComponentRegistry.get(c)||(c="chart");const B=c==="chart"?{xAxisKey:n.chart.xAxisKey||n.chart.xAxisField||"name",series:n.chart.series||(n.chart.yAxisFields?n.chart.yAxisFields.map(L=>({dataKey:L})):[]),chartType:n.chart.chartType||"bar"}:{},M={...n.chart,type:c,...B,data:h||n.chart.data,className:n.chart.className||"w-full h-[350px]"};return e.jsx(se.SchemaRenderer,{schema:M})})()}),n.type==="table"&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(E=n.columns)==null?void 0:E.map((c,k)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:c.label||c.name},k))})}),e.jsx("tbody",{children:h==null?void 0:h.map((c,k)=>{var F;return e.jsx("tr",{className:"border-t",children:(F=n.columns)==null?void 0:F.map((P,B)=>e.jsx("td",{className:"px-4 py-2",children:c[P.name]},B))},k)})})]})}),n.type==="text"&&n.text&&e.jsx("div",{className:"prose max-w-none",children:e.jsx("p",{children:n.text})}),n.type==="page-break"&&e.jsx("div",{className:"border-t-2 border-dashed my-8 print:page-break-after-always"}),n.content&&e.jsx(se.SchemaRenderer,{schema:n.content})]},C)})),!o.sections&&h&&h.length>0&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(w=o.fields)==null?void 0:w.map((n,C)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:n.label||n.name},C))})}),e.jsx("tbody",{children:h.map((n,C)=>{var _;return e.jsx("tr",{className:"border-t",children:(_=o.fields)==null?void 0:_.map((E,c)=>e.jsx("td",{className:"px-4 py-2",children:n[E.name]},c))},C)})})]})})]})]})]}):e.jsx(s.Card,{children:e.jsx(s.CardContent,{className:"p-8 text-center text-muted-foreground",children:"No report to display"})})},ne=({schema:v})=>{const{report:o,dataSources:h=[],availableFields:u=[],showPreview:m=!0,onSave:y,onCancel:A}=v,[d,x]=I.useState(o||{type:"report",title:"New Report",fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[j,f]=I.useState(d.fields||[]),[w,n]=I.useState(d.filters||[]),[C,_]=I.useState(d.groupBy||[]),[E,c]=I.useState(d.sections||[]),k=()=>{if(u.length>0&&j.length<u.length){const t=u.find(a=>!j.some(l=>l.name===a.name));if(t){const a=[...j,t];f(a),x({...d,fields:a})}}},F=t=>{const a=j.filter((l,T)=>T!==t);f(a),x({...d,fields:a})},P=(t,a)=>{const l=[...j];l[t]=a,f(l),x({...d,fields:l})},B=()=>{var l;const t={field:((l=u[0])==null?void 0:l.name)||"",operator:"equals",value:""},a=[...w,t];n(a),x({...d,filters:a})},M=t=>{const a=w.filter((l,T)=>T!==t);n(a),x({...d,filters:a})},L=(t,a)=>{const l=[...w];l[t]=a,n(l),x({...d,filters:l})},X=()=>{var l;const t={field:((l=u[0])==null?void 0:l.name)||"",sort:"asc"},a=[...C,t];_(a),x({...d,groupBy:a})},Z=t=>{const a=C.filter((l,T)=>T!==t);_(a),x({...d,groupBy:a})},D=(t,a)=>{const l=[...C];l[t]=a,_(l),x({...d,groupBy:l})},U=t=>{const a={type:t,title:`New ${t} Section`},l=[...E,a];c(l),x({...d,sections:l})},K=t=>{const a=E.filter((l,T)=>T!==t);c(a),x({...d,sections:a})},O=(t,a)=>{const l=[...E];l[t]=a,c(l),x({...d,sections:l})},H=()=>{console.log("Saving report:",d),y&&alert("Report saved! (Handler: "+y+")")},Q=()=>{console.log("Canceling report builder")};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(s.Card,{children:[e.jsxs(s.CardHeader,{children:[e.jsx(s.CardTitle,{children:"Report Builder"}),e.jsx(s.CardDescription,{children:"Configure your report settings, fields, filters, and sections"})]}),e.jsxs(s.CardContent,{children:[e.jsxs(s.Tabs,{defaultValue:"basic",className:"w-full",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-5",children:[e.jsxs(s.TabsTrigger,{value:"basic",children:[e.jsx(g.Settings,{className:"h-4 w-4 mr-2"}),"Basic"]}),e.jsxs(s.TabsTrigger,{value:"fields",children:[e.jsx(g.Layers,{className:"h-4 w-4 mr-2"}),"Fields"]}),e.jsxs(s.TabsTrigger,{value:"filters",children:[e.jsx(g.Filter,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(s.TabsTrigger,{value:"grouping",children:[e.jsx(g.Layers,{className:"h-4 w-4 mr-2"}),"Group By"]}),e.jsxs(s.TabsTrigger,{value:"sections",children:[e.jsx(g.Layers,{className:"h-4 w-4 mr-2"}),"Sections"]})]}),e.jsx(s.TabsContent,{value:"basic",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"report-title",children:"Report Title"}),e.jsx(s.Input,{id:"report-title",value:d.title||"",onChange:t=>x({...d,title:t.target.value}),placeholder:"Enter report title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"report-description",children:"Description"}),e.jsx(s.Input,{id:"report-description",value:d.description||"",onChange:t=>x({...d,description:t.target.value}),placeholder:"Enter report description"})]}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Data Source"}),e.jsxs("select",{className:"w-full border rounded-md p-2",children:[e.jsx("option",{value:"",children:"Select a data source"}),h.map((t,a)=>e.jsxs("option",{value:a,children:["Data Source ",a+1]},a))]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Export Options"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:d.showExportButtons||!1,onChange:t=>x({...d,showExportButtons:t.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Export Buttons"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:d.showPrintButton||!1,onChange:t=>x({...d,showPrintButton:t.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Print Button"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"export-format",children:"Default Export Format"}),e.jsxs("select",{id:"export-format",className:"w-full border rounded-md p-2",value:d.defaultExportFormat||"pdf",onChange:t=>x({...d,defaultExportFormat:t.target.value}),children:[e.jsx("option",{value:"pdf",children:"PDF"}),e.jsx("option",{value:"excel",children:"Excel"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"html",children:"HTML"})]})]})]})}),e.jsxs(s.TabsContent,{value:"fields",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Fields"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:k,disabled:j.length>=u.length,children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Add Field"]})]}),e.jsxs("div",{className:"space-y-2",children:[j.map((t,a)=>e.jsx("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field Name"}),e.jsx("div",{className:"text-sm font-medium",children:t.name})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Label"}),e.jsx(s.Input,{className:"h-8 text-sm",value:t.label||t.name,onChange:l=>P(a,{...t,label:l.target.value})})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Aggregation"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:t.aggregation||"",onChange:l=>P(a,{...t,aggregation:l.target.value}),children:[e.jsx("option",{value:"",children:"None"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsx("div",{className:"flex items-end justify-end",children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>F(a),children:e.jsx(g.Trash2,{className:"h-4 w-4"})})})]})},a)),j.length===0&&e.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.'})]})]}),e.jsxs(s.TabsContent,{value:"filters",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Filters"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:B,children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Add Filter"]})]}),e.jsxs("div",{className:"space-y-2",children:[w.map((t,a)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:t.field,onChange:l=>L(a,{...t,field:l.target.value}),children:u.map((l,T)=>e.jsx("option",{value:l.name,children:l.label||l.name},T))})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Operator"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:t.operator,onChange:l=>L(a,{...t,operator:l.target.value}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"gt",children:"Greater Than"}),e.jsx("option",{value:"lt",children:"Less Than"}),e.jsx("option",{value:"between",children:"Between"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Value"}),e.jsx(s.Input,{className:"h-8 text-sm",value:String(t.value),onChange:l=>L(a,{...t,value:l.target.value})})]})]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>M(a),children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]},a)),w.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No filters defined."})]})]}),e.jsxs(s.TabsContent,{value:"grouping",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Grouping Rules"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:X,children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Add Group"]})]}),e.jsxs("div",{className:"space-y-2",children:[C.map((t,a)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:t.field,onChange:l=>D(a,{...t,field:l.target.value}),children:u.map((l,T)=>e.jsx("option",{value:l.name,children:l.label||l.name},T))})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Sort Order"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:t.sort||"asc",onChange:l=>D(a,{...t,sort:l.target.value}),children:[e.jsx("option",{value:"asc",children:"Ascending"}),e.jsx("option",{value:"desc",children:"Descending"})]})]})]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>Z(a),children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]},a)),C.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No grouping rules applied."})]})]}),e.jsxs(s.TabsContent,{value:"sections",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Sections"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>U("header"),children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Header"]}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>U("chart"),children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>U("table"),children:[e.jsx(g.Plus,{className:"h-4 w-4 mr-2"}),"Table"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[E.map((t,a)=>{var l,T,V,W;return e.jsxs("div",{className:"p-3 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx("div",{className:"text-xs bg-muted px-2 py-0.5 rounded uppercase",children:t.type}),t.title]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>K(a),children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Title"}),e.jsx(s.Input,{className:"h-8 text-sm",value:t.title||"",onChange:r=>O(a,{...t,title:r.target.value})})]}),t.type==="text"&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(s.Label,{className:"text-xs",children:"Content"}),e.jsx(s.Input,{className:"h-8 text-sm",value:t.text||"",onChange:r=>O(a,{...t,text:r.target.value})})]}),t.type==="chart"&&e.jsxs("div",{className:"col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(s.Label,{className:"text-xs font-semibold",children:"Chart Configuration"})}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Chart Type"}),e.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:((l=t.chart)==null?void 0:l.chartType)||"bar",onChange:r=>O(a,{...t,chart:{...t.chart,type:"chart",chartType:r.target.value}}),children:[e.jsx("option",{value:"bar",children:"Bar"}),e.jsx("option",{value:"line",children:"Line"}),e.jsx("option",{value:"area",children:"Area"}),e.jsx("option",{value:"pie",children:"Pie"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"X-Axis Field"}),e.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:((T=t.chart)==null?void 0:T.xAxisField)||"",onChange:r=>O(a,{...t,chart:{...t.chart,type:"chart",xAxisField:r.target.value}}),children:[e.jsx("option",{value:"",children:"Select Field..."}),u.map(r=>e.jsx("option",{value:r.name,children:r.label||r.name},r.name)),u.length===0&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"name",children:"Name"}),e.jsx("option",{value:"month",children:"Month"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(s.Label,{className:"text-xs",children:"Y-Axis Fields (comma separated)"}),e.jsx(s.Input,{className:"h-8 text-sm",placeholder:"e.g. value, count",value:((W=(V=t.chart)==null?void 0:V.yAxisFields)==null?void 0:W.join(", "))||"",onChange:r=>O(a,{...t,chart:{...t.chart,type:"chart",yAxisFields:r.target.value.split(",").map(i=>i.trim()).filter(Boolean)}})})]})]})]})]},a)}),E.length===0&&e.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."})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-6 pt-4 border-t",children:[e.jsx(s.Button,{variant:"outline",onClick:Q,children:"Cancel"}),e.jsxs(s.Button,{onClick:H,children:[e.jsx(g.Save,{className:"h-4 w-4 mr-2"}),"Save Report"]})]})]})]}),m&&e.jsxs(s.Card,{className:"mt-8 border-2 border-blue-100",children:[e.jsx(s.CardHeader,{className:"bg-blue-50/50",children:e.jsx(s.CardTitle,{className:"text-blue-900 text-sm uppercase tracking-wide",children:"Live Preview"})}),e.jsx(s.CardContent,{className:"pt-6",children:e.jsx(J,{schema:{type:"report-viewer",report:{...d,fields:j,filters:w,groupBy:C,sections:E},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"}]}})})]})]})};S.ComponentRegistry.register("report",le,{label:"Report",category:"Report",inputs:[{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"chart",type:"code",label:"Chart Configuration"}]}),S.ComponentRegistry.register("report-viewer",J,{label:"Report Viewer",category:"Report",inputs:[{name:"report",type:"code",label:"Report Definition"},{name:"showToolbar",type:"boolean",label:"Show Toolbar"}]}),S.ComponentRegistry.register("report-builder",ne,{label:"Report Builder",category:"Report",inputs:[{name:"report",type:"code",label:"Initial Report"}]}),R.ReportBuilder=ne,R.ReportRenderer=le,R.ReportViewer=J,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,R,F,M,F),H[F+R]=!0)}if(F=null,T!==void 0&&(a(T),F=""+T),j(f)&&(a(f.key),F=""+f.key),"key"in f){T={};for(var le in f)le!=="key"&&(T[le]=f[le])}else T=f;return F&&i(T,typeof t=="function"?t.displayName||t.name||"Unknown":t),n(t,F,T,u(),Z,se)}function y(t){E(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===z&&(t._payload.status==="fulfilled"?E(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function E(t){return typeof t=="object"&&t!==null&&t.$$typeof===m}var S=B,m=Symbol.for("react.transitional.element"),v=Symbol.for("react.portal"),N=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),L=Symbol.for("react.consumer"),D=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),V=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),W=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),$=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,re=Array.isArray,l=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(t){return t()}};var o,h={},A=S.react_stack_bottom_frame.bind(S,p)(),q=l(c(p)),H={};G.Fragment=N,G.jsx=function(t,f,T){var R=1e4>$.recentlyCreatedOwnerStacks++;return b(t,f,T,!1,R?Error("react-stack-top-frame"):A,R?l(c(t)):q)},G.jsxs=function(t,f,T){var R=1e4>$.recentlyCreatedOwnerStacks++;return b(t,f,T,!0,R?Error("react-stack-top-frame"):A,R?l(c(t)):q)}}()),G}process.env.NODE_ENV==="production"?Q.exports=ge():Q.exports=ye();var e=Q.exports;const ce=({schema:s})=>{var x;const{title:d,description:a,data:c,columns:u}=s;(x=s.chart)!=null&&x.type;const p=!!s.chart,i=!(process.env.NODE_ENV==="test");return e.jsxs(r.Card,{className:`h-full flex flex-col ${s.className||""}`,children:[e.jsxs(r.CardHeader,{children:[d&&e.jsx(r.CardTitle,{children:d}),a&&e.jsx(r.CardDescription,{children:a})]}),e.jsxs(r.CardContent,{className:"flex-1 overflow-auto space-y-4",children:[p&&(()=>{var y;const n=(y=s.chart)==null?void 0:y.type;let b=n?_.ComponentRegistry.get(n):null;return b||(b=_.ComponentRegistry.get("chart")),b?e.jsx("div",{className:"min-h-[300px] border rounded-md p-4 bg-white/50",children:e.jsx(b,{schema:{...s.chart,data:s.chart.data||c}})}):e.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"]})})(),c&&c.length>0&&e.jsx("div",{className:"border rounded-md",children:(()=>{const n=i?_.ComponentRegistry.get("aggrid")||_.ComponentRegistry.get("table"):null;return n?e.jsx(n,{schema:{type:"aggrid",rowData:c,columnDefs:u,domLayout:"autoHeight"}}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs uppercase bg-gray-50",children:e.jsx("tr",{children:u==null?void 0:u.map(b=>e.jsx("th",{className:"px-6 py-3",children:b.headerName||b.label||b.field},b.field))})}),e.jsx("tbody",{children:c.map((b,y)=>e.jsx("tr",{className:"bg-white border-b",children:u==null?void 0:u.map(E=>e.jsx("td",{className:"px-6 py-4",children:b[E.field]},E.field))},y))})]})})})()})]})]})};function oe(s,d,a){const c=s.fields||[],u=c.map(i=>i.label||i.name),p=d.map(i=>c.map(x=>{let n=i[x.name];return n=xe(n),typeof n=="string"&&(n.includes(",")||n.includes('"')||n.includes(`
|
|
23
|
+
`))?`"${n.replace(/"/g,'""')}"`:n??""})),j=[...(a==null?void 0:a.includeHeaders)!==!1?[u.join(",")]:[],...p.map(i=>i.join(","))].join(`
|
|
24
|
+
`);J(j,(a==null?void 0:a.filename)||`${s.title||"report"}.csv`,"text/csv")}function ue(s,d,a){const c={title:s.title,description:s.description,generatedAt:new Date().toISOString(),data:d},u=JSON.stringify(c,null,2);J(u,(a==null?void 0:a.filename)||`${s.title||"report"}.json`,"application/json")}function K(s,d,a){const c=s.fields||[],u=fe(a==null?void 0:a.orientation),p=pe(a==null?void 0:a.pageSize),j=`<!DOCTYPE html>
|
|
25
|
+
<html>
|
|
26
|
+
<head>
|
|
27
|
+
<meta charset="utf-8">
|
|
28
|
+
<title>${O(s.title||"Report")}</title>
|
|
29
|
+
<style>
|
|
30
|
+
@page { size: ${p} ${u}; margin: 20mm; }
|
|
31
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
32
|
+
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
33
|
+
.description { color: #666; margin-bottom: 24px; }
|
|
34
|
+
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
35
|
+
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
36
|
+
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
37
|
+
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
38
|
+
tr:nth-child(even) { background: #fafafa; }
|
|
39
|
+
</style>
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
<h1>${O(s.title||"Report")}</h1>
|
|
43
|
+
${s.description?`<p class="description">${O(s.description)}</p>`:""}
|
|
44
|
+
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
45
|
+
<table>
|
|
46
|
+
<thead><tr>${c.map(i=>`<th>${O(i.label||i.name)}</th>`).join("")}</tr></thead>
|
|
47
|
+
<tbody>${d.map(i=>`<tr>${c.map(x=>`<td>${O(String(i[x.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
|
|
48
|
+
</table>
|
|
49
|
+
</body>
|
|
50
|
+
</html>`;J(j,(a==null?void 0:a.filename)||`${s.title||"report"}.html`,"text/html")}function he(s,d,a){var i;const c=s.fields||[],u=fe(a==null?void 0:a.orientation),p=pe(a==null?void 0:a.pageSize),j=window.open("","_blank");if(!j){const x={...a,filename:((i=a==null?void 0:a.filename)==null?void 0:i.replace(/\.pdf$/,".html"))||`${s.title||"report"}.html`};K(s,d,x);return}j.document.write(`<!DOCTYPE html>
|
|
51
|
+
<html>
|
|
52
|
+
<head>
|
|
53
|
+
<meta charset="utf-8">
|
|
54
|
+
<title>${O(s.title||"Report")}</title>
|
|
55
|
+
<style>
|
|
56
|
+
@page { size: ${p} ${u}; margin: 20mm; }
|
|
57
|
+
@media print { .no-print { display: none; } }
|
|
58
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
59
|
+
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
60
|
+
.description { color: #666; margin-bottom: 24px; }
|
|
61
|
+
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
62
|
+
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
63
|
+
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
64
|
+
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
65
|
+
tr:nth-child(even) { background: #fafafa; }
|
|
66
|
+
</style>
|
|
67
|
+
</head>
|
|
68
|
+
<body>
|
|
69
|
+
<h1>${O(s.title||"Report")}</h1>
|
|
70
|
+
${s.description?`<p class="description">${O(s.description)}</p>`:""}
|
|
71
|
+
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
72
|
+
<table>
|
|
73
|
+
<thead><tr>${c.map(x=>`<th>${O(x.label||x.name)}</th>`).join("")}</tr></thead>
|
|
74
|
+
<tbody>${d.map(x=>`<tr>${c.map(n=>`<td>${O(String(x[n.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
|
|
75
|
+
</table>
|
|
76
|
+
</body>
|
|
77
|
+
</html>`),j.document.close(),j.onload=()=>{j.print()}}function me(s,d,a){const c=s.fields||[],u=c.map(i=>i.label||i.name),p=d.map(i=>c.map(x=>{let n=i[x.name];return n=xe(n),typeof n=="string"&&(n.includes(",")||n.includes('"')||n.includes(`
|
|
78
|
+
`)||n.includes(" "))?`"${n.replace(/"/g,'""')}"`:n??""})),j="\uFEFF"+[...(a==null?void 0:a.includeHeaders)!==!1?[u.join(" ")]:[],...p.map(i=>i.join(" "))].join(`
|
|
79
|
+
`);J(j,(a==null?void 0:a.filename)||`${s.title||"report"}.tsv`,"text/tab-separated-values")}function ee(s,d,a,c){switch(s){case"csv":oe(d,a,c);break;case"json":ue(d,a,c);break;case"html":K(d,a,c);break;case"pdf":he(d,a,c);break;case"excel":me(d,a,c);break;default:console.warn(`Unsupported export format: ${s}`)}}function O(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function xe(s){if(typeof s=="string"&&s.length>0){const d=s.charAt(0);if(d==="="||d==="+"||d==="-"||d==="@"||d==="|")return` ${s}`}return s}function pe(s){return["A4","A3","Letter","Legal"].includes(s||"")?s:"A4"}function fe(s){return s==="landscape"?"landscape":"portrait"}function J(s,d,a){const c=new Blob([s],{type:`${a};charset=utf-8`}),u=URL.createObjectURL(c),p=document.createElement("a");p.href=u,p.download=d,document.body.appendChild(p),p.click(),document.body.removeChild(p),URL.revokeObjectURL(u)}const te=({schema:s,onRefresh:d})=>{var E,S;const{report:a,data:c,showToolbar:u=!0,allowExport:p=!0,allowPrint:j=!0,loading:i=!1}=s,x=m=>{var v;if(!a){console.warn("ReportViewer: Cannot export, no report defined");return}ee(m,a,c||[],(v=a.exportConfigs)==null?void 0:v[m])},n=()=>{window.print()},b=()=>{d==null||d()},y=(m,v)=>{if(!c)return 0;const N=c.map(k=>Number(k[m])||0);switch(v){case"count":return c.length;case"sum":return N.reduce((k,g)=>k+g,0);case"avg":return N.length>0?(N.reduce((k,g)=>k+g,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""}};return a?e.jsxs("div",{className:"space-y-4",children:[u&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a.title}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.refreshInterval&&e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:b,children:[e.jsx(w.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),j&&e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:n,children:[e.jsx(w.Printer,{className:"h-4 w-4 mr-2"}),"Print"]}),p&&a.showExportButtons&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("pdf"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"PDF"]}),e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("excel"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"Excel"]}),e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("csv"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"CSV"]})]})]})]}),e.jsxs(r.Card,{children:[e.jsxs(r.CardHeader,{children:[!u&&a.title&&e.jsx(r.CardTitle,{children:a.title}),!u&&a.description&&e.jsx(r.CardDescription,{children:a.description})]}),e.jsxs(r.CardContent,{className:"space-y-6",children:[i&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading report data..."}),!i&&((E=a.sections)==null?void 0:E.map((m,v)=>{var N,k;return m.visible===!1?null:e.jsxs("div",{className:"space-y-2",children:[m.title&&e.jsx("h3",{className:"text-lg font-semibold border-b pb-2",children:m.title}),m.type==="header"&&m.title&&e.jsx("div",{className:"text-2xl font-bold py-4",children:m.title}),m.type==="summary"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:(N=a.fields)==null?void 0:N.filter(g=>g.showInSummary).map((g,L)=>e.jsx(r.Card,{children:e.jsxs(r.CardContent,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:g.label||g.name}),e.jsx("div",{className:"text-2xl font-bold",children:y(g.name,g.aggregation)})]})},L))}),m.type==="chart"&&m.chart&&e.jsx("div",{className:"min-h-[300px]",children:(()=>{let g=m.chart.type;const L=!!m.chart.chartType;!g&&L&&(g="chart"),g&&!!_.ComponentRegistry.get(g)||(g="chart");const P=g==="chart"?{xAxisKey:m.chart.xAxisKey||m.chart.xAxisField||"name",series:m.chart.series||(m.chart.yAxisFields?m.chart.yAxisFields.map(Y=>({dataKey:Y})):[]),chartType:m.chart.chartType||"bar"}:{},V={...m.chart,type:g,...P,data:c||m.chart.data,className:m.chart.className||"w-full h-[350px]"};return e.jsx(ne.SchemaRenderer,{schema:V})})()}),m.type==="table"&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(k=m.columns)==null?void 0:k.map((g,L)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:g.label||g.name},L))})}),e.jsx("tbody",{children:c==null?void 0:c.map((g,L)=>{var D;return e.jsx("tr",{className:"border-t",children:(D=m.columns)==null?void 0:D.map((I,P)=>e.jsx("td",{className:"px-4 py-2",children:g[I.name]},P))},L)})})]})}),m.type==="text"&&m.text&&e.jsx("div",{className:"prose max-w-none",children:e.jsx("p",{children:m.text})}),m.type==="page-break"&&e.jsx("div",{className:"border-t-2 border-dashed my-8 print:page-break-after-always"}),m.content&&e.jsx(ne.SchemaRenderer,{schema:m.content})]},v)})),!a.sections&&c&&c.length>0&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(S=a.fields)==null?void 0:S.map((m,v)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:m.label||m.name},v))})}),e.jsx("tbody",{children:c.map((m,v)=>{var N;return e.jsx("tr",{className:"border-t",children:(N=a.fields)==null?void 0:N.map((k,g)=>e.jsx("td",{className:"px-4 py-2",children:m[k.name]},g))},v)})})]})})]})]})]}):e.jsx(r.Card,{children:e.jsx(r.CardContent,{className:"p-8 text-center text-muted-foreground",children:"No report to display"})})},je=({schedule:s,onChange:d})=>{var x;const[a,c]=B.useState(s||{enabled:!1,frequency:"weekly",time:"09:00",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:["pdf"]}),u=n=>{const b={...a,...n};c(b),d==null||d(b)},p=[{value:"once",label:"Once"},{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"monthly",label:"Monthly"},{value:"quarterly",label:"Quarterly"},{value:"yearly",label:"Yearly"}],j=[{value:"pdf",label:"PDF"},{value:"excel",label:"Excel"},{value:"csv",label:"CSV"},{value:"html",label:"HTML"}],i=[{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"}];return e.jsxs(r.Card,{children:[e.jsx(r.CardHeader,{children:e.jsxs(r.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(w.Calendar,{className:"h-5 w-5"}),"Schedule Configuration"]})}),e.jsxs(r.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"schedule-enabled",checked:a.enabled||!1,onChange:n=>u({enabled:n.target.checked}),className:"rounded"}),e.jsx(r.Label,{htmlFor:"schedule-enabled",children:"Enable Scheduled Report"})]}),a.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Frequency"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.frequency||"weekly",onChange:n=>u({frequency:n.target.value}),children:p.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),a.frequency==="weekly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Day of Week"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.dayOfWeek??1,onChange:n=>u({dayOfWeek:Number(n.target.value)}),children:i.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),a.frequency==="monthly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Day of Month"}),e.jsx(r.Input,{type:"number",min:1,max:31,value:a.dayOfMonth??1,onChange:n=>u({dayOfMonth:Number(n.target.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(r.Label,{className:"flex items-center gap-2",children:[e.jsx(w.Clock,{className:"h-4 w-4"}),"Time"]}),e.jsx(r.Input,{type:"time",value:a.time||"09:00",onChange:n=>u({time:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Timezone"}),e.jsx(r.Input,{value:a.timezone||"",onChange:n=>u({timezone:n.target.value}),placeholder:"e.g. America/New_York"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Export Formats"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(n=>{var b;return e.jsxs("label",{className:"flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50",children:[e.jsx("input",{type:"checkbox",checked:((b=a.formats)==null?void 0:b.includes(n.value))||!1,onChange:y=>{const E=a.formats||[];u({formats:y.target.checked?[...E,n.value]:E.filter(S=>S!==n.value)})},className:"rounded"}),e.jsx("span",{className:"text-sm",children:n.label})]},n.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(r.Label,{className:"flex items-center gap-2",children:[e.jsx(w.Mail,{className:"h-4 w-4"}),"Email Recipients"]}),e.jsx(r.Input,{placeholder:"email1@example.com, email2@example.com",value:((x=a.recipients)==null?void 0:x.join(", "))||"",onChange:n=>u({recipients:n.target.value.split(",").map(b=>b.trim()).filter(Boolean)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Email Subject"}),e.jsx(r.Input,{value:a.subject||"",onChange:n=>u({subject:n.target.value}),placeholder:"Scheduled Report: {report_title}"})]})]})]})]})},be=({schema:s})=>{const{report:d,dataSources:a=[],availableFields:c=[],showPreview:u=!0,onSave:p,onCancel:j}=s,[i,x]=B.useState(d||{type:"report",title:"New Report",fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[n,b]=B.useState(i.fields||[]),[y,E]=B.useState(i.filters||[]),[S,m]=B.useState(i.groupBy||[]),[v,N]=B.useState(i.sections||[]),k=()=>{if(c.length>0&&n.length<c.length){const l=c.find(o=>!n.some(h=>h.name===o.name));if(l){const o=[...n,l];b(o),x({...i,fields:o})}}},g=l=>{const o=n.filter((h,A)=>A!==l);b(o),x({...i,fields:o})},L=(l,o)=>{const h=[...n];h[l]=o,b(h),x({...i,fields:h})},D=()=>{var h;const l={field:((h=c[0])==null?void 0:h.name)||"",operator:"equals",value:""},o=[...y,l];E(o),x({...i,filters:o})},I=l=>{const o=y.filter((h,A)=>A!==l);E(o),x({...i,filters:o})},P=(l,o)=>{const h=[...y];h[l]=o,E(h),x({...i,filters:h})},V=()=>{var h;const l={field:((h=c[0])==null?void 0:h.name)||"",sort:"asc"},o=[...S,l];m(o),x({...i,groupBy:o})},Y=l=>{const o=S.filter((h,A)=>A!==l);m(o),x({...i,groupBy:o})},z=(l,o)=>{const h=[...S];h[l]=o,m(h),x({...i,groupBy:h})},W=l=>{const o={type:l,title:`New ${l} Section`},h=[...v,o];N(h),x({...i,sections:h})},ae=l=>{const o=v.filter((h,A)=>A!==l);N(o),x({...i,sections:o})},$=(l,o)=>{const h=[...v];h[l]=o,N(h),x({...i,sections:h})},X=()=>{console.log("Saving report:",i),p&&alert("Report saved! (Handler: "+p+")")},re=()=>{j&&console.log("Report cancelled:",j)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(r.Card,{children:[e.jsxs(r.CardHeader,{children:[e.jsx(r.CardTitle,{children:"Report Builder"}),e.jsx(r.CardDescription,{children:"Configure your report settings, fields, filters, and sections"})]}),e.jsxs(r.CardContent,{children:[e.jsxs(r.Tabs,{defaultValue:"basic",className:"w-full",children:[e.jsxs(r.TabsList,{className:"grid w-full grid-cols-6",children:[e.jsxs(r.TabsTrigger,{value:"basic",children:[e.jsx(w.Settings,{className:"h-4 w-4 mr-2"}),"Basic"]}),e.jsxs(r.TabsTrigger,{value:"fields",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Fields"]}),e.jsxs(r.TabsTrigger,{value:"filters",children:[e.jsx(w.Filter,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(r.TabsTrigger,{value:"grouping",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Group By"]}),e.jsxs(r.TabsTrigger,{value:"sections",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Sections"]}),e.jsxs(r.TabsTrigger,{value:"schedule",children:[e.jsx(w.Calendar,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsx(r.TabsContent,{value:"basic",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"report-title",children:"Report Title"}),e.jsx(r.Input,{id:"report-title",value:i.title||"",onChange:l=>x({...i,title:l.target.value}),placeholder:"Enter report title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"report-description",children:"Description"}),e.jsx(r.Input,{id:"report-description",value:i.description||"",onChange:l=>x({...i,description:l.target.value}),placeholder:"Enter report description"})]}),a.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Data Source"}),e.jsxs("select",{className:"w-full border rounded-md p-2",children:[e.jsx("option",{value:"",children:"Select a data source"}),a.map((l,o)=>e.jsxs("option",{value:o,children:["Data Source ",o+1]},o))]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Export Options"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showExportButtons||!1,onChange:l=>x({...i,showExportButtons:l.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Export Buttons"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showPrintButton||!1,onChange:l=>x({...i,showPrintButton:l.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Print Button"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"export-format",children:"Default Export Format"}),e.jsxs("select",{id:"export-format",className:"w-full border rounded-md p-2",value:i.defaultExportFormat||"pdf",onChange:l=>x({...i,defaultExportFormat:l.target.value}),children:[e.jsx("option",{value:"pdf",children:"PDF"}),e.jsx("option",{value:"excel",children:"Excel"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"html",children:"HTML"})]})]})]})}),e.jsxs(r.TabsContent,{value:"fields",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Fields"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:k,disabled:n.length>=c.length,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Field"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map((l,o)=>e.jsx("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field Name"}),e.jsx("div",{className:"text-sm font-medium",children:l.name})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Label"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.label||l.name,onChange:h=>L(o,{...l,label:h.target.value})})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Aggregation"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.aggregation||"",onChange:h=>L(o,{...l,aggregation:h.target.value}),children:[e.jsx("option",{value:"",children:"None"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsx("div",{className:"flex items-end justify-end",children:e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>g(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})})]})},o)),n.length===0&&e.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.'})]})]}),e.jsxs(r.TabsContent,{value:"filters",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Filters"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:D,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Filter"]})]}),e.jsxs("div",{className:"space-y-2",children:[y.map((l,o)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.field,onChange:h=>P(o,{...l,field:h.target.value}),children:c.map((h,A)=>e.jsx("option",{value:h.name,children:h.label||h.name},A))})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Operator"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.operator,onChange:h=>P(o,{...l,operator:h.target.value}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"gt",children:"Greater Than"}),e.jsx("option",{value:"lt",children:"Less Than"}),e.jsx("option",{value:"between",children:"Between"})]})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Value"}),e.jsx(r.Input,{className:"h-8 text-sm",value:String(l.value),onChange:h=>P(o,{...l,value:h.target.value})})]})]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>I(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]},o)),y.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No filters defined."})]})]}),e.jsxs(r.TabsContent,{value:"grouping",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Grouping Rules"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:V,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Group"]})]}),e.jsxs("div",{className:"space-y-2",children:[S.map((l,o)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.field,onChange:h=>z(o,{...l,field:h.target.value}),children:c.map((h,A)=>e.jsx("option",{value:h.name,children:h.label||h.name},A))})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Sort Order"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.sort||"asc",onChange:h=>z(o,{...l,sort:h.target.value}),children:[e.jsx("option",{value:"asc",children:"Ascending"}),e.jsx("option",{value:"desc",children:"Descending"})]})]})]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>Y(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]},o)),S.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No grouping rules applied."})]})]}),e.jsxs(r.TabsContent,{value:"sections",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Sections"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("header"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Header"]}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("chart"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("table"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Table"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[v.map((l,o)=>{var h,A,q,H;return e.jsxs("div",{className:"p-3 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx("div",{className:"text-xs bg-muted px-2 py-0.5 rounded uppercase",children:l.type}),l.title]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>ae(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Title"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.title||"",onChange:t=>$(o,{...l,title:t.target.value})})]}),l.type==="text"&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(r.Label,{className:"text-xs",children:"Content"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.text||"",onChange:t=>$(o,{...l,text:t.target.value})})]}),l.type==="chart"&&e.jsxs("div",{className:"col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(r.Label,{className:"text-xs font-semibold",children:"Chart Configuration"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Chart Type"}),e.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:((h=l.chart)==null?void 0:h.chartType)||"bar",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",chartType:t.target.value}}),children:[e.jsx("option",{value:"bar",children:"Bar"}),e.jsx("option",{value:"line",children:"Line"}),e.jsx("option",{value:"area",children:"Area"}),e.jsx("option",{value:"pie",children:"Pie"})]})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"X-Axis Field"}),e.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:((A=l.chart)==null?void 0:A.xAxisField)||"",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",xAxisField:t.target.value}}),children:[e.jsx("option",{value:"",children:"Select Field..."}),c.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name)),c.length===0&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"name",children:"Name"}),e.jsx("option",{value:"month",children:"Month"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(r.Label,{className:"text-xs",children:"Y-Axis Fields (comma separated)"}),e.jsx(r.Input,{className:"h-8 text-sm",placeholder:"e.g. value, count",value:((H=(q=l.chart)==null?void 0:q.yAxisFields)==null?void 0:H.join(", "))||"",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",yAxisFields:t.target.value.split(",").map(f=>f.trim()).filter(Boolean)}})})]})]})]})]},o)}),v.length===0&&e.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."})]})]}),e.jsx(r.TabsContent,{value:"schedule",className:"space-y-4 mt-4",children:e.jsx(je,{schedule:i.schedule,onChange:l=>x({...i,schedule:l})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-6 pt-4 border-t",children:[e.jsx(r.Button,{variant:"outline",onClick:re,children:"Cancel"}),e.jsxs(r.Button,{onClick:X,children:[e.jsx(w.Save,{className:"h-4 w-4 mr-2"}),"Save Report"]})]})]})]}),u&&e.jsxs(r.Card,{className:"mt-8 border-2 border-blue-100",children:[e.jsx(r.CardHeader,{className:"bg-blue-50/50",children:e.jsx(r.CardTitle,{className:"text-blue-900 text-sm uppercase tracking-wide",children:"Live Preview"})}),e.jsx(r.CardContent,{className:"pt-6",children:e.jsx(te,{schema:{type:"report-viewer",report:{...i,fields:n,filters:y,groupBy:S,sections:v},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"}]}})})]})]})};async function ve(s,d){var x;const{dataSource:a,resource:c,queryParams:u,format:p,exportConfig:j}=d,i=p||s.defaultExportFormat||"pdf";try{const b=(await a.find(c,u)).data||[],y={format:i,...(x=s.exportConfigs)==null?void 0:x[i],...j};return ee(i,s,b,y),{success:!0,recordCount:b.length,format:i}}catch(n){return{success:!1,recordCount:0,format:i,error:n.message}}}function Ne(s,d,a={}){const{columns:c,filename:u,includeAggregationRow:p=!1}=a,j=c||(s.fields||[]).map(Ce),i=j.map(y=>y.header),x=d.map((y,E)=>j.map(S=>{if(S.formula)return S.formula.replace(/\{ROW\}/g,String(E+2));const m=y[S.name];return Se(m,S.numberFormat)}));if(p&&d.length>0){const y=j.map((E,S)=>{const m=(s.fields||[]).find(v=>v.name===E.name);if(m!=null&&m.aggregation){const v=ke(S),N=2,k=d.length+1;switch(m.aggregation){case"sum":return`=SUM(${v}${N}:${v}${k})`;case"avg":return`=AVERAGE(${v}${N}:${v}${k})`;case"count":return`=COUNTA(${v}${N}:${v}${k})`;case"min":return`=MIN(${v}${N}:${v}${k})`;case"max":return`=MAX(${v}${N}:${v}${k})`;default:return""}}return""});x.push(y)}const n="\uFEFF"+[i.join(" "),...x.map(y=>y.join(" "))].join(`
|
|
80
|
+
`),b=u||`${s.title||"report"}.tsv`;Re(n,b,"text/tab-separated-values")}function we(s,d,a,c){return async()=>{const u=s.schedule;if(!(u!=null&&u.enabled))return[];const p=u.formats||[s.defaultExportFormat||"pdf"],j=[];for(const i of p){const x=await ve(s,{dataSource:d,resource:a,format:i});j.push(x)}return c(s,u),j}}function Ce(s){return{name:s.name,header:s.label||s.name}}function Se(s,d){return s==null?"":typeof s=="number"&&d?s.toLocaleString("en-US",Te(d)):Ee(String(s))}function Te(s){if(s.includes("%"))return{style:"percent",minimumFractionDigits:0};const d=(s.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,d-1),maximumFractionDigits:Math.max(0,d-1)}}function ke(s){let d="",a=s;for(;a>=0;)d=String.fromCharCode(a%26+65)+d,a=Math.floor(a/26)-1;return d}function Ee(s){if(s.length>0){const d=s.charAt(0);if(d==="="||d==="+"||d==="-"||d==="@"||d==="|")return`'${s}`}return s}function Re(s,d,a){const c=new Blob([s],{type:`${a};charset=utf-8`}),u=URL.createObjectURL(c),p=document.createElement("a");p.href=u,p.download=d,document.body.appendChild(p),p.click(),document.body.removeChild(p),URL.revokeObjectURL(u)}_.ComponentRegistry.register("report",ce,{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"}]}),_.ComponentRegistry.register("report-viewer",te,{namespace:"report",label:"Report Viewer",category:"Report",inputs:[{name:"report",type:"code",label:"Report Definition"},{name:"showToolbar",type:"boolean",label:"Show Toolbar"}]}),_.ComponentRegistry.register("report-builder",be,{namespace:"report",label:"Report Builder",category:"Report",inputs:[{name:"report",type:"code",label:"Initial Report"}]}),C.ReportBuilder=be,C.ReportRenderer=ce,C.ReportViewer=te,C.ScheduleConfig=je,C.createScheduleTrigger=we,C.exportAsCSV=oe,C.exportAsExcel=me,C.exportAsHTML=K,C.exportAsJSON=ue,C.exportAsPDF=he,C.exportExcelWithFormulas=Ne,C.exportReport=ee,C.exportWithLiveData=ve,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DataSource, QueryParams, ReportSchema, ReportExportFormat, ReportExportConfig, ReportSchedule } from '../../types/src';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for live report export
|
|
5
|
+
*/
|
|
6
|
+
export interface LiveExportOptions {
|
|
7
|
+
/** Data source adapter (e.g. ApiDataSource or ObjectStackAdapter) */
|
|
8
|
+
dataSource: DataSource;
|
|
9
|
+
/** Resource / object name to query */
|
|
10
|
+
resource: string;
|
|
11
|
+
/** Additional query parameters */
|
|
12
|
+
queryParams?: QueryParams;
|
|
13
|
+
/** Export format override */
|
|
14
|
+
format?: ReportExportFormat;
|
|
15
|
+
/** Export config override */
|
|
16
|
+
exportConfig?: ReportExportConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Excel column configuration for formatted export
|
|
20
|
+
*/
|
|
21
|
+
export interface ExcelColumnConfig {
|
|
22
|
+
/** Field name */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Column display header */
|
|
25
|
+
header: string;
|
|
26
|
+
/** Column width (character units) */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** Number format (e.g. '#,##0.00', '0%') */
|
|
29
|
+
numberFormat?: string;
|
|
30
|
+
/** Excel formula template (use {ROW} as row placeholder) */
|
|
31
|
+
formula?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Result of a live export operation
|
|
35
|
+
*/
|
|
36
|
+
export interface LiveExportResult {
|
|
37
|
+
/** Whether the export succeeded */
|
|
38
|
+
success: boolean;
|
|
39
|
+
/** Number of records exported */
|
|
40
|
+
recordCount: number;
|
|
41
|
+
/** Export format used */
|
|
42
|
+
format: ReportExportFormat;
|
|
43
|
+
/** Error message if failed */
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Schedule trigger callback
|
|
48
|
+
*/
|
|
49
|
+
export type ScheduleTriggerCallback = (report: ReportSchema, schedule: ReportSchedule) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Export a report with live data fetched from a DataSource adapter.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* await exportWithLiveData(report, {
|
|
56
|
+
* dataSource: myAdapter,
|
|
57
|
+
* resource: 'orders',
|
|
58
|
+
* format: 'pdf',
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function exportWithLiveData(report: ReportSchema, options: LiveExportOptions): Promise<LiveExportResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Export report as Excel with formatted columns and formula support.
|
|
65
|
+
*
|
|
66
|
+
* Generates a TSV file with:
|
|
67
|
+
* - Column headers from field labels
|
|
68
|
+
* - Formatted numeric values
|
|
69
|
+
* - Excel formula cells (=SUM, =AVERAGE, etc.)
|
|
70
|
+
* - UTF-8 BOM for proper character display
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* exportExcelWithFormulas(report, data, {
|
|
75
|
+
* columns: [
|
|
76
|
+
* { name: 'amount', header: 'Amount', numberFormat: '#,##0.00' },
|
|
77
|
+
* { name: 'total', header: 'Total', formula: '=B{ROW}*C{ROW}' },
|
|
78
|
+
* ],
|
|
79
|
+
* includeAggregationRow: true,
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function exportExcelWithFormulas(report: ReportSchema, data: any[], options?: {
|
|
84
|
+
columns?: ExcelColumnConfig[];
|
|
85
|
+
filename?: string;
|
|
86
|
+
includeAggregationRow?: boolean;
|
|
87
|
+
}): void;
|
|
88
|
+
/**
|
|
89
|
+
* Create a schedule trigger that can be invoked by workflow engines.
|
|
90
|
+
*
|
|
91
|
+
* Returns a callback that, when invoked, exports the report using the
|
|
92
|
+
* schedule's configured formats and notifies the provided handler.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const trigger = createScheduleTrigger(report, dataSource, 'orders', (report, schedule) => {
|
|
97
|
+
* // Send email with attachments
|
|
98
|
+
* sendEmail(schedule.recipients, schedule.subject, ...);
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* // Invoke from workflow engine
|
|
102
|
+
* await trigger();
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function createScheduleTrigger(report: ReportSchema, dataSource: DataSource, resource: string, onComplete: ScheduleTriggerCallback): () => Promise<LiveExportResult[]>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReportSchema, ReportExportConfig, ReportExportFormat } from '../../types/src';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Report Export Engine
|
|
5
|
+
* Handles exporting report data to various formats using browser-native APIs.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Export report data as CSV
|
|
9
|
+
*/
|
|
10
|
+
export declare function exportAsCSV(report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
11
|
+
/**
|
|
12
|
+
* Export report data as JSON
|
|
13
|
+
*/
|
|
14
|
+
export declare function exportAsJSON(report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
15
|
+
/**
|
|
16
|
+
* Export report as HTML (printable format)
|
|
17
|
+
*/
|
|
18
|
+
export declare function exportAsHTML(report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
19
|
+
/**
|
|
20
|
+
* Export report as PDF using browser print
|
|
21
|
+
*/
|
|
22
|
+
export declare function exportAsPDF(report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
23
|
+
/**
|
|
24
|
+
* Export report as Excel-compatible CSV (with BOM for proper UTF-8 in Excel)
|
|
25
|
+
*/
|
|
26
|
+
export declare function exportAsExcel(report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
27
|
+
/**
|
|
28
|
+
* Main export function - routes to correct format handler
|
|
29
|
+
*/
|
|
30
|
+
export declare function exportReport(format: ReportExportFormat, report: ReportSchema, data: any[], config?: ReportExportConfig): void;
|
|
@@ -3,10 +3,11 @@ import { ReportViewerSchema } from '../../types/src';
|
|
|
3
3
|
|
|
4
4
|
export interface ReportViewerProps {
|
|
5
5
|
schema: ReportViewerSchema;
|
|
6
|
+
/** Callback to refresh data */
|
|
7
|
+
onRefresh?: () => void;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* ReportViewer - Display a generated report with optional toolbar
|
|
9
11
|
* Supports rendering report sections, charts, tables, and export functionality
|
|
10
12
|
*/
|
|
11
13
|
export declare const ReportViewer: React.FC<ReportViewerProps>;
|
|
12
|
-
//# sourceMappingURL=ReportViewer.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ReportSchedule } from '../../types/src';
|
|
3
|
+
|
|
4
|
+
export interface ScheduleConfigProps {
|
|
5
|
+
schedule?: ReportSchedule;
|
|
6
|
+
onChange?: (schedule: ReportSchedule) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const ScheduleConfig: React.FC<ScheduleConfigProps>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReportRenderer } from './ReportRenderer';
|
|
2
|
+
import { ReportViewer } from './ReportViewer';
|
|
3
|
+
import { ReportBuilder } from './ReportBuilder';
|
|
4
|
+
|
|
5
|
+
export { ReportRenderer, ReportViewer, ReportBuilder };
|
|
6
|
+
export { exportReport, exportAsCSV, exportAsJSON, exportAsHTML, exportAsPDF, exportAsExcel } from './ReportExportEngine';
|
|
7
|
+
export { ScheduleConfig } from './ScheduleConfig';
|
|
8
|
+
export { exportWithLiveData, exportExcelWithFormulas, createScheduleTrigger, } from './LiveReportExporter';
|
|
9
|
+
export type { LiveExportOptions, LiveExportResult, ExcelColumnConfig, ScheduleTriggerCallback, } from './LiveReportExporter';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-report",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^18.0.0",
|
|
20
20
|
"react-dom": "^18.0.0",
|
|
21
|
-
"@object-ui/
|
|
22
|
-
"@object-ui/
|
|
23
|
-
"@object-ui/
|
|
24
|
-
"@object-ui/react": "0.
|
|
25
|
-
"@object-ui/
|
|
21
|
+
"@object-ui/components": "3.0.0",
|
|
22
|
+
"@object-ui/core": "3.0.0",
|
|
23
|
+
"@object-ui/fields": "3.0.0",
|
|
24
|
+
"@object-ui/react": "3.0.0",
|
|
25
|
+
"@object-ui/types": "3.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"clsx": "^2.1.
|
|
28
|
+
"clsx": "^2.1.1",
|
|
29
29
|
"lucide-react": "^0.344.0",
|
|
30
|
-
"tailwind-merge": "^2.
|
|
30
|
+
"tailwind-merge": "^2.6.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"@types/react": "
|
|
35
|
-
"@types/react-dom": "
|
|
36
|
-
"@vitejs/plugin-react": "^
|
|
37
|
-
"vite": "^5.
|
|
38
|
-
"vite-plugin-dts": "^3.
|
|
39
|
-
"vitest": "^1.
|
|
33
|
+
"@types/node": "^25.2.3",
|
|
34
|
+
"@types/react": "19.2.13",
|
|
35
|
+
"@types/react-dom": "19.2.3",
|
|
36
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
37
|
+
"vite": "^5.4.21",
|
|
38
|
+
"vite-plugin-dts": "^3.9.1",
|
|
39
|
+
"vitest": "^1.6.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "vite build",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReportBuilder.d.ts","sourceRoot":"","sources":["../../src/ReportBuilder.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAyE,MAAM,kBAAkB,CAAC;AAInI,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsmBtD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReportRenderer.d.ts","sourceRoot":"","sources":["../../src/ReportRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwFxD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReportViewer.d.ts","sourceRoot":"","sources":["../../src/ReportViewer.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,kBAAkB,CAAC;AAG1E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAwPpD,CAAC"}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
|