react-semaphor 0.1.320 → 0.1.322
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/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +4 -4
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +278 -208
- package/dist/chunks/{braces-NfG5hX2c.js → braces-C7BeIXvM.js} +1 -1
- package/dist/chunks/{braces-CDPz6CF2.js → braces-ZjRH2Kl7.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-CFXQBJ4A.js → calendar-preferences-dialog-CZqePF6B.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-B7Z8OnuZ.js → calendar-preferences-dialog-t0OOALVd.js} +3 -3
- package/dist/chunks/{chevrons-up-down-BsdQRmJL.js → chevrons-up-down-CA-XvN1o.js} +1 -1
- package/dist/chunks/{chevrons-up-down-DiWloubI.js → chevrons-up-down-Cuilz9aY.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-DB16djcj.js → dashboard-briefing-launcher-BYbnbZ9e.js} +933 -910
- package/dist/chunks/{dashboard-briefing-launcher-DjDpGyD7.js → dashboard-briefing-launcher-d1_fm91W.js} +17 -17
- package/dist/chunks/dashboard-controls-B3HHMRPC.js +52 -0
- package/dist/chunks/dashboard-controls-BuChCKDm.js +2246 -0
- package/dist/chunks/{dashboard-json-C8-kkiyT.js → dashboard-json-DgoYjD0O.js} +2 -2
- package/dist/chunks/{dashboard-json-2nyFJ_-w.js → dashboard-json-M5-VFCtZ.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-BP77bJFI.js → edit-dashboard-visual-BH8DP1qq.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-D6oiTlXr.js → edit-dashboard-visual-DP31ytwJ.js} +6 -6
- package/dist/chunks/{index-Clw0hJzi.js → index-ChmS5nsv.js} +28873 -28145
- package/dist/chunks/{index-D8eouWYC.js → index-CodH6sqg.js} +217 -212
- package/dist/chunks/{palette-CJTdBzJB.js → palette-CanPG11m.js} +1 -1
- package/dist/chunks/{palette-BlxLchHy.js → palette-D96DOM7E.js} +1 -1
- package/dist/chunks/resource-management-panel-D3vO68dH.js +6 -0
- package/dist/chunks/{resource-management-panel-HcRJRZHO.js → resource-management-panel-gt__S0Pb.js} +451 -369
- package/dist/chunks/{save-B8x5Vi0W.js → save-CqrBQKG6.js} +1 -1
- package/dist/chunks/{save-DVRQBMeb.js → save-DxkSzUTZ.js} +1 -1
- package/dist/chunks/{switch-DPaKnsb8.js → switch-BXICAlvS.js} +2 -2
- package/dist/chunks/{switch-sauemjyY.js → switch-Deo2Ltmj.js} +133 -133
- package/dist/chunks/{use-create-flow-overlay-state-CdCldE6J.js → use-create-flow-overlay-state-BZaSpL-c.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-75l5mrVp.js → use-create-flow-overlay-state-OA3iI54p.js} +104 -104
- package/dist/chunks/{use-visual-utils-CMdEUnM5.js → use-visual-utils-CMucAqbS.js} +1 -1
- package/dist/chunks/{use-visual-utils-Bd4Cf9_B.js → use-visual-utils-CsXS-Zeh.js} +20 -20
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +3 -0
- package/dist/dashboard-authoring/index.js +532 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +131 -130
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/briefings.d.ts +15 -0
- package/dist/types/dashboard-authoring.d.ts +2703 -0
- package/dist/types/main.d.ts +145 -0
- package/package.json +6 -1
- package/dist/chunks/dashboard-controls-BisfskDD.js +0 -52
- package/dist/chunks/dashboard-controls-DPStW1kd.js +0 -1999
- package/dist/chunks/resource-management-panel-DTvY5OIq.js +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("./index-
|
|
1
|
+
"use strict";const u=require("./index-CodH6sqg.js"),f=require("./switch-BXICAlvS.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { H as ne, E as ie, u as
|
|
1
|
+
import { ac as X, u as Y, ad as Z, ae as ee, af as te, ag as re, ah as se, ai as ae, o as V, aj as oe } from "./index-ChmS5nsv.js";
|
|
2
|
+
import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-Deo2Ltmj.js";
|
|
3
3
|
import { useState as z, useEffect as de, useCallback as A } from "react";
|
|
4
4
|
function le(e) {
|
|
5
5
|
const [a, s] = z(null), [r, t] = z(null), o = X();
|
|
@@ -69,7 +69,7 @@ function ue(e, a) {
|
|
|
69
69
|
return e[0].id;
|
|
70
70
|
}
|
|
71
71
|
const M = /* @__PURE__ */ new Set();
|
|
72
|
-
function
|
|
72
|
+
function we(e) {
|
|
73
73
|
return M.add(e), () => {
|
|
74
74
|
M.delete(e);
|
|
75
75
|
};
|
|
@@ -178,7 +178,7 @@ function pe() {
|
|
|
178
178
|
};
|
|
179
179
|
}, [a]) };
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function be() {
|
|
182
182
|
const { authToken: e, tokenProps: a } = Y(), s = Z(), r = ee(), t = te(), { selectVisual: o } = re(), {
|
|
183
183
|
setFrame: l,
|
|
184
184
|
setCard: n,
|
|
@@ -193,23 +193,23 @@ function we() {
|
|
|
193
193
|
setSelectedTableName: p,
|
|
194
194
|
setSelectedDatamodelId: g,
|
|
195
195
|
setFilterValues: P,
|
|
196
|
-
setInlineFilterValuesMap:
|
|
197
|
-
setApplyFilters:
|
|
198
|
-
clearEditorContext:
|
|
196
|
+
setInlineFilterValuesMap: j,
|
|
197
|
+
setApplyFilters: D,
|
|
198
|
+
clearEditorContext: L
|
|
199
199
|
} = ne(), {
|
|
200
200
|
setIsDashboardEditing: U,
|
|
201
|
-
setIsVisualEditing:
|
|
201
|
+
setIsVisualEditing: T,
|
|
202
202
|
setSelectedFrameId: k,
|
|
203
203
|
clearSelectedFrameId: N,
|
|
204
204
|
setIsDashboardPanelOpen: W
|
|
205
|
-
} = ie(), E =
|
|
205
|
+
} = ie(), E = b((c) => c.selectedSheetId), $ = b((c) => c.selectedFrameId), R = b((c) => c.dashboard), x = b((c) => c.filterValues), O = b(
|
|
206
206
|
(c) => c.inlineFilterValuesMap
|
|
207
207
|
), S = se((t == null ? void 0 : t.id) || "", {
|
|
208
208
|
enabled: !!(t != null && t.id) && !!(e != null && e.accessToken)
|
|
209
209
|
}), G = A(
|
|
210
210
|
async (c) => {
|
|
211
211
|
try {
|
|
212
|
-
o(c), N(),
|
|
212
|
+
o(c), N(), L();
|
|
213
213
|
const { data: u, fromCache: v } = await Q(
|
|
214
214
|
a.apiServiceUrl,
|
|
215
215
|
(e == null ? void 0 : e.accessToken) || "",
|
|
@@ -230,10 +230,10 @@ function we() {
|
|
|
230
230
|
setSelectedTableName: p,
|
|
231
231
|
setSelectedDatamodelId: g,
|
|
232
232
|
setFilterValues: P,
|
|
233
|
-
setInlineFilterValuesMap:
|
|
234
|
-
setApplyFilters:
|
|
233
|
+
setInlineFilterValuesMap: j,
|
|
234
|
+
setApplyFilters: D,
|
|
235
235
|
setIsDashboardEditing: U,
|
|
236
|
-
setIsVisualEditing:
|
|
236
|
+
setIsVisualEditing: T,
|
|
237
237
|
dashboard: R,
|
|
238
238
|
selectedSheetId: E,
|
|
239
239
|
selectedFrameId: $,
|
|
@@ -254,7 +254,7 @@ function we() {
|
|
|
254
254
|
l,
|
|
255
255
|
n,
|
|
256
256
|
U,
|
|
257
|
-
|
|
257
|
+
T,
|
|
258
258
|
i,
|
|
259
259
|
f,
|
|
260
260
|
h,
|
|
@@ -266,9 +266,9 @@ function we() {
|
|
|
266
266
|
p,
|
|
267
267
|
g,
|
|
268
268
|
P,
|
|
269
|
+
j,
|
|
269
270
|
D,
|
|
270
271
|
L,
|
|
271
|
-
T,
|
|
272
272
|
N,
|
|
273
273
|
R,
|
|
274
274
|
E,
|
|
@@ -291,11 +291,11 @@ function we() {
|
|
|
291
291
|
), _ = (d == null ? void 0 : d.frameObject) ?? ((v = d == null ? void 0 : d.visual) == null ? void 0 : v.frameObject);
|
|
292
292
|
if (!_)
|
|
293
293
|
return u("Visual has no frame data");
|
|
294
|
-
const
|
|
295
|
-
if (!(
|
|
294
|
+
const w = q(_);
|
|
295
|
+
if (!(w != null && w.cards) || w.cards.length === 0)
|
|
296
296
|
return u("Visual frame is malformed");
|
|
297
297
|
const B = {
|
|
298
|
-
...ae(
|
|
298
|
+
...ae(w),
|
|
299
299
|
visualId: c.id
|
|
300
300
|
// Link this frame to the library visual
|
|
301
301
|
};
|
|
@@ -335,6 +335,6 @@ function we() {
|
|
|
335
335
|
}
|
|
336
336
|
export {
|
|
337
337
|
fe as f,
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
we as r,
|
|
339
|
+
be as u
|
|
340
340
|
};
|
package/dist/dashboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-CodH6sqg.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
|
package/dist/dashboard/index.js
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=["lg","md","sm","xs","xxs"],_=10;function c(t,a,e){return e?{code:t,message:a,cardId:e}:{code:t,message:a}}function v(t){const a=new Set;for(const e of t){if(a.has(e))return e;a.add(e)}return null}function C(t){var I,k;const a=[];if(!t||typeof t!="object")return{ok:!1,errors:[c("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const e=t,s=[...e.warnings||[]];e.version!==1&&a.push(c("invalid_version","Dashboard plan version must be 1.")),(I=e.title)!=null&&I.trim()||a.push(c("missing_title","Dashboard plan needs a title."));const n=Array.isArray(e.datasets)?e.datasets:[],d=Array.isArray(e.sheets)?e.sheets:[];n.length!==1&&a.push(c("invalid_dataset_count","MVP dashboard authoring requires exactly one selected dataset.")),d.length!==1&&a.push(c("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=d[0];i&&i.kind!=="dashboard"&&a.push(c("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const l=(i==null?void 0:i.cards)||[];l.length>_&&a.push(c("too_many_cards",`Generated dashboards can contain at most ${_} cards.`));const r=v(l.map(p=>p.id));r&&a.push(c("duplicate_card_id",`Duplicate generated card id: ${r}.`));const u=v(l.map(p=>p.frameId));u&&a.push(c("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const p of l)(k=p.title)!=null&&k.trim()||a.push(c("missing_card_title","Card title is required.",p.id)),p.type==="custom"&&a.push(c("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",p.id)),p.type!=="text"&&!p.query&&s.push(c("missing_query_intent","Non-text card has no query intent and may be skipped by the app layer.",p.id));const f=Array.isArray(e.filterInputs)?e.filterInputs:[],b=f.map(p=>p.id),m=v(b);m&&a.push(c("duplicate_input_id",`Duplicate dashboard input id: ${m}.`));const o=f.map(p=>p.variableName).filter(Boolean)||[],h=v(o);h&&a.push(c("duplicate_input_variable",`Duplicate dashboard input variable name: ${h}.`));const y=Array.isArray(e.calculatedFields)?e.calculatedFields:[];for(const p of y)p.scope==="domain"&&p.reuseOnly!==!0&&a.push(c("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${p.name}" is outside MVP.`));return{ok:a.length===0,errors:a,warnings:s}}function F(t){var i;const a=[];if(!t||typeof t!="object")return{ok:!1,errors:[c("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const e=t,s=[...e.warnings||[]];e.version!==1&&a.push(c("invalid_version","Dashboard change plan version must be 1.")),(i=e.dashboardId)!=null&&i.trim()||a.push(c("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const n=Array.isArray(e.datasets)?e.datasets:[],d=Array.isArray(e.operations)?e.operations:[];n.length>1&&a.push(c("invalid_dataset_count","MVP dashboard refinement can ground new AI operations in at most one selected dataset."));for(const l of d){if(l.kind==="unsupported"){s.push(c("unsupported_operation",l.reason||l.requestedAction));continue}l.kind==="addCard"&&l.card.type==="custom"&&a.push(c("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.card.id)),l.kind==="addCalculatedField"&&l.field.scope==="domain"&&l.field.reuseOnly!==!0&&a.push(c("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.field.name}" is outside MVP.`))}return{ok:a.length===0,errors:a,warnings:s}}const O={lg:48,md:36,sm:24,xs:12,xxs:6};function M(t){switch(t){case"kpi":return{w:12,h:12,minW:8,minH:8};case"table":return{w:48,h:28,minW:12,minH:12};case"text":return{w:48,h:10,minW:12,minH:8};case"chart":default:return{w:24,h:24,minW:12,minH:10}}}function R(t,a){let e=0,s=0,n=0;return t.map(d=>{const i=Math.min(d.w,a);e>0&&e+i>a&&(e=0,s+=n,n=0);const l={i:d.frameId,x:e,y:s,w:i,h:d.h,minW:Math.min(d.minW,a),minH:d.minH,static:!1};return e+=i,n=Math.max(n,d.h),l})}function w(t){const a=[...t].sort((e,s)=>e.priority-s.priority).map(e=>({...e,...M(e.role)}));return Object.fromEntries(A.map(e=>{const s=O[e],n=e==="lg"||e==="md"?a:a.map(d=>({...d,w:s,minW:Math.min(d.minW,s)}));return[e,R(n,s)]}))}function N(t,a,e){return e?{code:t,message:a,cardId:e}:{code:t,message:a}}function S(t,a,e){const s=(a||[]).filter(n=>n.scope==="card"&&n.targetCardId===e).map(n=>n.field).filter(Boolean);return s.length===0?t:{...t,calculatedFields:[...t.calculatedFields||[],...s]}}function V(t){const a={};return{inputs:(t.filterInputs||[]).map((s,n)=>(s.defaultValue!==void 0&&(a.shared??(a.shared={}),a.shared[s.id]={status:"set",value:{kind:"filter",filterValue:s.defaultValue}}),{id:s.id,kind:"filter",label:s.label,variableName:s.variableName,scope:{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:n},exports:["label","value","start","end","range"],filter:s.filter})),defaultInputValues:a.shared&&Object.keys(a.shared).length>0?a:void 0}}function E(t){var b,m;const a=C(t.plan);if(!a.ok)throw new Error(a.errors.map(o=>o.message).join(`
|
|
2
|
+
`)||"Dashboard plan is invalid.");const e=t.plan.sheets[0],s=[...a.warnings],n=[],d=new Map(t.cardArtifacts.map(o=>[o.planCardId,o])),i=[];for(const o of e.cards){const h=d.get(o.id);if(!h){const I=N("missing_card_artifact",`Card "${o.title}" was skipped because no generated artifact was supplied.`,o.id);n.push(I);continue}s.push(...h.warnings||[]);const y=S(h.card,t.plan.calculatedFields,o.id);i.push({id:o.frameId,cards:[y],activeCardId:y.id})}if(i.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:l,defaultInputValues:r}=V(t.plan),u=w(e.cards.filter(o=>i.some(h=>h.id===o.frameId)).map(o=>({frameId:o.frameId,priority:o.priority,role:o.role})));return{dashboard:{id:t.dashboardId,title:t.plan.title,description:t.plan.description||"",sheets:[{id:e.id,kind:"dashboard",title:e.title,description:e.description,frames:i,layouts:u,calculatedFields:(b=t.plan.calculatedFields)==null?void 0:b.filter(o=>o.scope==="sheet"&&o.field).map(o=>o.field)}],calculatedFields:(m=t.plan.calculatedFields)==null?void 0:m.filter(o=>o.scope==="dashboard"&&o.field).map(o=>o.field),inputs:l,...r?{defaultInputValues:r}:{}},warnings:s,skippedOperations:n}}function g(t,a,e){return e?{code:t,message:a,cardId:e}:{code:t,message:a}}function H(t){return JSON.parse(JSON.stringify(t))}function $(t){var a;return(a=t.sheets)==null?void 0:a.find(e=>(e.kind||"dashboard")==="dashboard")}function D(t,a){var e;for(const s of t.sheets||[])for(const n of s.frames||[]){const d=(e=n.cards)==null?void 0:e.find(i=>i.id===a);if(d)return{sheet:s,frame:n,card:d}}return null}function x(t){var e,s;const a=(s=(e=t.cards)==null?void 0:e[0])==null?void 0:s.type;return a==="kpi"?"kpi":a==="table"||a==="detailTable"||a==="pivotTable"?"table":a==="text"?"text":"chart"}function T(t){var a;return new Map((((a=t.layouts)==null?void 0:a.lg)||[]).map((e,s)=>[e.i,s]))}function P(t,a=new Map){const e=T(t),s=Math.max(e.size,a.size),n=(t.frames||[]).map((d,i)=>({frameId:d.id,role:x(d),priority:a.get(d.id)??e.get(d.id)??s+i}));t.layouts=w(n)}function B(t){return Object.values(t.layouts||{}).some(a=>a.length>0)}function j(t,a){if(!B(t)){P(t);return}const e=w([{frameId:a.id,role:x(a),priority:0}]);t.layouts??(t.layouts={});for(const[s,n]of Object.entries(e)){const d=t.layouts[s]||[];if(d.some(r=>r.i===a.id))continue;const i=n[0];if(!i)continue;const l=d.reduce((r,u)=>Math.max(r,u.y+u.h),0);t.layouts[s]=[...d,{...i,y:l}]}}function W(t,a){var e;a.defaultValue!==void 0&&(t.defaultInputValues??(t.defaultInputValues={}),(e=t.defaultInputValues).shared??(e.shared={}),t.defaultInputValues.shared[a.id]={status:"set",value:{kind:"filter",filterValue:a.defaultValue}})}function G(t){var l;const a=F(t.changePlan);if(!a.ok)throw new Error(a.errors.map(r=>r.message).join(`
|
|
3
|
+
`)||"Dashboard change plan is invalid.");const e=H(t.dashboard),s=[...a.warnings],n=[],d=new Map(t.cardArtifacts.map(r=>[r.planCardId,r])),i=$(e);if(!i)throw new Error("Dashboard has no editable dashboard sheet.");i.frames??(i.frames=[]);for(const r of t.changePlan.operations)switch(r.kind){case"addCard":{if((i.frames||[]).reduce((m,o)=>{var h;return m+(((h=o.cards)==null?void 0:h.length)||0)},0)>=_){n.push(g("generated_card_limit_reached",`MVP AI refinement is capped at ${_} cards.`,r.card.id));break}const f=d.get(r.card.id);if(!f){n.push(g("missing_card_artifact",`Card "${r.card.title}" was skipped because no generated artifact was supplied.`,r.card.id));break}const b={id:r.card.frameId,cards:[f.card],activeCardId:f.card.id};i.frames.push(b),j(i,b);break}case"addFilterInput":{e.inputs??(e.inputs=[]);const u={id:r.input.id,kind:"filter",label:r.input.label,variableName:r.input.variableName,scope:{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:e.inputs.length},exports:["label","value","start","end","range"],filter:r.input.filter};e.inputs.push(u),W(e,r.input);break}case"addCalculatedField":{if(r.field.scope==="dashboard"&&r.field.field)e.calculatedFields??(e.calculatedFields=[]),e.calculatedFields.push(r.field.field);else if(r.field.scope==="sheet"&&r.field.field)i.calculatedFields??(i.calculatedFields=[]),i.calculatedFields.push(r.field.field);else if(r.field.scope==="card"&&r.field.field){const u=r.field.targetCardId?D(e,r.field.targetCardId):null;u?((l=u.card).calculatedFields??(l.calculatedFields=[]),u.card.calculatedFields.push(r.field.field)):n.push(g("missing_calculated_field_target",`Calculated field "${r.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=D(e,r.cardId);if(!u){n.push(g("card_not_found",`Card "${r.cardId}" could not be renamed because it was not found.`,r.cardId));break}u.card.title=r.title,r.description!==void 0&&(u.card.description=r.description);break}case"reorderCards":{const u=new Map;for(let f=0;f<r.cardIds.length;f+=1){const b=r.cardIds[f],m=D(e,b);m&&u.set(m.frame.id,f)}P(i,u);break}case"reuseCalculatedField":s.push(g("reused_calculated_field",`Calculated field "${r.fieldId}" is reused by reference.`));break;case"unsupported":n.push(g("unsupported_operation",r.reason||r.requestedAction));break}return{dashboard:e,warnings:s,skippedOperations:n}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=A;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=_;exports.applyDashboardChangePlan=G;exports.compileDashboardFromPlan=E;exports.compileResponsiveDashboardLayouts=w;exports.validateDashboardChangePlan=F;exports.validateDashboardPlan=C;
|