deepspotscreen-sdk 0.0.3 → 0.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.
@@ -1,780 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class F{constructor(e,t){this.tokenCache=new Map,this.baseUrl=e.replace(/\/$/,""),this.apiKey=t}async getEmbedToken(e){var i,a,o,d;const t=[e.dashboardId,e.embedType,(i=e.embedLevel)!=null?i:"",(a=e.componentId)!=null?a:"",(o=e.userId)!=null?o:""].join(":"),s=this.tokenCache.get(t);if(s&&s.expiresAt>Date.now()+6e4)return s.token;const r=await this.post("/dashboard-builder/embed-token",{dashboardId:e.dashboardId,embedType:e.embedType,embedLevel:(d=e.embedLevel)!=null?d:"dashboard",componentId:e.componentId,userId:e.userId,tenantId:e.tenantId,expiresIn:3600},{"x-deepspot-api-key":this.apiKey});return this.tokenCache.set(t,{token:r.token,expiresAt:new Date(r.expiresAt).getTime()}),r.token}async getDashboardRender(e,t,s={}){var i;const r=new URLSearchParams({embedType:"dashboard",embedLevel:(i=s.embedLevel)!=null?i:"dashboard"});return s.pageId&&r.set("pageId",s.pageId),s.tabId&&r.set("tabId",s.tabId),s.filters&&Object.entries(s.filters).forEach(([a,o])=>{o!=null&&o!==""&&r.set(`filter[${a}]`,Array.isArray(o)?o.join(","):String(o))}),this.get(`/dashboard-builder/embed/${e}/render?${r}`,{"x-embed-token":t})}async getReportRender(e,t,s,r={}){const i=new URLSearchParams({embedType:"report",embedLevel:"report",componentId:t});return r.filters&&Object.entries(r.filters).forEach(([a,o])=>{o!=null&&o!==""&&i.set(`filter[${a}]`,Array.isArray(o)?o.join(","):String(o))}),this.get(`/dashboard-builder/embed/${e}/render?${i}`,{"x-embed-token":s})}async createApiKey(e,t){return this.post("/dashboard-builder/api-keys",e,{Authorization:`Bearer ${t}`})}async listApiKeys(e){return this.get("/dashboard-builder/api-keys",{Authorization:`Bearer ${e}`})}async deleteApiKey(e,t){await this.delete(`/dashboard-builder/api-keys/${e}`,{Authorization:`Bearer ${t}`})}async getTablePage(e,t,s,r,i){return this.get(`/dashboard-builder/embed/${e}/table/${t}/data?page=${s}&pageSize=${r}`,{"x-embed-token":i})}async getFilterOptions(e,t,s){try{const r=await this.get(`/dashboard-builder/embed/${e}/filters/${t}/options`,{"x-embed-token":s});return Array.isArray(r)?r:Array.isArray(r==null?void 0:r.options)?r.options:Array.isArray(r==null?void 0:r.data)?r.data:[]}catch(r){return[]}}clearTokenCache(){this.tokenCache.clear()}async get(e,t={}){const s=await fetch(`${this.baseUrl}${e}`,{method:"GET",headers:{"Content-Type":"application/json",...t}});return this.handleResponse(s)}async post(e,t,s={}){const r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)});return this.handleResponse(r)}async delete(e,t={}){const s=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:{"Content-Type":"application/json",...t}});if(!s.ok)throw new Error(`Deepspot SDK: DELETE ${e} failed (${s.status})`)}async handleResponse(e){if(!e.ok){let s=`HTTP ${e.status}`;try{const r=await e.json();s=(r==null?void 0:r.message)||(r==null?void 0:r.error)||s}catch(r){}throw new Error(`Deepspot SDK: ${s}`)}const t=await e.json();return(t==null?void 0:t.data)!==void 0?t.data:t}}class ${constructor(e){var t,s;this.destroyed=!1,this.refreshTimer=null,this.opts=e,this.filters={...e.activeFilters},this.activePageId=(t=e.activePageId)!=null?t:"",this.activeTabId=(s=e.activeTabId)!=null?s:""}getActiveFilters(){return{...this.filters}}setFilter(e,t){this.filters[e]=t,this.scheduleRefresh()}setFilters(e){Object.assign(this.filters,e),this.scheduleRefresh()}goToPage(e){this.opts.embedType==="dashboard"&&(this.activePageId=e,this.opts.renderer.goToPage(e))}goToTab(e,t){this.opts.embedType==="dashboard"&&(this.activePageId=e,this.activeTabId=t,this.opts.renderer.goToTab(e,t))}async refresh(){if(!this.destroyed)try{const e=await this.fetchData();this.opts.renderer.update(e)}catch(e){console.error("Deepspot SDK: refresh failed",e)}}exportPDF(){this.opts.embedType==="dashboard"&&this.opts.renderer.exportPDF()}destroy(){this.destroyed=!0,this.refreshTimer&&clearTimeout(this.refreshTimer),this.opts.renderer.destroy(),this.opts.apiClient.clearTokenCache()}scheduleRefresh(){this.refreshTimer&&clearTimeout(this.refreshTimer),this.refreshTimer=setTimeout(()=>this.refresh(),300)}async fetchData(){const{apiClient:e,dashboardId:t,componentId:s,token:r,embedType:i,embedLevel:a}=this.opts;return i==="report"&&s?e.getReportRender(t,s,r,{filters:this.filters}):e.getDashboardRender(t,r,{embedLevel:a,pageId:this.activePageId||void 0,tabId:this.activeTabId||void 0,filters:this.filters})}}const A=24,w=10,T=12;class S{constructor(e,t=0){this.containerWidth=e,this.minY=t}get colWidth(){return this.containerWidth/A}toPx(e){const t=this.colWidth,s=T/2;return{left:e.x*t+s,top:(e.y-this.minY)*w+s,width:e.w*t-T,height:e.h*w-T}}static totalHeight(e){if(!e.length)return 400;const t=Math.min(...e.map(r=>r.y));return(Math.max(...e.map(r=>r.y+r.h))-t)*w+40}applyStyles(e,t){const s=this.toPx(t);e.style.position="absolute",e.style.left=`${s.left}px`,e.style.top=`${s.top}px`,e.style.width=`${s.width}px`,e.style.height=`${s.height}px`}}let k=null;function E(){return k||(k=Promise.resolve().then(()=>require("./apexcharts.common-DGzslxI3.cjs")).then(u=>u.apexcharts_common)),k}class R{constructor(e){this.chart=null,this.container=e}async render(e,t,s,r){if(!t||t.length===0){this.renderEmpty(e.title);return}const i=this.buildOptions(e,t,s,r);if(!i){this.renderEmpty(e.title);return}this.container.innerHTML=`
2
- <div class="ds-chart-card">
3
- <div class="ds-chart-title">${e.title||""}</div>
4
- <div class="ds-chart-body" id="ds-chart-body-${e.id}"></div>
5
- </div>
6
- `;const a=this.container.querySelector(`#ds-chart-body-${e.id}`);if(a)try{this.chart&&this.chart.destroy();const{default:o}=await E();this.chart=new o(a,i),this.chart.render()}catch(o){console.error("[Deepspot SDK] ChartRenderer error:",o),a.innerHTML='<div class="ds-chart-empty">Chart render error</div>'}}async update(e,t,s){if(!this.chart||!t||t.length===0){await this.render(e,t,s);return}const{series:r,categories:i}=this.extractSeriesAndCategories(e,t);try{this.chart.updateOptions({series:r,xaxis:{categories:i},theme:{mode:s}})}catch(a){this.render(e,t,s)}}destroy(){var e;try{(e=this.chart)==null||e.destroy()}catch(t){}this.chart=null}buildOptions(e,t,s,r){const i=e.type;return i==="pie"||i==="donut"?this.buildPieOptions(e,t,s,r):i==="bar"||i==="line"||i==="area"?this.buildCartesianOptions(e,t,s,r):null}buildCartesianOptions(e,t,s,r){var n;const{series:i,categories:a,xAxisLabel:o,yAxisLabel:d}=this.extractSeriesAndCategories(e,t),c=e.properties||{},h=c.colors?Object.values(c.colors):["#6366f1","#8b5cf6","#ec4899","#f59e0b","#10b981","#3b82f6"],l=s==="dark";return{chart:{type:e.type==="area"?"area":e.type==="line"?"line":"bar",toolbar:{show:!1},background:"transparent",animations:{enabled:!0,speed:400},fontFamily:"inherit",height:r!=null?r:"100%"},theme:{mode:s},series:i,xaxis:{categories:a,title:{text:o},labels:{rotate:a.length>8?-45:0,style:{colors:l?"#94a3b8":"#6b7280",fontSize:"11px"}},axisBorder:{color:l?"#334155":"#e5e7eb"},axisTicks:{color:l?"#334155":"#e5e7eb"}},yaxis:{title:{text:d},labels:{style:{colors:l?"#94a3b8":"#6b7280",fontSize:"11px"}}},colors:h,legend:{show:i.length>1||((n=c.showLegend)!=null?n:!1),position:"bottom",labels:{colors:l?"#94a3b8":"#6b7280"}},grid:{borderColor:l?"#1e293b":"#f3f4f6",strokeDashArray:4,padding:{bottom:a.length>8?60:10}},tooltip:{theme:s},stroke:{curve:"smooth",width:e.type==="bar"?0:2},fill:e.type==="area"?{type:"gradient",gradient:{shadeIntensity:.5,opacityFrom:.4,opacityTo:0}}:{},dataLabels:{enabled:!1},plotOptions:{bar:{borderRadius:4,distributed:i.length===1}}}}buildPieOptions(e,t,s,r){const i=e.properties||{},a=t.length>0?Object.keys(t[0]):[],o=a[0]||"label",d=a[1]||"value",c=t.map(b=>{var p;return String((p=b[o])!=null?p:"")}),h=t.map(b=>Number(b[d])||0),l=s==="dark",n=i.colors?Object.values(i.colors):["#6366f1","#8b5cf6","#ec4899","#f59e0b","#10b981","#3b82f6"];return{chart:{type:e.type,toolbar:{show:!1},background:"transparent",fontFamily:"inherit",height:r!=null?r:"100%"},theme:{mode:s},series:h,labels:c,colors:n,legend:{position:"bottom",labels:{colors:l?"#94a3b8":"#6b7280"}},tooltip:{theme:s},dataLabels:{enabled:c.length<=8},plotOptions:{pie:{donut:{size:e.type==="donut"?"65%":"0%"}}}}}extractSeriesAndCategories(e,t){const s=e.properties||{},r=t.length>0?Object.keys(t[0]):[],i=s.xAxis||r[0]||"x";let a=[];if(s.selectedYAxisColumn)try{const n=typeof s.selectedYAxisColumn=="string"?JSON.parse(s.selectedYAxisColumn):s.selectedYAxisColumn;Array.isArray(n)&&(a=n.map(b=>typeof b=="string"?{column:b}:b))}catch(n){}if(!a.length&&s.yAxis){const n=s.yAxis;a=(Array.isArray(n)?n:[n]).map(p=>({column:String(p)}))}!a.length&&r.length>1&&(a=r.slice(1).map(n=>({column:n})));const o=t.map(n=>{var b;return String((b=n[i])!=null?b:"")}),d=t.length>0?Object.keys(t[0]):[],c=a.map(n=>{const b=d.includes(n.column)?n.column:null,p=b?null:d.find(g=>g.includes(n.column)||n.column.includes(g)),m=!b&&!p?d.find(g=>{var y;return g!==i&&!isNaN(Number((y=t[0])==null?void 0:y[g]))}):null,f=b||p||m||n.column;return{name:n.label||n.column.replace(/_/g," "),data:t.map(g=>{const y=g[f];return y!=null?Number(y):null})}}),h=s.xAxisLabel||i.replace(/_/g," "),l=s.yAxisLabel||(c.length===1?c[0].name:"Values");return{series:c,categories:o,xAxisLabel:h,yAxisLabel:l}}renderEmpty(e){this.container.innerHTML=`
7
- <div class="ds-chart-card">
8
- ${e?`<div class="ds-chart-title">${e}</div>`:""}
9
- <div class="ds-chart-empty">No data available</div>
10
- </div>
11
- `}}class L{constructor(){this.columns=[],this.allData=[],this.currentRows=[],this.totalRows=0,this.currentPage=1,this.currentPageSize=10,this.searchTerm="",this.isLoading=!1}render(e,t,s,r){var h;this.container=e,this.component=t,this.fetchPage=r,this.searchTerm="",this.currentPage=1,this.currentPageSize=10;const i=s&&!Array.isArray(s)&&"rows"in s;if(i){const l=s;this.currentRows=l.rows,this.allData=[],this.totalRows=l.total,this.currentPage=l.page,this.currentPageSize=l.pageSize}else this.allData=s||[],this.currentRows=[],this.totalRows=this.allData.length,this.currentPage=1;if(i&&s.rows.length===0&&s.total===0||!i&&this.allData.length===0){e.innerHTML=`
12
- <div class="ds-table-card">
13
- <div class="ds-table-header-row">
14
- <span class="ds-table-dot"></span>
15
- <div class="ds-table-title">${this.escape(t.title||"")}</div>
16
- </div>
17
- <div class="ds-chart-empty">No data available</div>
18
- </div>
19
- `;return}const a=i?s.rows[0]:this.allData[0],o=a?Object.keys(a):[],d=((h=t.properties)==null?void 0:h.columns)||[],c=d.length?d.filter(l=>o.includes(l)):[];this.columns=c.length?c:o,this.paint()}paint(){const{rows:e,startNum:t}=this.getPageRows(),s=Math.max(1,Math.ceil(this.totalRows/this.currentPageSize)),r=(this.currentPage-1)*this.currentPageSize+1,i=this.fetchPage?Math.min(r-1+(this.isLoading?this.currentPageSize:e.length),this.totalRows):Math.min(this.currentPage*this.currentPageSize,this.totalRows),a=this.columns.map(n=>`<th>${this.escape(this.formatHeader(n))}</th>`).join(""),o=e.length===0?`<tr><td colspan="${this.columns.length+1}" style="text-align:center;padding:20px;color:#9ca3af">No results found</td></tr>`:e.map((n,b)=>{const p=this.columns.map(m=>{const f=n[m];return`<td title="${this.escape(String(f!=null?f:""))}">${this.escape(this.formatValue(f))}</td>`}).join("");return`<tr><td class="ds-table-sno">${t+b}</td>${p}</tr>`}).join(""),d=this.currentPageSize,c=[10,25,50,100].map(n=>`<option value="${n}"${n===d?" selected":""}>${n}</option>`).join(""),h=this.currentPage<=1,l=this.currentPage>=s;this.container.innerHTML=`
20
- <div class="ds-table-card">
21
- <div class="ds-table-header-row">
22
- <div class="ds-table-title-wrap">
23
- <span class="ds-table-dot"></span>
24
- <span class="ds-table-title">${this.escape(this.component.title||"")}</span>
25
- </div>
26
- </div>
27
- <div class="ds-table-scroll">
28
- <table class="ds-table">
29
- <thead><tr><th class="ds-table-sno-th">S.No</th>${a}</tr></thead>
30
- <tbody>${o}</tbody>
31
- </table>
32
- </div>
33
- <div class="ds-table-footer">
34
- <div class="ds-table-info">
35
- <span>${r.toLocaleString()}–${i.toLocaleString()} of ${this.totalRows.toLocaleString()}</span>
36
- <span class="ds-table-rows-label">Rows:</span>
37
- <select class="ds-table-page-size">${c}</select>
38
- </div>
39
- <div class="ds-table-pagination">
40
- <button class="ds-table-pg-btn" data-action="first" ${h?"disabled":""}>&#171;</button>
41
- <button class="ds-table-pg-btn" data-action="prev" ${h?"disabled":""}>Previous</button>
42
- <span class="ds-table-pg-info">Page ${this.currentPage} of ${s}</span>
43
- <button class="ds-table-pg-btn" data-action="next" ${l?"disabled":""}>Next</button>
44
- <button class="ds-table-pg-btn" data-action="last" ${l?"disabled":""}>&#187;</button>
45
- </div>
46
- </div>
47
- ${this.isLoading?'<div class="ds-table-loading-overlay"><div class="ds-embed-spinner"></div></div>':""}
48
- </div>
49
- `,this.attachEvents()}attachEvents(){const e=this.container.querySelector(".ds-table-search");e==null||e.addEventListener("input",()=>{this.searchTerm=e.value,this.currentPage=1,this.fetchPage||(this.totalRows=this.filteredRows().length,this.paint())});const t=this.container.querySelector(".ds-table-page-size");t==null||t.addEventListener("change",()=>{this.currentPageSize=parseInt(t.value,10),this.currentPage=1,this.fetchPage?this.loadPage(1):(this.totalRows=this.filteredRows().length,this.paint())}),this.container.querySelectorAll("[data-action]").forEach(s=>{s.addEventListener("click",()=>{if(s.disabled)return;const r=Math.max(1,Math.ceil(this.totalRows/this.currentPageSize)),i=s.dataset.action;let a=this.currentPage;i==="first"?a=1:i==="prev"?a=Math.max(1,this.currentPage-1):i==="next"?a=Math.min(r,this.currentPage+1):i==="last"&&(a=r),(a!==this.currentPage||i==="first"||i==="last")&&(this.currentPage=a,this.fetchPage?this.loadPage(a):this.paint())})})}async loadPage(e){if(this.fetchPage){this.isLoading=!0,this.currentPage=e,this.paint();try{const t=await this.fetchPage(e,this.currentPageSize);this.currentRows=t.rows||[],this.totalRows=Number(t.total)||this.currentRows.length,this.currentPage=Number(t.page)||e}catch(t){console.error("[Deepspot SDK] TableRenderer: page fetch failed",t)}finally{this.isLoading=!1,this.paint()}}}getPageRows(){const e=(this.currentPage-1)*this.currentPageSize+1;if(this.fetchPage)return{rows:this.currentRows,startNum:e};const t=this.filteredRows(),s=(this.currentPage-1)*this.currentPageSize;return{rows:t.slice(s,s+this.currentPageSize),startNum:e}}filteredRows(){if(!this.searchTerm)return this.allData;const e=this.searchTerm.toLowerCase();return this.allData.filter(t=>this.columns.some(s=>{var r;return String((r=t[s])!=null?r:"").toLowerCase().includes(e)}))}formatHeader(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}formatValue(e){return e==null?"—":typeof e=="number"?e%1===0?e.toLocaleString():e.toFixed(2):String(e)}escape(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}}class C{render(e,t,s){const r=t.properties||{};let i=null;if(s&&s.length>0){const b=s[0],p=r.metric||Object.keys(b)[0],m=b[p];if(m!==void 0)i=m;else{const f=Object.keys(b).find(g=>g.includes(p)||p.includes(g));i=b[f!=null?f:Object.keys(b)[0]]}}const a=this.formatValue(i,r),o=r.backgroundColor||"",d=r.textColor||"",c=t.title||"",h=o?`background:${o};border-color:${o};`:"",l=d?`color:${d};`:"",n=d?`color:${d};opacity:0.7;`:"";e.innerHTML=`
50
- <div class="ds-card"${h?` style="${h}"`:""}>
51
- <div class="ds-card-label"${n?` style="${n}"`:""}>${c}</div>
52
- <div class="ds-card-value"${l?` style="${l}"`:""}>${a}</div>
53
- </div>
54
- `}formatValue(e,t){if(e==null)return"—";const s=Number(e);if(isNaN(s))return String(e);const r=(t==null?void 0:t.prefix)||(t==null?void 0:t.currencySymbol)||"",i=(t==null?void 0:t.suffix)||"";let a;return Math.abs(s)>=1e6?a=(s/1e6).toFixed(1)+"M":Math.abs(s)>=1e3?a=(s/1e3).toFixed(1)+"K":a=s%1===0?s.toLocaleString():s.toFixed(2),`${r}${a}${i}`}}class D{constructor(e,t){this.currentValues={},this.container=e,this.onFilterChange=t}render(e,t={}){if(!e||e.length===0){this.container.style.display="none";return}this.container.style.display="",this.currentValues={...t},this.container.innerHTML=`<div class="ds-filter-bar">${e.map(s=>this.renderFilter(s,t[s.applyToField||s.filterId])).join("")}</div>`,this.attachListeners(e)}updateOptions(e,t){const s=this.container.querySelector(`select[data-filter-id="${e}"]`);if(!s)return;const r=s.value;s.innerHTML='<option value="">All</option>'+t.map(i=>`<option value="${this.escAttr(i)}">${this.escText(i)}</option>`).join(""),r&&t.includes(r)&&(s.value=r)}updateValues(e){Object.assign(this.currentValues,e),Object.entries(e).forEach(([t,s])=>{const r=this.container.querySelector(`[data-filter-id="${t}"]`);r&&s!==void 0&&(r.value=String(s))})}renderFilter(e,t){const s=`ds-filter-${e.filterId}`,r=`<label class="ds-filter-label" for="${s}">${e.label}</label>`;switch(e.type){case"dropdown":return`
55
- <div class="ds-filter-item">
56
- ${r}
57
- <select class="ds-filter-select" id="${s}" data-filter-id="${e.filterId}">
58
- <option value="">All</option>
59
- ${(e.options||[]).map(o=>`
60
- <option value="${this.escAttr(o)}" ${t===o?"selected":""}>
61
- ${this.escText(o)}
62
- </option>
63
- `).join("")}
64
- </select>
65
- </div>`;case"multi-select":return`
66
- <div class="ds-filter-item">
67
- ${r}
68
- <select class="ds-filter-select" id="${s}" data-filter-id="${e.filterId}" multiple size="1">
69
- ${(e.options||[]).map(o=>`
70
- <option value="${this.escAttr(o)}">${this.escText(o)}</option>
71
- `).join("")}
72
- </select>
73
- </div>`;case"date-range":const i=(t==null?void 0:t.from)||"",a=(t==null?void 0:t.to)||"";return`
74
- <div class="ds-filter-item">
75
- ${r}
76
- <div class="ds-date-range-inputs">
77
- <input type="date" class="ds-filter-input"
78
- data-filter-id="${e.filterId}" data-date-part="from"
79
- value="${i}" />
80
- <span>–</span>
81
- <input type="date" class="ds-filter-input"
82
- data-filter-id="${e.filterId}" data-date-part="to"
83
- value="${a}" />
84
- </div>
85
- </div>`;case"text-input":return`
86
- <div class="ds-filter-item">
87
- ${r}
88
- <input type="text" class="ds-filter-input" id="${s}"
89
- data-filter-id="${e.filterId}"
90
- value="${this.escAttr(String(t!=null?t:""))}"
91
- placeholder="Search..." />
92
- </div>`;case"number-input":return`
93
- <div class="ds-filter-item">
94
- ${r}
95
- <input type="number" class="ds-filter-input" id="${s}"
96
- data-filter-id="${e.filterId}"
97
- value="${this.escAttr(String(t!=null?t:""))}" />
98
- </div>`;default:return""}}attachListeners(e){const t={};this.container.querySelectorAll("[data-filter-id]").forEach(s=>{const r=s.dataset.filterId,i=s.dataset.datePart,a=e.find(d=>d.filterId===r),o=()=>{let d;if((a==null?void 0:a.type)==="date-range"&&i)t[r]=t[r]||{},t[r][i]=s.value,d={...t[r]};else if((a==null?void 0:a.type)==="multi-select"){const c=s;d=Array.from(c.selectedOptions).map(h=>h.value).filter(Boolean)}else d=s.value;this.currentValues[r]=d,this.onFilterChange(r,d)};s.addEventListener((a==null?void 0:a.type)==="text-input"?"input":"change",o)})}escAttr(e){return e.replace(/"/g,"&quot;").replace(/'/g,"&#39;")}escText(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}}class O{constructor(e,t){this.activePageId="",this.activeTabId="",this.activeFilters={},this.chartRenderers=new Map,this.tableRenderer=new L,this.cardRenderer=new C,this.isLoadingTab=!1,this.root=e,this.opts=t,this.activeFilters={...t.initialFilters}}render(e){var t,s;this.renderData=e,this.activePageId=e.activePage,this.activeTabId=e.activeTab,this.buildShell(),this.renderNavigation(),this.renderFilterBar(),this.renderGrid(),(s=(t=this.opts).onReady)==null||s.call(t)}update(e){this.renderData=e,this.activePageId=e.activePage,this.activeTabId=e.activeTab,this.isLoadingTab=!1,this.syncNavHighlight(),this.updateFilterBar(),this.renderGrid()}goToPage(e){const t=this.getTabsForPage(e)[0];t&&this.triggerTabSwitch(e,t.id)}goToTab(e,t){this.triggerTabSwitch(e,t)}destroy(){this.chartRenderers.forEach(e=>e.destroy()),this.chartRenderers.clear(),this.root.innerHTML=""}exportPDF(){var n,b;const e=this.root.querySelector("#ds-grid");if(!e)return;const t=this.root.style.height,s=this.root.style.overflow;this.root.style.height="auto",this.root.style.overflow="visible";const r=this.root.querySelector("#ds-canvas"),i=(n=r==null?void 0:r.style.height)!=null?n:"",a=(b=r==null?void 0:r.style.overflow)!=null?b:"";r&&(r.style.height="auto",r.style.overflow="visible");const o=Array.from(e.querySelectorAll(".ds-table-scroll")),d=o.map(p=>({el:p,overflow:p.style.overflow,maxHeight:p.style.maxHeight,height:p.style.height}));o.forEach(p=>{p.style.overflow="visible",p.style.maxHeight="none",p.style.height="auto"});const c=e.offsetWidth,h=parseInt(e.style.height,10)||e.offsetHeight,l=e.getBoundingClientRect().top+window.scrollY;Promise.resolve().then(()=>require("./html2canvas.esm-EoNFmhrp.cjs")).then(({default:p})=>p(e,{scale:2,useCORS:!0,allowTaint:!0,logging:!1,width:c,height:h,windowWidth:c,windowHeight:h,scrollX:0,scrollY:-l}).then(m=>{this.root.style.height=t,this.root.style.overflow=s,r&&(r.style.height=i,r.style.overflow=a),d.forEach(({el:f,overflow:g,maxHeight:y,height:v})=>{f.style.overflow=g,f.style.maxHeight=y,f.style.height=v}),Promise.resolve().then(()=>require("./jspdf.es.min-D6GjoB2T.cjs")).then(f=>f.jspdf_es_min).then(({jsPDF:f})=>{const g=m.width/2,y=m.height/2,v=new f({orientation:g>=y?"landscape":"portrait",unit:"px",format:[g,y]});v.addImage(m.toDataURL("image/png"),"PNG",0,0,g,y),v.save(`${this.renderData.dashboard.name||"dashboard"}.pdf`)})}))}exportCSV(){this.renderData.components.forEach(e=>{const t=this.renderData.data[e.id];if(!(t!=null&&t.length)||!["table","bar","line","area"].includes(e.type))return;const s=Object.keys(t[0]),r=[s.join(","),...t.map(a=>s.map(o=>{var d;return JSON.stringify((d=a[o])!=null?d:"")}).join(","))].join(`
99
- `);Object.assign(document.createElement("a"),{href:URL.createObjectURL(new Blob([r],{type:"text/csv"})),download:`${e.title||e.id}.csv`}).click()})}updateFilterValues(e){var t;Object.assign(this.activeFilters,e),(t=this.filterRenderer)==null||t.updateValues(e)}buildShell(){const e=this.opts.embedLevel,t=this.renderData.dashboard.pages,s=e==="dashboard"&&t.length>1,r=e==="page"||e==="dashboard";this.root.innerHTML=`
100
- ${this.opts.hideExport?"":'<div class="ds-toolbar" id="ds-toolbar"></div>'}
101
- ${s?'<nav class="ds-page-nav" id="ds-page-nav"></nav>':""}
102
- ${r?'<nav class="ds-page-nav" id="ds-tab-nav"></nav>':""}
103
- <div id="ds-filter-container"></div>
104
- <div class="ds-canvas" id="ds-canvas">
105
- <div class="ds-grid" id="ds-grid"></div>
106
- </div>
107
- <div id="ds-tab-loading" style="display:none;position:absolute;inset:0;
108
- background:rgba(255,255,255,0.5);align-items:center;justify-content:center;">
109
- <div class="ds-embed-spinner"></div>
110
- </div>
111
- `,this.root.style.position="relative",this.opts.hideExport||this.buildExportToolbar();const i=this.root.querySelector("#ds-filter-container");this.filterRenderer=new D(i,(a,o)=>{var h,l;const d=this.renderData.filters.find(n=>n.filterId===a),c=(d==null?void 0:d.applyToField)||a;this.activeFilters[c]=o,(l=(h=this.opts).onFilterChange)==null||l.call(h,this.activeFilters),this.opts.onTabSwitch(this.activePageId,this.activeTabId)})}buildExportToolbar(){var t,s;const e=this.root.querySelector("#ds-toolbar");e&&(e.innerHTML=`
112
- <button class="ds-toolbar-btn" id="ds-btn-pdf">⬇ PDF</button>
113
- <button class="ds-toolbar-btn" id="ds-btn-csv" style="display:none">⬇ CSV</button>
114
- `,(t=e.querySelector("#ds-btn-pdf"))==null||t.addEventListener("click",()=>this.exportPDF()),(s=e.querySelector("#ds-btn-csv"))==null||s.addEventListener("click",()=>this.exportCSV()))}renderNavigation(){this.renderPageNav(),this.renderTabNav(this.activePageId)}renderPageNav(){const e=this.root.querySelector("#ds-page-nav");e&&(e.innerHTML=this.renderData.dashboard.pages.map(t=>`
115
- <button class="ds-page-tab ${t.pageId===this.activePageId?"ds-active":""}"
116
- data-page-id="${t.pageId}">${t.title}</button>
117
- `).join(""),e.querySelectorAll(".ds-page-tab").forEach(t=>{t.addEventListener("click",()=>{var r,i;const s=t.dataset.pageId;s===this.activePageId&&!this.isLoadingTab||this.triggerTabSwitch(s,(i=(r=this.getTabsForPage(s)[0])==null?void 0:r.id)!=null?i:"")})}))}renderTabNav(e){const t=this.root.querySelector("#ds-tab-nav");t&&this.buildTabButtons(t,e)}buildTabButtons(e,t){const s=this.getTabsForPage(t);if(s.length<=1){e.style.display="none";return}e.style.display="",e.innerHTML=s.map(r=>`
118
- <button class="ds-page-tab ${r.id===this.activeTabId?"ds-active":""}"
119
- data-tab-id="${r.id}" data-page-id="${t}">${r.title}</button>
120
- `).join(""),e.querySelectorAll(".ds-page-tab").forEach(r=>{r.addEventListener("click",()=>{const i=r.dataset.tabId,a=r.dataset.pageId;i===this.activeTabId&&a===this.activePageId&&!this.isLoadingTab||this.triggerTabSwitch(a,i)})})}triggerTabSwitch(e,t){this.isLoadingTab||!e||!t||(this.isLoadingTab=!0,this.activePageId=e,this.activeTabId=t,this.syncNavHighlight(),this.showTabSpinner(),this.opts.onTabSwitch(e,t))}syncNavHighlight(){this.root.querySelectorAll("#ds-page-nav .ds-page-tab").forEach(t=>{t.classList.toggle("ds-active",t.dataset.pageId===this.activePageId)});const e=this.root.querySelector("#ds-tab-nav");e&&this.buildTabButtons(e,this.activePageId)}renderFilterBar(){this.opts.hideFilters||(this.filterRenderer.render(this.renderData.filters,this.activeFilters),this.fetchFilterOptions())}updateFilterBar(){this.opts.hideFilters||(this.filterRenderer.render(this.renderData.filters,this.activeFilters),this.fetchFilterOptions())}async fetchFilterOptions(){if(this.opts.onFetchFilterOptions)for(const e of this.renderData.filters){if(e.type!=="dropdown"&&e.type!=="multi-select"||e.options&&e.options.length>0)continue;const t=await this.opts.onFetchFilterOptions(e.filterId);t.length>0&&this.filterRenderer.updateOptions(e.filterId,t)}}renderGrid(){this.hideTabSpinner();const e=this.root.querySelector("#ds-grid");if(!e)return;this.chartRenderers.forEach(c=>c.destroy()),this.chartRenderers.clear();const t=this.renderData.components;if(!t.length){e.style.height="200px",e.innerHTML='<div class="ds-chart-empty" style="padding-top:80px;">No components on this tab.</div>';return}const s=e.clientWidth||this.root.clientWidth||800,r=t.map(c=>c.position),i=r.length?Math.min(...r.map(c=>c.y)):0,a=new S(s,i);e.style.height=`${S.totalHeight(r)}px`,e.innerHTML="";const o=36,d=[];t.forEach(c=>{const h=document.createElement("div");h.className="ds-component-wrapper",h.dataset.componentId=c.id,a.applyStyles(h,c.position),e.appendChild(h);const l=a.toPx(c.position),n=Math.max(50,l.height-o);d.push(this.renderComponent(h,c,n))}),Promise.all(d).catch(()=>{})}async renderComponent(e,t,s){var a,o;const r=this.renderData.data[t.id]||[],i=this.opts.theme;switch(t.type){case"bar":case"line":case"pie":case"donut":case"area":{const d=new R(e);await d.render(t,r,i,s),this.chartRenderers.set(t.id,d);break}case"table":{const d=this.opts.onFetchTablePage?(c,h)=>this.opts.onFetchTablePage(t.id,c,h):void 0;this.tableRenderer.render(e,t,r,d);break}case"number-card":this.cardRenderer.render(e,t,r);break;case"text":{const d=Object.entries(((a=t.properties)==null?void 0:a.style)||{}).map(([c,h])=>`${c}:${h}`).join(";");e.innerHTML=`<div style="${d};padding:8px;">${((o=t.properties)==null?void 0:o.content)||""}</div>`;break}}}showTabSpinner(){const e=this.root.querySelector("#ds-tab-loading"),t=this.root.querySelector("#ds-grid");e&&(e.style.display="flex"),t&&(t.style.opacity="0.35")}hideTabSpinner(){const e=this.root.querySelector("#ds-tab-loading"),t=this.root.querySelector("#ds-grid");e&&(e.style.display="none"),t&&(t.style.opacity="1")}getTabsForPage(e){var t,s;return(s=(t=this.renderData.dashboard.pages.find(r=>r.pageId===e))==null?void 0:t.tabs)!=null?s:[]}}class z{constructor(e,t){this.chartRenderer=null,this.tableRenderer=new L,this.cardRenderer=new C,this.root=e,this.theme=t}render(e,t){const s=e.components[0];if(!s){this.root.innerHTML=`<div class="ds-embed-error">
121
- <div class="ds-embed-error-icon">⚠</div>
122
- <div>Component not found.</div>
123
- </div>`;return}const r=e.data[s.id]||[];this.renderComponent(s,r),t==null||t()}update(e){const t=e.components[0];if(!t)return;const s=e.data[t.id]||[];switch(t.type){case"bar":case"line":case"pie":case"donut":case"area":this.chartRenderer?this.chartRenderer.update(t,s,this.theme):this.renderComponent(t,s);break;case"table":this.tableRenderer.render(this.root,t,s);break;case"number-card":this.cardRenderer.render(this.root,t,s);break}}destroy(){var e;(e=this.chartRenderer)==null||e.destroy(),this.chartRenderer=null,this.root.innerHTML=""}renderComponent(e,t){var s;switch(e.type){case"bar":case"line":case"pie":case"donut":case"area":(s=this.chartRenderer)==null||s.destroy(),this.chartRenderer=new R(this.root),this.chartRenderer.render(e,t,this.theme);break;case"table":this.tableRenderer.render(this.root,e,t);break;case"number-card":this.cardRenderer.render(this.root,e,t);break;default:this.root.innerHTML=`<div class="ds-chart-empty">Unsupported component type: ${e.type}</div>`}}}let P=!1;function j(){if(!(P||typeof document=="undefined")){P=!0;try{const u=`/* ─────────────────────────────────────────────────────────────────────────────
124
- Deepspot SDK — Base Embed Styles
125
- Injected once into the host page's <head> by the SDK.
126
- All selectors are scoped under .ds-embed-* to avoid leaking into host styles.
127
- ───────────────────────────────────────────────────────────────────────────── */
128
-
129
- /* ── Reset inside SDK containers ──────────────────────────────────────────── */
130
- .ds-embed-root *,
131
- .ds-embed-root *::before,
132
- .ds-embed-root *::after {
133
- box-sizing: border-box;
134
- margin: 0;
135
- padding: 0;
136
- }
137
-
138
- /* ── Root container ────────────────────────────────────────────────────────── */
139
- .ds-embed-root {
140
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
141
- Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
142
- font-size: 14px;
143
- line-height: 1.5;
144
- width: 100%;
145
- height: 100%;
146
- overflow: auto;
147
- position: relative;
148
- }
149
-
150
- .ds-embed-root.ds-theme-light {
151
- background: #ffffff;
152
- color: #111827;
153
- }
154
-
155
- .ds-embed-root.ds-theme-dark {
156
- background: #0f172a;
157
- color: #f1f5f9;
158
- }
159
-
160
- /* ── Loading state ─────────────────────────────────────────────────────────── */
161
- .ds-embed-loading {
162
- display: flex;
163
- flex-direction: column;
164
- align-items: center;
165
- justify-content: center;
166
- height: 100%;
167
- min-height: 200px;
168
- gap: 12px;
169
- color: #6b7280;
170
- }
171
-
172
- .ds-embed-spinner {
173
- width: 36px;
174
- height: 36px;
175
- border: 3px solid #e5e7eb;
176
- border-top-color: #6366f1;
177
- border-radius: 50%;
178
- animation: ds-spin 0.8s linear infinite;
179
- }
180
-
181
- @keyframes ds-spin {
182
- to { transform: rotate(360deg); }
183
- }
184
-
185
- .ds-embed-loading-text {
186
- font-size: 13px;
187
- }
188
-
189
- /* ── Error state ───────────────────────────────────────────────────────────── */
190
- .ds-embed-error {
191
- display: flex;
192
- flex-direction: column;
193
- align-items: center;
194
- justify-content: center;
195
- height: 100%;
196
- min-height: 200px;
197
- gap: 8px;
198
- padding: 24px;
199
- text-align: center;
200
- color: #ef4444;
201
- }
202
-
203
- .ds-embed-error-icon {
204
- font-size: 32px;
205
- }
206
-
207
- .ds-embed-error-message {
208
- font-size: 13px;
209
- color: #6b7280;
210
- }
211
-
212
- /* ── Filter bar ────────────────────────────────────────────────────────────── */
213
- .ds-filter-bar {
214
- display: flex;
215
- flex-wrap: wrap;
216
- align-items: center;
217
- gap: 10px;
218
- padding: 10px 16px;
219
- border-bottom: 1px solid #e5e7eb;
220
- background: inherit;
221
- }
222
-
223
- .ds-theme-dark .ds-filter-bar {
224
- border-bottom-color: #1e293b;
225
- }
226
-
227
- .ds-filter-item {
228
- display: flex;
229
- flex-direction: column;
230
- gap: 4px;
231
- }
232
-
233
- .ds-filter-label {
234
- font-size: 11px;
235
- font-weight: 600;
236
- text-transform: uppercase;
237
- letter-spacing: 0.05em;
238
- color: #6b7280;
239
- }
240
-
241
- .ds-filter-select,
242
- .ds-filter-input {
243
- height: 32px;
244
- padding: 0 10px;
245
- border: 1px solid #d1d5db;
246
- border-radius: 6px;
247
- font-size: 13px;
248
- background: #ffffff;
249
- color: #111827;
250
- cursor: pointer;
251
- min-width: 130px;
252
- }
253
-
254
- .ds-theme-dark .ds-filter-select,
255
- .ds-theme-dark .ds-filter-input {
256
- background: #1e293b;
257
- border-color: #334155;
258
- color: #f1f5f9;
259
- }
260
-
261
- .ds-filter-select:focus,
262
- .ds-filter-input:focus {
263
- outline: none;
264
- border-color: #6366f1;
265
- box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
266
- }
267
-
268
- .ds-date-range-inputs {
269
- display: flex;
270
- gap: 6px;
271
- align-items: center;
272
- }
273
-
274
- .ds-date-range-inputs input[type="date"] {
275
- height: 32px;
276
- padding: 0 8px;
277
- border: 1px solid #d1d5db;
278
- border-radius: 6px;
279
- font-size: 13px;
280
- background: #ffffff;
281
- color: #111827;
282
- }
283
-
284
- .ds-theme-dark .ds-date-range-inputs input[type="date"] {
285
- background: #1e293b;
286
- border-color: #334155;
287
- color: #f1f5f9;
288
- }
289
-
290
- /* ── Page / Tab navigation ─────────────────────────────────────────────────── */
291
- .ds-page-nav {
292
- display: flex;
293
- gap: 4px;
294
- padding: 8px 16px 0;
295
- border-bottom: 1px solid #e5e7eb;
296
- overflow-x: auto;
297
- }
298
-
299
- .ds-theme-dark .ds-page-nav {
300
- border-bottom-color: #1e293b;
301
- }
302
-
303
- .ds-page-tab {
304
- padding: 6px 16px;
305
- font-size: 13px;
306
- font-weight: 500;
307
- border: none;
308
- border-bottom: 2px solid transparent;
309
- background: transparent;
310
- color: #6b7280;
311
- cursor: pointer;
312
- white-space: nowrap;
313
- transition: color 0.15s, border-color 0.15s;
314
- }
315
-
316
- .ds-page-tab:hover {
317
- color: #111827;
318
- }
319
-
320
- .ds-theme-dark .ds-page-tab:hover {
321
- color: #f1f5f9;
322
- }
323
-
324
- .ds-page-tab.ds-active {
325
- color: #6366f1;
326
- border-bottom-color: #6366f1;
327
- }
328
-
329
- /* ── Grid canvas ───────────────────────────────────────────────────────────── */
330
- .ds-canvas {
331
- position: relative;
332
- width: 100%;
333
- /* No horizontal padding — grid.clientWidth must equal container width so
334
- GridLayout.colWidth = containerWidth/24 matches the dashboard builder.
335
- 16px on each side was shrinking the grid by 32px and misaligning positions. */
336
- padding: 8px 0 16px;
337
- overflow-x: hidden;
338
- }
339
-
340
- .ds-grid {
341
- position: relative;
342
- width: 100%;
343
- /* Clip absolutely-positioned children to the grid boundary so rounding
344
- errors or miscalculated widths don't create a horizontal scrollbar. */
345
- overflow: hidden;
346
- }
347
-
348
- .ds-component-wrapper {
349
- position: absolute;
350
- overflow: hidden;
351
- }
352
-
353
- /* ── Chart component ───────────────────────────────────────────────────────── */
354
- .ds-chart-card {
355
- width: 100%;
356
- height: 100%;
357
- background: #ffffff;
358
- border: 1px solid #e5e7eb;
359
- border-radius: 10px;
360
- overflow: hidden;
361
- display: flex;
362
- flex-direction: column;
363
- }
364
-
365
- .ds-theme-dark .ds-chart-card {
366
- background: #1e293b;
367
- border-color: #334155;
368
- }
369
-
370
- .ds-chart-title {
371
- padding: 10px 14px 4px;
372
- font-size: 13px;
373
- font-weight: 600;
374
- color: #374151;
375
- flex-shrink: 0;
376
- }
377
-
378
- .ds-theme-dark .ds-chart-title {
379
- color: #e2e8f0;
380
- }
381
-
382
- .ds-chart-body {
383
- flex: 1;
384
- min-height: 0;
385
- }
386
-
387
- .ds-chart-empty {
388
- display: flex;
389
- align-items: center;
390
- justify-content: center;
391
- height: 100%;
392
- color: #9ca3af;
393
- font-size: 13px;
394
- }
395
-
396
- /* ── Table component ───────────────────────────────────────────────────────── */
397
- .ds-table-card {
398
- width: 100%;
399
- height: 100%;
400
- background: #ffffff;
401
- border: 1px solid #e5e7eb;
402
- border-radius: 10px;
403
- overflow: hidden;
404
- display: flex;
405
- flex-direction: column;
406
- position: relative;
407
- }
408
-
409
- .ds-theme-dark .ds-table-card {
410
- background: #1e293b;
411
- border-color: #334155;
412
- }
413
-
414
- /* ── Table header: dot + title on left, search on right ──────────────────────*/
415
- .ds-table-header-row {
416
- display: flex;
417
- align-items: center;
418
- justify-content: space-between;
419
- padding: 10px 14px 8px;
420
- flex-shrink: 0;
421
- gap: 8px;
422
- border-bottom: 1px solid #f3f4f6;
423
- }
424
-
425
- .ds-theme-dark .ds-table-header-row {
426
- border-bottom-color: #334155;
427
- }
428
-
429
- .ds-table-title-wrap {
430
- display: flex;
431
- align-items: center;
432
- gap: 6px;
433
- min-width: 0;
434
- }
435
-
436
- .ds-table-dot {
437
- width: 8px;
438
- height: 8px;
439
- border-radius: 50%;
440
- background: #6366f1;
441
- flex-shrink: 0;
442
- }
443
-
444
- .ds-table-title {
445
- font-size: 13px;
446
- font-weight: 600;
447
- color: #374151;
448
- white-space: nowrap;
449
- overflow: hidden;
450
- text-overflow: ellipsis;
451
- }
452
-
453
- .ds-theme-dark .ds-table-title {
454
- color: #e2e8f0;
455
- }
456
-
457
- /* ── Search ──────────────────────────────────────────────────────────────────*/
458
- .ds-table-search-wrap {
459
- position: relative;
460
- flex-shrink: 0;
461
- }
462
-
463
- .ds-table-search-icon {
464
- position: absolute;
465
- left: 8px;
466
- top: 50%;
467
- transform: translateY(-50%);
468
- width: 14px;
469
- height: 14px;
470
- color: #9ca3af;
471
- pointer-events: none;
472
- }
473
-
474
- .ds-table-search {
475
- height: 30px;
476
- padding: 0 10px 0 28px;
477
- border: 1px solid #e5e7eb;
478
- border-radius: 6px;
479
- font-size: 12px;
480
- background: #f9fafb;
481
- color: #374151;
482
- width: 180px;
483
- outline: none;
484
- transition: border-color 0.15s, box-shadow 0.15s;
485
- }
486
-
487
- .ds-table-search:focus {
488
- border-color: #6366f1;
489
- box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
490
- background: #fff;
491
- }
492
-
493
- .ds-theme-dark .ds-table-search {
494
- background: #0f172a;
495
- border-color: #334155;
496
- color: #e2e8f0;
497
- }
498
-
499
- .ds-theme-dark .ds-table-search:focus {
500
- background: #1e293b;
501
- }
502
-
503
- /* ── Scroll area ─────────────────────────────────────────────────────────────*/
504
- .ds-table-scroll {
505
- flex: 1;
506
- overflow: auto;
507
- min-height: 0;
508
- }
509
-
510
- .ds-table {
511
- width: 100%;
512
- border-collapse: collapse;
513
- font-size: 12px;
514
- }
515
-
516
- .ds-table-sno-th {
517
- width: 48px;
518
- text-align: center !important;
519
- }
520
-
521
- .ds-table-sno {
522
- text-align: center;
523
- color: #9ca3af;
524
- font-size: 11px;
525
- }
526
-
527
- .ds-theme-dark .ds-table-sno {
528
- color: #64748b;
529
- }
530
-
531
- .ds-table th {
532
- position: sticky;
533
- top: 0;
534
- padding: 8px 12px;
535
- text-align: left;
536
- font-weight: 600;
537
- font-size: 11px;
538
- text-transform: uppercase;
539
- letter-spacing: 0.05em;
540
- background: #f9fafb;
541
- color: #6b7280;
542
- border-bottom: 1px solid #e5e7eb;
543
- white-space: nowrap;
544
- }
545
-
546
- .ds-theme-dark .ds-table th {
547
- background: #0f172a;
548
- color: #94a3b8;
549
- border-bottom-color: #334155;
550
- }
551
-
552
- .ds-table td {
553
- padding: 8px 12px;
554
- border-bottom: 1px solid #f3f4f6;
555
- color: #374151;
556
- max-width: 200px;
557
- overflow: hidden;
558
- text-overflow: ellipsis;
559
- white-space: nowrap;
560
- }
561
-
562
- .ds-theme-dark .ds-table td {
563
- color: #cbd5e1;
564
- border-bottom-color: #1e293b;
565
- }
566
-
567
- .ds-table tr:hover td {
568
- background: #f9fafb;
569
- }
570
-
571
- .ds-theme-dark .ds-table tr:hover td {
572
- background: #0f172a;
573
- }
574
-
575
- /* ── Footer: info + pagination ───────────────────────────────────────────────*/
576
- .ds-table-footer {
577
- display: flex;
578
- align-items: center;
579
- justify-content: space-between;
580
- padding: 8px 14px;
581
- border-top: 1px solid #f3f4f6;
582
- flex-shrink: 0;
583
- gap: 8px;
584
- flex-wrap: wrap;
585
- }
586
-
587
- .ds-theme-dark .ds-table-footer {
588
- border-top-color: #334155;
589
- }
590
-
591
- .ds-table-info {
592
- display: flex;
593
- align-items: center;
594
- gap: 8px;
595
- font-size: 12px;
596
- color: #6b7280;
597
- }
598
-
599
- .ds-theme-dark .ds-table-info {
600
- color: #94a3b8;
601
- }
602
-
603
- .ds-table-rows-label {
604
- margin-left: 4px;
605
- }
606
-
607
- .ds-table-page-size {
608
- height: 28px;
609
- padding: 0 6px;
610
- border: 1px solid #e5e7eb;
611
- border-radius: 5px;
612
- font-size: 12px;
613
- background: #fff;
614
- color: #374151;
615
- cursor: pointer;
616
- outline: none;
617
- }
618
-
619
- .ds-theme-dark .ds-table-page-size {
620
- background: #0f172a;
621
- border-color: #334155;
622
- color: #e2e8f0;
623
- }
624
-
625
- .ds-table-pagination {
626
- display: flex;
627
- align-items: center;
628
- gap: 6px;
629
- }
630
-
631
- .ds-table-pg-btn {
632
- height: 28px;
633
- padding: 0 10px;
634
- border: 1px solid #e5e7eb;
635
- border-radius: 5px;
636
- font-size: 12px;
637
- font-weight: 500;
638
- background: #fff;
639
- color: #374151;
640
- cursor: pointer;
641
- transition: background 0.12s, border-color 0.12s;
642
- white-space: nowrap;
643
- }
644
-
645
- .ds-table-pg-btn:hover:not(:disabled) {
646
- background: #f3f4f6;
647
- border-color: #d1d5db;
648
- }
649
-
650
- .ds-table-pg-btn:disabled {
651
- opacity: 0.4;
652
- cursor: not-allowed;
653
- }
654
-
655
- .ds-theme-dark .ds-table-pg-btn {
656
- background: #1e293b;
657
- border-color: #334155;
658
- color: #e2e8f0;
659
- }
660
-
661
- .ds-theme-dark .ds-table-pg-btn:hover:not(:disabled) {
662
- background: #0f172a;
663
- }
664
-
665
- .ds-table-pg-info {
666
- font-size: 12px;
667
- color: #6b7280;
668
- white-space: nowrap;
669
- }
670
-
671
- .ds-theme-dark .ds-table-pg-info {
672
- color: #94a3b8;
673
- }
674
-
675
- /* ── Loading overlay while fetching a page ───────────────────────────────────*/
676
- .ds-table-loading-overlay {
677
- position: absolute;
678
- inset: 0;
679
- background: rgba(255,255,255,0.6);
680
- display: flex;
681
- align-items: center;
682
- justify-content: center;
683
- border-radius: 10px;
684
- z-index: 10;
685
- }
686
-
687
- .ds-theme-dark .ds-table-loading-overlay {
688
- background: rgba(30,41,59,0.7);
689
- }
690
-
691
- /* ── KPI Number Card ───────────────────────────────────────────────────────── */
692
- .ds-card {
693
- width: 100%;
694
- height: 100%;
695
- border: 1px solid #e5e7eb;
696
- border-radius: 10px;
697
- display: flex;
698
- flex-direction: column;
699
- align-items: center;
700
- justify-content: center;
701
- padding: 16px;
702
- text-align: center;
703
- background: #ffffff;
704
- }
705
-
706
- .ds-theme-dark .ds-card {
707
- background: #1e293b;
708
- border-color: #334155;
709
- }
710
-
711
- .ds-card-label {
712
- font-size: 12px;
713
- font-weight: 500;
714
- color: #6b7280;
715
- margin-bottom: 6px;
716
- text-transform: uppercase;
717
- letter-spacing: 0.05em;
718
- }
719
-
720
- .ds-card-value {
721
- font-size: 32px;
722
- font-weight: 700;
723
- color: #111827;
724
- line-height: 1.1;
725
- }
726
-
727
- .ds-theme-dark .ds-card-value {
728
- color: #f1f5f9;
729
- }
730
-
731
- /* ── Export toolbar ────────────────────────────────────────────────────────── */
732
- .ds-toolbar {
733
- display: flex;
734
- justify-content: flex-end;
735
- padding: 8px 16px 0;
736
- gap: 8px;
737
- }
738
-
739
- .ds-toolbar-btn {
740
- height: 30px;
741
- padding: 0 12px;
742
- border: 1px solid #d1d5db;
743
- border-radius: 6px;
744
- font-size: 12px;
745
- font-weight: 500;
746
- background: #ffffff;
747
- color: #374151;
748
- cursor: pointer;
749
- display: flex;
750
- align-items: center;
751
- gap: 5px;
752
- transition: background 0.15s, border-color 0.15s;
753
- }
754
-
755
- .ds-toolbar-btn:hover {
756
- background: #f9fafb;
757
- border-color: #9ca3af;
758
- }
759
-
760
- .ds-theme-dark .ds-toolbar-btn {
761
- background: #1e293b;
762
- border-color: #334155;
763
- color: #e2e8f0;
764
- }
765
-
766
- .ds-theme-dark .ds-toolbar-btn:hover {
767
- background: #0f172a;
768
- }
769
- `,e=document.createElement("style");e.id="deepspot-sdk-styles",e.textContent=u,document.head.appendChild(e)}catch(u){}}}function I(u){if(typeof u=="string"){const e=document.querySelector(u);if(!e)throw new Error(`Deepspot SDK: container "${u}" not found in DOM`);return e}return u}class M{constructor(e){if(!e.apiKey)throw new Error("Deepspot SDK: apiKey is required");if(!e.baseUrl)throw new Error("Deepspot SDK: baseUrl is required");this.apiClient=new F(e.baseUrl,e.apiKey),j()}async embedDashboard(e){var a,o,d,c,h;const t=I(e.container),s=(a=e.embedLevel)!=null?a:"dashboard",r=(o=e.theme)!=null?o:"light";t.style.height=e.height||"600px",t.style.display="block";const i=this.createRoot(t,r);this.showLoading(i);try{const l=await this.apiClient.getEmbedToken({dashboardId:e.dashboardId,embedType:"dashboard",embedLevel:s,userId:e.userId,tenantId:e.tenantId}),n=await this.apiClient.getDashboardRender(e.dashboardId,l,{embedLevel:s,pageId:e.pageId,tabId:e.tabId,filters:e.filters||{}});let b;const p=new O(i,{embedLevel:s,theme:r,hideFilters:(d=e.hideFilters)!=null?d:!1,hideExport:(c=e.hideExport)!=null?c:!1,initialFilters:e.filters||{},onFilterChange:e.onFilterChange,onReady:e.onReady,onFetchFilterOptions:m=>this.apiClient.getFilterOptions(e.dashboardId,m,l),onFetchTablePage:(m,f,g)=>this.apiClient.getTablePage(e.dashboardId,m,f,g,l),onTabSwitch:async(m,f)=>{var g,y,v;(g=e.onTabSwitch)==null||g.call(e,m,f);try{const x=await this.apiClient.getDashboardRender(e.dashboardId,l,{embedLevel:s,pageId:m,tabId:f,filters:(v=(y=b==null?void 0:b.getActiveFilters())!=null?y:e.filters)!=null?v:{}});p.update(x)}catch(x){console.error("Deepspot SDK: tab fetch failed",x)}}});return p.render(n),b=new $({dashboardId:e.dashboardId,token:l,embedType:"dashboard",embedLevel:s,activePageId:n.activePage,activeTabId:n.activeTab,activeFilters:e.filters||{},apiClient:this.apiClient,renderer:p,onFilterChange:e.onFilterChange}),b}catch(l){throw this.showError(i,(l==null?void 0:l.message)||"Failed to load dashboard"),(h=e.onError)==null||h.call(e,(l==null?void 0:l.message)||"Failed to load dashboard"),l}}async embedReport(e){var r;const t=I(e.container);t.style.height=e.height||"400px",t.style.display="block";const s=this.createRoot(t,e.theme||"light");this.showLoading(s);try{const i=await this.apiClient.getEmbedToken({dashboardId:e.dashboardId,embedType:"report",componentId:e.componentId,userId:e.userId,tenantId:e.tenantId}),a=await this.apiClient.getReportRender(e.dashboardId,e.componentId,i,{filters:e.filters||{}}),o=new z(s,e.theme||"light");return o.render(a,e.onReady),new $({dashboardId:e.dashboardId,componentId:e.componentId,token:i,embedType:"report",activeFilters:e.filters||{},apiClient:this.apiClient,renderer:o})}catch(i){throw this.showError(s,(i==null?void 0:i.message)||"Failed to load report"),(r=e.onError)==null||r.call(e,(i==null?void 0:i.message)||"Failed to load report"),i}}createRoot(e,t){e.innerHTML="";const s=document.createElement("div");return s.className=`ds-embed-root ds-theme-${t}`,s.style.width="100%",s.style.height="100%",e.appendChild(s),s}showLoading(e){e.innerHTML=`
770
- <div class="ds-embed-loading">
771
- <div class="ds-embed-spinner"></div>
772
- <div class="ds-embed-loading-text">Loading…</div>
773
- </div>
774
- `}showError(e,t){e.innerHTML=`
775
- <div class="ds-embed-error">
776
- <div class="ds-embed-error-icon">⚠</div>
777
- <div>${t}</div>
778
- <div class="ds-embed-error-message">Check your SDK configuration.</div>
779
- </div>
780
- `}}exports.DeepspotSDK=M;