react-semaphor 0.1.323 → 0.1.325

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -0
  2. package/dist/analytics-protocol/index.js +240 -0
  3. package/dist/chunks/{calendar-preferences-dialog-CLXaVo3h.js → calendar-preferences-dialog-BxeROxyq.js} +1 -1
  4. package/dist/chunks/{calendar-preferences-dialog-B9Hz3pTH.js → calendar-preferences-dialog-DHhT6Sja.js} +1 -1
  5. package/dist/chunks/{dashboard-briefing-launcher-CUEn7cr6.js → dashboard-briefing-launcher-BzIxRlzW.js} +3 -3
  6. package/dist/chunks/{dashboard-briefing-launcher-COLpvReF.js → dashboard-briefing-launcher-DZiFMK8I.js} +1 -1
  7. package/dist/chunks/{dashboard-controls-DH8gdpOc.js → dashboard-controls-BX693lE0.js} +1 -1
  8. package/dist/chunks/{dashboard-controls-CLShFyUq.js → dashboard-controls-DVwsWny9.js} +3 -3
  9. package/dist/chunks/{dashboard-json-Db0DpTMw.js → dashboard-json-D15C_I9e.js} +1 -1
  10. package/dist/chunks/{dashboard-json-eGBWfSN1.js → dashboard-json-DxNEFM-p.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-Cc3xpTNQ.js → edit-dashboard-visual-90_qEgRc.js} +1 -1
  12. package/dist/chunks/{edit-dashboard-visual-DmMKWtln.js → edit-dashboard-visual-wQyJEcVH.js} +3 -3
  13. package/dist/chunks/{index-PTx7430W.js → index-CffvIaZO.js} +33125 -32694
  14. package/dist/chunks/{index-CMS4bp9G.js → index-YTk9Hab2.js} +203 -203
  15. package/dist/chunks/{resource-management-panel-C1mbF-2a.js → resource-management-panel-CLoO2DL3.js} +2 -2
  16. package/dist/chunks/{resource-management-panel-DR7Ku6sa.js → resource-management-panel-DlnrD0y-.js} +1 -1
  17. package/dist/chunks/{use-create-flow-overlay-state-CmxTpqeg.js → use-create-flow-overlay-state-DocFanjO.js} +1 -1
  18. package/dist/chunks/{use-create-flow-overlay-state-B65gg2oB.js → use-create-flow-overlay-state-DsPoCfMu.js} +2 -2
  19. package/dist/chunks/{use-visual-utils-Diuguy3D.js → use-visual-utils-BdO22fQZ.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-51Nsy8cj.js → use-visual-utils-DSbXQQD1.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/dashboard-authoring/index.cjs +3 -3
  24. package/dist/dashboard-authoring/index.js +825 -310
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.js +5 -5
  27. package/dist/surfboard/index.cjs +1 -1
  28. package/dist/surfboard/index.js +2 -2
  29. package/dist/types/analytics-protocol.d.ts +172 -0
  30. package/dist/types/dashboard-authoring.d.ts +161 -0
  31. package/dist/types/main.d.ts +1 -0
  32. package/package.json +6 -1
@@ -1,532 +1,1047 @@
1
- const C = [
1
+ import { validateSemaphorDashboardIntent as Q } from "../analytics-protocol/index.js";
2
+ const Z = [
2
3
  "lg",
3
4
  "md",
4
5
  "sm",
5
6
  "xs",
6
7
  "xxs"
7
- ], G = 10;
8
- function c(t, a, e) {
9
- return e ? { code: t, message: a, cardId: e } : { code: t, message: a };
10
- }
11
- function I(t) {
12
- const a = /* @__PURE__ */ new Set();
13
- for (const e of t) {
14
- if (a.has(e))
15
- return e;
16
- a.add(e);
8
+ ], D = 10;
9
+ function f(e, t, a) {
10
+ return a ? { code: e, message: t, cardId: a } : { code: e, message: t };
11
+ }
12
+ function $(e) {
13
+ const t = /* @__PURE__ */ new Set();
14
+ for (const a of e) {
15
+ if (t.has(a))
16
+ return a;
17
+ t.add(a);
17
18
  }
18
19
  return null;
19
20
  }
20
- function F(t) {
21
- var y, v;
22
- const a = [];
23
- if (!t || typeof t != "object")
21
+ function ee(e) {
22
+ var w, C;
23
+ const t = [];
24
+ if (!e || typeof e != "object")
24
25
  return {
25
26
  ok: !1,
26
27
  errors: [
27
- c(
28
+ f(
28
29
  "invalid_plan",
29
30
  "Dashboard plan must be a structured object."
30
31
  )
31
32
  ],
32
33
  warnings: []
33
34
  };
34
- const e = t, i = [...e.warnings || []];
35
- e.version !== 1 && a.push(c("invalid_version", "Dashboard plan version must be 1.")), (y = e.title) != null && y.trim() || a.push(c("missing_title", "Dashboard plan needs a title."));
36
- const n = Array.isArray(e.datasets) ? e.datasets : [], d = Array.isArray(e.sheets) ? e.sheets : [];
37
- n.length !== 1 && a.push(
38
- c(
35
+ const a = e, n = [...a.warnings || []];
36
+ a.version !== 1 && t.push(f("invalid_version", "Dashboard plan version must be 1.")), (w = a.title) != null && w.trim() || t.push(f("missing_title", "Dashboard plan needs a title."));
37
+ const i = Array.isArray(a.datasets) ? a.datasets : [], r = Array.isArray(a.sheets) ? a.sheets : [];
38
+ i.length !== 1 && t.push(
39
+ f(
39
40
  "invalid_dataset_count",
40
41
  "MVP dashboard authoring requires exactly one selected dataset."
41
42
  )
42
- ), d.length !== 1 && a.push(
43
- c(
43
+ ), r.length !== 1 && t.push(
44
+ f(
44
45
  "invalid_sheet_count",
45
46
  "MVP dashboard authoring creates exactly one dashboard sheet."
46
47
  )
47
48
  );
48
- const s = d[0];
49
- s && s.kind !== "dashboard" && a.push(
50
- c("invalid_sheet_kind", 'Generated sheet must use kind "dashboard".')
49
+ const d = r[0];
50
+ d && d.kind !== "dashboard" && t.push(
51
+ f("invalid_sheet_kind", 'Generated sheet must use kind "dashboard".')
51
52
  );
52
- const l = (s == null ? void 0 : s.cards) || [];
53
- l.length > 10 && a.push(
54
- c(
53
+ const l = (d == null ? void 0 : d.cards) || [];
54
+ l.length > D && t.push(
55
+ f(
55
56
  "too_many_cards",
56
- "Generated dashboards can contain at most 10 cards."
57
+ `Generated dashboards can contain at most ${D} cards.`
57
58
  )
58
59
  );
59
- const r = I(l.map((p) => p.id));
60
- r && a.push(
61
- c("duplicate_card_id", `Duplicate generated card id: ${r}.`)
60
+ const s = $(l.map((u) => u.id));
61
+ s && t.push(
62
+ f("duplicate_card_id", `Duplicate generated card id: ${s}.`)
62
63
  );
63
- const u = I(l.map((p) => p.frameId));
64
- u && a.push(
65
- c(
64
+ const c = $(l.map((u) => u.frameId));
65
+ c && t.push(
66
+ f(
66
67
  "duplicate_frame_id",
67
- `Duplicate generated frame id: ${u}.`
68
+ `Duplicate generated frame id: ${c}.`
68
69
  )
69
70
  );
70
- for (const p of l)
71
- (v = p.title) != null && v.trim() || a.push(c("missing_card_title", "Card title is required.", p.id)), p.type === "custom" && a.push(
72
- c(
71
+ for (const u of l)
72
+ (C = u.title) != null && C.trim() || t.push(f("missing_card_title", "Card title is required.", u.id)), u.type === "custom" && t.push(
73
+ f(
73
74
  "custom_visual_out_of_scope",
74
75
  "Whole-dashboard authoring supports built-in visual types only.",
75
- p.id
76
+ u.id
76
77
  )
77
- ), p.type !== "text" && !p.query && i.push(
78
- c(
78
+ ), u.type !== "text" && !u.query && n.push(
79
+ f(
79
80
  "missing_query_intent",
80
81
  "Non-text card has no query intent and may be skipped by the app layer.",
81
- p.id
82
+ u.id
82
83
  )
83
84
  );
84
- const f = Array.isArray(e.filterInputs) ? e.filterInputs : [], b = f.map((p) => p.id), m = I(b);
85
- m && a.push(
86
- c(
85
+ const m = Array.isArray(a.filterInputs) ? a.filterInputs : [], y = m.map((u) => u.id), g = $(y);
86
+ g && t.push(
87
+ f(
87
88
  "duplicate_input_id",
88
- `Duplicate dashboard input id: ${m}.`
89
+ `Duplicate dashboard input id: ${g}.`
89
90
  )
90
91
  );
91
- const o = f.map((p) => p.variableName).filter(Boolean) || [], h = I(o);
92
- h && a.push(
93
- c(
92
+ const o = m.map((u) => u.variableName).filter(Boolean) || [], b = $(o);
93
+ b && t.push(
94
+ f(
94
95
  "duplicate_input_variable",
95
- `Duplicate dashboard input variable name: ${h}.`
96
+ `Duplicate dashboard input variable name: ${b}.`
96
97
  )
97
98
  );
98
- const g = Array.isArray(e.calculatedFields) ? e.calculatedFields : [];
99
- for (const p of g)
100
- p.scope === "domain" && p.reuseOnly !== !0 && a.push(
101
- c(
99
+ const k = Array.isArray(a.calculatedFields) ? a.calculatedFields : [];
100
+ for (const u of k)
101
+ u.scope === "domain" && u.reuseOnly !== !0 && t.push(
102
+ f(
102
103
  "domain_calculated_field_create_out_of_scope",
103
- `Creating domain calculated field "${p.name}" is outside MVP.`
104
+ `Creating domain calculated field "${u.name}" is outside MVP.`
104
105
  )
105
106
  );
106
- return { ok: a.length === 0, errors: a, warnings: i };
107
+ return { ok: t.length === 0, errors: t, warnings: n };
107
108
  }
108
- function R(t) {
109
- var s;
110
- const a = [];
111
- if (!t || typeof t != "object")
109
+ function te(e) {
110
+ var d;
111
+ const t = [];
112
+ if (!e || typeof e != "object")
112
113
  return {
113
114
  ok: !1,
114
115
  errors: [
115
- c(
116
+ f(
116
117
  "invalid_change_plan",
117
118
  "Dashboard change plan must be a structured object."
118
119
  )
119
120
  ],
120
121
  warnings: []
121
122
  };
122
- const e = t, i = [...e.warnings || []];
123
- e.version !== 1 && a.push(
124
- c("invalid_version", "Dashboard change plan version must be 1.")
125
- ), (s = e.dashboardId) != null && s.trim() || a.push(
126
- c("missing_dashboard_id", "Dashboard change plan needs a dashboard id.")
123
+ const a = e, n = [...a.warnings || []];
124
+ a.version !== 1 && t.push(
125
+ f("invalid_version", "Dashboard change plan version must be 1.")
126
+ ), (d = a.dashboardId) != null && d.trim() || t.push(
127
+ f("missing_dashboard_id", "Dashboard change plan needs a dashboard id.")
127
128
  );
128
- const n = Array.isArray(e.datasets) ? e.datasets : [], d = Array.isArray(e.operations) ? e.operations : [];
129
- n.length > 1 && a.push(
130
- c(
129
+ const i = Array.isArray(a.datasets) ? a.datasets : [], r = Array.isArray(a.operations) ? a.operations : [];
130
+ i.length > 1 && t.push(
131
+ f(
131
132
  "invalid_dataset_count",
132
133
  "MVP dashboard refinement can ground new AI operations in at most one selected dataset."
133
134
  )
134
135
  );
135
- for (const l of d) {
136
+ for (const l of r) {
136
137
  if (l.kind === "unsupported") {
137
- i.push(
138
- c("unsupported_operation", l.reason || l.requestedAction)
138
+ n.push(
139
+ f("unsupported_operation", l.reason || l.requestedAction)
139
140
  );
140
141
  continue;
141
142
  }
142
- l.kind === "addCard" && l.card.type === "custom" && a.push(
143
- c(
143
+ l.kind === "addCard" && l.card.type === "custom" && t.push(
144
+ f(
144
145
  "custom_visual_out_of_scope",
145
146
  "Whole-dashboard authoring supports built-in visual types only.",
146
147
  l.card.id
147
148
  )
148
- ), l.kind === "addCalculatedField" && l.field.scope === "domain" && l.field.reuseOnly !== !0 && a.push(
149
- c(
149
+ ), l.kind === "addCalculatedField" && l.field.scope === "domain" && l.field.reuseOnly !== !0 && t.push(
150
+ f(
150
151
  "domain_calculated_field_create_out_of_scope",
151
152
  `Creating domain calculated field "${l.field.name}" is outside MVP.`
152
153
  )
153
154
  );
154
155
  }
155
- return { ok: a.length === 0, errors: a, warnings: i };
156
+ return { ok: t.length === 0, errors: t, warnings: n };
156
157
  }
157
- const x = {
158
+ const ae = {
158
159
  lg: 48,
159
160
  md: 36,
160
161
  sm: 24,
161
162
  xs: 12,
162
163
  xxs: 6
163
164
  };
164
- function O(t) {
165
- switch (t) {
166
- case "kpi":
167
- return { w: 12, h: 12, minW: 8, minH: 8 };
168
- case "table":
169
- return { w: 48, h: 28, minW: 12, minH: 12 };
170
- case "text":
171
- return { w: 48, h: 10, minW: 12, minH: 8 };
172
- case "chart":
173
- default:
174
- return { w: 24, h: 24, minW: 12, minH: 10 };
175
- }
176
- }
177
- function E(t, a) {
178
- let e = 0, i = 0, n = 0;
179
- return t.map((d) => {
180
- const s = Math.min(d.w, a);
181
- e > 0 && e + s > a && (e = 0, i += n, n = 0);
165
+ function ne(e, t) {
166
+ let a = 0, n = 0, i = 0;
167
+ return e.map((r) => {
168
+ const d = Math.min(r.w, t);
169
+ a > 0 && a + d > t && (a = 0, n += i, i = 0);
182
170
  const l = {
183
- i: d.frameId,
184
- x: e,
185
- y: i,
186
- w: s,
187
- h: d.h,
188
- minW: Math.min(d.minW, a),
189
- minH: d.minH,
171
+ i: r.frameId,
172
+ x: a,
173
+ y: n,
174
+ w: d,
175
+ h: r.h,
176
+ minW: Math.min(r.minW, t),
177
+ minH: r.minH,
190
178
  static: !1
191
179
  };
192
- return e += s, n = Math.max(n, d.h), l;
180
+ return a += d, i = Math.max(i, r.h), l;
193
181
  });
194
182
  }
195
- function D(t) {
196
- const a = [...t].sort((e, i) => e.priority - i.priority).map((e) => ({ ...e, ...O(e.role) }));
183
+ function re(e) {
184
+ const t = [...e].sort((s, c) => s.priority - c.priority), a = t.filter((s) => s.role === "kpi"), n = t.filter((s) => s.role === "chart"), i = t.filter((s) => s.role === "table"), r = t.filter((s) => s.role === "text"), d = r.slice(0, 1), l = r.slice(d.length);
185
+ return { kpis: a, introText: d, charts: n, tables: i, supportingText: l };
186
+ }
187
+ function ie(e, t, a) {
188
+ return t === "xxs" || t === "xs" ? a : t === "sm" ? Math.min(12, a) : t === "md" ? e <= 1 || e === 2 ? 18 : 12 : e <= 1 || e === 2 ? 24 : e === 3 ? 16 : 12;
189
+ }
190
+ function se(e, t, a, n) {
191
+ return a === "xxs" || a === "xs" || a === "sm" || a === "md" || t === 1 || t % 2 === 1 && e === 0 ? n : n / 2;
192
+ }
193
+ function de(e) {
194
+ const { item: t, band: a, index: n, bandCount: i, breakpoint: r, columns: d } = e;
195
+ return a === "kpi" ? {
196
+ ...t,
197
+ band: a,
198
+ w: ie(i, r, d),
199
+ h: 15,
200
+ minW: Math.min(6, d),
201
+ minH: 12
202
+ } : a === "table" ? {
203
+ ...t,
204
+ band: a,
205
+ w: d,
206
+ h: r === "xxs" || r === "xs" ? 34 : 38,
207
+ minW: Math.min(12, d),
208
+ minH: 18
209
+ } : a === "introText" ? {
210
+ ...t,
211
+ band: a,
212
+ w: d,
213
+ h: r === "xxs" || r === "xs" ? 12 : 10,
214
+ minW: Math.min(12, d),
215
+ minH: 8
216
+ } : a === "supportingText" ? {
217
+ ...t,
218
+ band: a,
219
+ w: r === "lg" ? d / 2 : d,
220
+ h: r === "xxs" || r === "xs" ? 12 : 10,
221
+ minW: Math.min(12, d),
222
+ minH: 8
223
+ } : {
224
+ ...t,
225
+ band: a,
226
+ w: se(n, i, r, d),
227
+ h: r === "xxs" || r === "xs" ? 28 : 30,
228
+ minW: Math.min(12, d),
229
+ minH: 16
230
+ };
231
+ }
232
+ function A(e, t, a, n) {
233
+ return e.map(
234
+ (i, r) => de({
235
+ item: i,
236
+ band: t,
237
+ index: r,
238
+ bandCount: e.length,
239
+ breakpoint: a,
240
+ columns: n
241
+ })
242
+ );
243
+ }
244
+ function P(e) {
245
+ const t = re(e);
197
246
  return Object.fromEntries(
198
- C.map((e) => {
199
- const i = x[e], n = e === "lg" || e === "md" ? a : a.map((d) => ({
200
- ...d,
201
- w: i,
202
- minW: Math.min(d.minW, i)
203
- }));
204
- return [e, E(n, i)];
247
+ Z.map((a) => {
248
+ const n = ae[a], i = [
249
+ ...A(t.introText, "introText", a, n),
250
+ ...A(t.kpis, "kpi", a, n),
251
+ ...A(t.charts, "chart", a, n),
252
+ ...A(t.tables, "table", a, n),
253
+ ...A(t.supportingText, "supportingText", a, n)
254
+ ];
255
+ return [a, ne(i, n)];
205
256
  })
206
257
  );
207
258
  }
208
- function M(t, a, e) {
209
- return e ? { code: t, message: a, cardId: e } : { code: t, message: a };
259
+ function oe(e) {
260
+ const t = String(e || "").trim().toLowerCase();
261
+ return t.includes("date") || t.includes("time") || t.includes("timestamp") ? "date" : t.includes("int") || t.includes("float") || t.includes("double") || t.includes("decimal") || t.includes("numeric") || t.includes("number") || t.includes("currency") || t.includes("percent") ? "number" : t.includes("bool") ? "boolean" : "string";
210
262
  }
211
- function N(t, a, e) {
212
- const i = (a || []).filter(
213
- (n) => n.scope === "card" && n.targetCardId === e
214
- ).map((n) => n.field).filter(Boolean);
215
- return i.length === 0 ? t : {
216
- ...t,
263
+ function le(e) {
264
+ return !!(e && typeof e == "object" && !Array.isArray(e));
265
+ }
266
+ function ce(e) {
267
+ return le(e) && typeof e.filterId == "string" && typeof e.operation == "string" && Array.isArray(e.values);
268
+ }
269
+ function ue(e) {
270
+ return e.filter(
271
+ (t) => typeof t == "string" || typeof t == "number"
272
+ );
273
+ }
274
+ function fe(e) {
275
+ return e.filter(
276
+ (t) => t instanceof Date || typeof t == "string"
277
+ );
278
+ }
279
+ function q(e, t) {
280
+ if (t === void 0)
281
+ return;
282
+ const a = oe(e.dataType), n = e.operation || "in";
283
+ if (ce(t))
284
+ return {
285
+ ...t,
286
+ filterId: e.id,
287
+ name: t.name || e.column,
288
+ valueType: a,
289
+ dataType: e.dataType,
290
+ fieldMeta: e.fieldMeta,
291
+ semanticContext: e.semanticContext
292
+ };
293
+ if (n === "is null" || n === "is not null")
294
+ return {
295
+ filterId: e.id,
296
+ name: e.column,
297
+ operation: n,
298
+ valueType: a,
299
+ values: [],
300
+ dataType: e.dataType,
301
+ fieldMeta: e.fieldMeta,
302
+ semanticContext: e.semanticContext
303
+ };
304
+ const i = Array.isArray(t) ? t : [t], r = a === "date" ? fe(i) : ue(i);
305
+ if (r.length !== 0 && !((n === "between" || n === "not between") && r.length < 2))
306
+ return {
307
+ filterId: e.id,
308
+ name: e.column,
309
+ operation: n,
310
+ valueType: a,
311
+ values: r,
312
+ dataType: e.dataType,
313
+ fieldMeta: e.fieldMeta,
314
+ semanticContext: e.semanticContext
315
+ };
316
+ }
317
+ function pe(e, t, a) {
318
+ return a ? { code: e, message: t, cardId: a } : { code: e, message: t };
319
+ }
320
+ function me(e, t, a) {
321
+ const n = (t || []).filter(
322
+ (i) => i.scope === "card" && i.targetCardId === a
323
+ ).map((i) => i.field).filter(Boolean);
324
+ return n.length === 0 ? e : {
325
+ ...e,
217
326
  calculatedFields: [
218
- ...t.calculatedFields || [],
219
- ...i
327
+ ...e.calculatedFields || [],
328
+ ...n
220
329
  ]
221
330
  };
222
331
  }
223
- function S(t) {
224
- const a = {};
332
+ function he(e) {
333
+ const t = {};
225
334
  return {
226
- inputs: (t.filterInputs || []).map((i, n) => (i.defaultValue !== void 0 && (a.shared ?? (a.shared = {}), a.shared[i.id] = {
227
- status: "set",
228
- value: {
335
+ inputs: (e.filterInputs || []).map((n, i) => {
336
+ const r = q(
337
+ n.filter,
338
+ n.defaultValue
339
+ );
340
+ return r && (t.shared ?? (t.shared = {}), t.shared[n.id] = {
341
+ status: "set",
342
+ value: {
343
+ kind: "filter",
344
+ filterValue: r
345
+ }
346
+ }), {
347
+ id: n.id,
229
348
  kind: "filter",
230
- filterValue: i.defaultValue
231
- }
232
- }), {
233
- id: i.id,
234
- kind: "filter",
235
- label: i.label,
236
- variableName: i.variableName,
237
- scope: { kind: "allSheets", sheetKinds: ["dashboard"] },
238
- runtimeScope: "shared",
239
- presentation: {
240
- placement: "toolbar",
241
- order: n
242
- },
243
- exports: ["label", "value", "start", "end", "range"],
244
- filter: i.filter
245
- })),
246
- defaultInputValues: a.shared && Object.keys(a.shared).length > 0 ? a : void 0
349
+ label: n.label,
350
+ variableName: n.variableName,
351
+ scope: n.scope || { kind: "allSheets", sheetKinds: ["dashboard"] },
352
+ runtimeScope: "shared",
353
+ presentation: {
354
+ placement: "toolbar",
355
+ order: i
356
+ },
357
+ exports: ["label", "value", "start", "end", "range"],
358
+ filter: n.filter
359
+ };
360
+ }),
361
+ defaultInputValues: t.shared && Object.keys(t.shared).length > 0 ? t : void 0
247
362
  };
248
363
  }
249
- function j(t) {
250
- var b, m;
251
- const a = F(t.plan);
252
- if (!a.ok)
364
+ function qe(e) {
365
+ var y, g;
366
+ const t = ee(e.plan);
367
+ if (!t.ok)
253
368
  throw new Error(
254
- a.errors.map((o) => o.message).join(`
369
+ t.errors.map((o) => o.message).join(`
255
370
  `) || "Dashboard plan is invalid."
256
371
  );
257
- const e = t.plan.sheets[0], i = [...a.warnings], n = [], d = new Map(
258
- t.cardArtifacts.map((o) => [o.planCardId, o])
259
- ), s = [];
260
- for (const o of e.cards) {
261
- const h = d.get(o.id);
262
- if (!h) {
263
- const y = M(
372
+ const a = e.plan.sheets[0], n = [...t.warnings], i = [], r = new Map(
373
+ e.cardArtifacts.map((o) => [o.planCardId, o])
374
+ ), d = [];
375
+ for (const o of a.cards) {
376
+ const b = r.get(o.id);
377
+ if (!b) {
378
+ const w = pe(
264
379
  "missing_card_artifact",
265
380
  `Card "${o.title}" was skipped because no generated artifact was supplied.`,
266
381
  o.id
267
382
  );
268
- n.push(y);
383
+ i.push(w);
269
384
  continue;
270
385
  }
271
- i.push(...h.warnings || []);
272
- const g = N(
273
- h.card,
274
- t.plan.calculatedFields,
386
+ n.push(...b.warnings || []);
387
+ const k = me(
388
+ b.card,
389
+ e.plan.calculatedFields,
275
390
  o.id
276
391
  );
277
- s.push({
392
+ d.push({
278
393
  id: o.frameId,
279
- cards: [g],
280
- activeCardId: g.id
394
+ cards: [k],
395
+ activeCardId: k.id
281
396
  });
282
397
  }
283
- if (s.length === 0)
398
+ if (d.length === 0)
284
399
  throw new Error("Dashboard plan did not produce any persistable cards.");
285
- const { inputs: l, defaultInputValues: r } = S(t.plan), u = D(
286
- e.cards.filter((o) => s.some((h) => h.id === o.frameId)).map((o) => ({
400
+ const { inputs: l, defaultInputValues: s } = he(e.plan), c = P(
401
+ a.cards.filter((o) => d.some((b) => b.id === o.frameId)).map((o) => ({
287
402
  frameId: o.frameId,
288
403
  priority: o.priority,
289
404
  role: o.role
290
405
  }))
291
406
  );
292
407
  return { dashboard: {
293
- id: t.dashboardId,
294
- title: t.plan.title,
295
- description: t.plan.description || "",
408
+ id: e.dashboardId,
409
+ title: e.plan.title,
410
+ description: e.plan.description || "",
296
411
  sheets: [
297
412
  {
298
- id: e.id,
413
+ id: a.id,
299
414
  kind: "dashboard",
300
- title: e.title,
301
- description: e.description,
302
- frames: s,
303
- layouts: u,
304
- calculatedFields: (b = t.plan.calculatedFields) == null ? void 0 : b.filter((o) => o.scope === "sheet" && o.field).map((o) => o.field)
415
+ title: a.title,
416
+ description: a.description,
417
+ frames: d,
418
+ layouts: c,
419
+ calculatedFields: (y = e.plan.calculatedFields) == null ? void 0 : y.filter((o) => o.scope === "sheet" && o.field).map((o) => o.field)
305
420
  }
306
421
  ],
307
- calculatedFields: (m = t.plan.calculatedFields) == null ? void 0 : m.filter((o) => o.scope === "dashboard" && o.field).map((o) => o.field),
422
+ calculatedFields: (g = e.plan.calculatedFields) == null ? void 0 : g.filter((o) => o.scope === "dashboard" && o.field).map((o) => o.field),
308
423
  inputs: l,
309
- ...r ? { defaultInputValues: r } : {}
310
- }, warnings: i, skippedOperations: n };
424
+ ...s ? { defaultInputValues: s } : {}
425
+ }, warnings: n, skippedOperations: i };
311
426
  }
312
- function _(t, a, e) {
313
- return e ? { code: t, message: a, cardId: e } : { code: t, message: a };
427
+ function v(e, t, a) {
428
+ return a ? { code: e, message: t, cardId: a } : { code: e, message: t };
314
429
  }
315
- function P(t) {
316
- return JSON.parse(JSON.stringify(t));
430
+ function be(e) {
431
+ return JSON.parse(JSON.stringify(e));
317
432
  }
318
- function H(t) {
319
- var a;
320
- return (a = t.sheets) == null ? void 0 : a.find(
321
- (e) => (e.kind || "dashboard") === "dashboard"
433
+ function ge(e) {
434
+ var t;
435
+ return (t = e.sheets) == null ? void 0 : t.find(
436
+ (a) => (a.kind || "dashboard") === "dashboard"
322
437
  );
323
438
  }
324
- function A(t, a) {
325
- var e;
326
- for (const i of t.sheets || [])
327
- for (const n of i.frames || []) {
328
- const d = (e = n.cards) == null ? void 0 : e.find((s) => s.id === a);
329
- if (d)
330
- return { sheet: i, frame: n, card: d };
439
+ function M(e, t) {
440
+ var a;
441
+ for (const n of e.sheets || [])
442
+ for (const i of n.frames || []) {
443
+ const r = (a = i.cards) == null ? void 0 : a.find((d) => d.id === t);
444
+ if (r)
445
+ return { sheet: n, frame: i, card: r };
331
446
  }
332
447
  return null;
333
448
  }
334
- function w(t) {
335
- var e, i;
336
- const a = (i = (e = t.cards) == null ? void 0 : e[0]) == null ? void 0 : i.type;
337
- return a === "kpi" ? "kpi" : a === "table" || a === "detailTable" || a === "pivotTable" ? "table" : a === "text" ? "text" : "chart";
449
+ function H(e) {
450
+ var a, n;
451
+ const t = (n = (a = e.cards) == null ? void 0 : a[0]) == null ? void 0 : n.type;
452
+ return t === "kpi" ? "kpi" : t === "table" || t === "detailTable" || t === "pivotTable" ? "table" : t === "text" ? "text" : "chart";
338
453
  }
339
- function V(t) {
340
- var a;
454
+ function Ie(e) {
455
+ var t;
341
456
  return new Map(
342
- (((a = t.layouts) == null ? void 0 : a.lg) || []).map((e, i) => [e.i, i])
457
+ (((t = e.layouts) == null ? void 0 : t.lg) || []).map((a, n) => [a.i, n])
343
458
  );
344
459
  }
345
- function k(t, a = /* @__PURE__ */ new Map()) {
346
- const e = V(t), i = Math.max(
347
- e.size,
348
- a.size
349
- ), n = (t.frames || []).map(
350
- (d, s) => ({
351
- frameId: d.id,
352
- role: w(d),
353
- priority: a.get(d.id) ?? e.get(d.id) ?? i + s
460
+ function W(e, t = /* @__PURE__ */ new Map()) {
461
+ const a = Ie(e), n = Math.max(
462
+ a.size,
463
+ t.size
464
+ ), i = (e.frames || []).map(
465
+ (r, d) => ({
466
+ frameId: r.id,
467
+ role: H(r),
468
+ priority: t.get(r.id) ?? a.get(r.id) ?? n + d
354
469
  })
355
470
  );
356
- t.layouts = D(n);
471
+ e.layouts = P(i);
357
472
  }
358
- function T(t) {
359
- return Object.values(t.layouts || {}).some((a) => a.length > 0);
473
+ function ye(e) {
474
+ return Object.values(e.layouts || {}).some((t) => t.length > 0);
360
475
  }
361
- function $(t, a) {
362
- if (!T(t)) {
363
- k(t);
476
+ function we(e, t) {
477
+ if (!ye(e)) {
478
+ W(e);
364
479
  return;
365
480
  }
366
- const e = D([
367
- { frameId: a.id, role: w(a), priority: 0 }
481
+ const a = P([
482
+ { frameId: t.id, role: H(t), priority: 0 }
368
483
  ]);
369
- t.layouts ?? (t.layouts = {});
370
- for (const [i, n] of Object.entries(e)) {
371
- const d = t.layouts[i] || [];
372
- if (d.some((r) => r.i === a.id))
484
+ e.layouts ?? (e.layouts = {});
485
+ for (const [n, i] of Object.entries(a)) {
486
+ const r = e.layouts[n] || [];
487
+ if (r.some((s) => s.i === t.id))
373
488
  continue;
374
- const s = n[0];
375
- if (!s)
489
+ const d = i[0];
490
+ if (!d)
376
491
  continue;
377
- const l = d.reduce(
378
- (r, u) => Math.max(r, u.y + u.h),
492
+ const l = r.reduce(
493
+ (s, c) => Math.max(s, c.y + c.h),
379
494
  0
380
495
  );
381
- t.layouts[i] = [
382
- ...d,
383
- { ...s, y: l }
496
+ e.layouts[n] = [
497
+ ...r,
498
+ { ...d, y: l }
384
499
  ];
385
500
  }
386
501
  }
387
- function B(t, a) {
388
- var e;
389
- a.defaultValue !== void 0 && (t.defaultInputValues ?? (t.defaultInputValues = {}), (e = t.defaultInputValues).shared ?? (e.shared = {}), t.defaultInputValues.shared[a.id] = {
502
+ function _e(e, t) {
503
+ var n;
504
+ const a = q(
505
+ t.filter,
506
+ t.defaultValue
507
+ );
508
+ a && (e.defaultInputValues ?? (e.defaultInputValues = {}), (n = e.defaultInputValues).shared ?? (n.shared = {}), e.defaultInputValues.shared[t.id] = {
390
509
  status: "set",
391
510
  value: {
392
511
  kind: "filter",
393
- filterValue: a.defaultValue
512
+ filterValue: a
394
513
  }
395
514
  });
396
515
  }
397
- function W(t) {
516
+ function Be(e) {
398
517
  var l;
399
- const a = R(t.changePlan);
400
- if (!a.ok)
518
+ const t = te(e.changePlan);
519
+ if (!t.ok)
401
520
  throw new Error(
402
- a.errors.map((r) => r.message).join(`
521
+ t.errors.map((s) => s.message).join(`
403
522
  `) || "Dashboard change plan is invalid."
404
523
  );
405
- const e = P(t.dashboard), i = [...a.warnings], n = [], d = new Map(
406
- t.cardArtifacts.map((r) => [r.planCardId, r])
407
- ), s = H(e);
408
- if (!s)
524
+ const a = be(e.dashboard), n = [...t.warnings], i = [], r = new Map(
525
+ e.cardArtifacts.map((s) => [s.planCardId, s])
526
+ ), d = ge(a);
527
+ if (!d)
409
528
  throw new Error("Dashboard has no editable dashboard sheet.");
410
- s.frames ?? (s.frames = []);
411
- for (const r of t.changePlan.operations)
412
- switch (r.kind) {
529
+ d.frames ?? (d.frames = []);
530
+ for (const s of e.changePlan.operations)
531
+ switch (s.kind) {
413
532
  case "addCard": {
414
- if ((s.frames || []).reduce(
415
- (m, o) => {
416
- var h;
417
- return m + (((h = o.cards) == null ? void 0 : h.length) || 0);
533
+ if ((d.frames || []).reduce(
534
+ (g, o) => {
535
+ var b;
536
+ return g + (((b = o.cards) == null ? void 0 : b.length) || 0);
418
537
  },
419
538
  0
420
- ) >= 10) {
421
- n.push(
422
- _(
539
+ ) >= D) {
540
+ i.push(
541
+ v(
423
542
  "generated_card_limit_reached",
424
- "MVP AI refinement is capped at 10 cards.",
425
- r.card.id
543
+ `MVP AI refinement is capped at ${D} cards.`,
544
+ s.card.id
426
545
  )
427
546
  );
428
547
  break;
429
548
  }
430
- const f = d.get(r.card.id);
431
- if (!f) {
432
- n.push(
433
- _(
549
+ const m = r.get(s.card.id);
550
+ if (!m) {
551
+ i.push(
552
+ v(
434
553
  "missing_card_artifact",
435
- `Card "${r.card.title}" was skipped because no generated artifact was supplied.`,
436
- r.card.id
554
+ `Card "${s.card.title}" was skipped because no generated artifact was supplied.`,
555
+ s.card.id
437
556
  )
438
557
  );
439
558
  break;
440
559
  }
441
- const b = {
442
- id: r.card.frameId,
443
- cards: [f.card],
444
- activeCardId: f.card.id
560
+ const y = {
561
+ id: s.card.frameId,
562
+ cards: [m.card],
563
+ activeCardId: m.card.id
445
564
  };
446
- s.frames.push(b), $(s, b);
565
+ d.frames.push(y), we(d, y);
447
566
  break;
448
567
  }
449
568
  case "addFilterInput": {
450
- e.inputs ?? (e.inputs = []);
451
- const u = {
452
- id: r.input.id,
569
+ a.inputs ?? (a.inputs = []);
570
+ const c = {
571
+ id: s.input.id,
453
572
  kind: "filter",
454
- label: r.input.label,
455
- variableName: r.input.variableName,
456
- scope: { kind: "allSheets", sheetKinds: ["dashboard"] },
573
+ label: s.input.label,
574
+ variableName: s.input.variableName,
575
+ scope: s.input.scope || {
576
+ kind: "allSheets",
577
+ sheetKinds: ["dashboard"]
578
+ },
457
579
  runtimeScope: "shared",
458
580
  presentation: {
459
581
  placement: "toolbar",
460
- order: e.inputs.length
582
+ order: a.inputs.length
461
583
  },
462
584
  exports: ["label", "value", "start", "end", "range"],
463
- filter: r.input.filter
585
+ filter: s.input.filter
464
586
  };
465
- e.inputs.push(u), B(e, r.input);
587
+ a.inputs.push(c), _e(a, s.input);
466
588
  break;
467
589
  }
468
590
  case "addCalculatedField": {
469
- if (r.field.scope === "dashboard" && r.field.field)
470
- e.calculatedFields ?? (e.calculatedFields = []), e.calculatedFields.push(r.field.field);
471
- else if (r.field.scope === "sheet" && r.field.field)
472
- s.calculatedFields ?? (s.calculatedFields = []), s.calculatedFields.push(r.field.field);
473
- else if (r.field.scope === "card" && r.field.field) {
474
- const u = r.field.targetCardId ? A(e, r.field.targetCardId) : null;
475
- u ? ((l = u.card).calculatedFields ?? (l.calculatedFields = []), u.card.calculatedFields.push(r.field.field)) : n.push(
476
- _(
591
+ if (s.field.scope === "dashboard" && s.field.field)
592
+ a.calculatedFields ?? (a.calculatedFields = []), a.calculatedFields.push(s.field.field);
593
+ else if (s.field.scope === "sheet" && s.field.field)
594
+ d.calculatedFields ?? (d.calculatedFields = []), d.calculatedFields.push(s.field.field);
595
+ else if (s.field.scope === "card" && s.field.field) {
596
+ const c = s.field.targetCardId ? M(a, s.field.targetCardId) : null;
597
+ c ? ((l = c.card).calculatedFields ?? (l.calculatedFields = []), c.card.calculatedFields.push(s.field.field)) : i.push(
598
+ v(
477
599
  "missing_calculated_field_target",
478
- `Calculated field "${r.field.name}" needs a valid target card.`
600
+ `Calculated field "${s.field.name}" needs a valid target card.`
479
601
  )
480
602
  );
481
603
  }
482
604
  break;
483
605
  }
484
606
  case "renameCard": {
485
- const u = A(e, r.cardId);
486
- if (!u) {
487
- n.push(
488
- _(
607
+ const c = M(a, s.cardId);
608
+ if (!c) {
609
+ i.push(
610
+ v(
489
611
  "card_not_found",
490
- `Card "${r.cardId}" could not be renamed because it was not found.`,
491
- r.cardId
612
+ `Card "${s.cardId}" could not be renamed because it was not found.`,
613
+ s.cardId
492
614
  )
493
615
  );
494
616
  break;
495
617
  }
496
- u.card.title = r.title, r.description !== void 0 && (u.card.description = r.description);
618
+ c.card.title = s.title, s.description !== void 0 && (c.card.description = s.description);
497
619
  break;
498
620
  }
499
621
  case "reorderCards": {
500
- const u = /* @__PURE__ */ new Map();
501
- for (let f = 0; f < r.cardIds.length; f += 1) {
502
- const b = r.cardIds[f], m = A(e, b);
503
- m && u.set(m.frame.id, f);
622
+ const c = /* @__PURE__ */ new Map();
623
+ for (let m = 0; m < s.cardIds.length; m += 1) {
624
+ const y = s.cardIds[m], g = M(a, y);
625
+ g && c.set(g.frame.id, m);
504
626
  }
505
- k(s, u);
627
+ W(d, c);
506
628
  break;
507
629
  }
508
630
  case "reuseCalculatedField":
509
- i.push(
510
- _(
631
+ n.push(
632
+ v(
511
633
  "reused_calculated_field",
512
- `Calculated field "${r.fieldId}" is reused by reference.`
634
+ `Calculated field "${s.fieldId}" is reused by reference.`
513
635
  )
514
636
  );
515
637
  break;
516
638
  case "unsupported":
517
- n.push(
518
- _("unsupported_operation", r.reason || r.requestedAction)
639
+ i.push(
640
+ v("unsupported_operation", s.reason || s.requestedAction)
519
641
  );
520
642
  break;
521
643
  }
522
- return { dashboard: e, warnings: i, skippedOperations: n };
644
+ return { dashboard: a, warnings: n, skippedOperations: i };
645
+ }
646
+ function I(e, t, a) {
647
+ return a ? { code: e, message: t, cardId: a } : { code: e, message: t };
648
+ }
649
+ function S(e, t) {
650
+ return e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || t;
651
+ }
652
+ function G(e, t) {
653
+ if (!t.has(e))
654
+ return t.add(e), e;
655
+ let a = 2, n = `${e}-${a}`;
656
+ for (; t.has(n); )
657
+ a += 1, n = `${e}-${a}`;
658
+ return t.add(n), n;
659
+ }
660
+ function ve(e) {
661
+ return e.kind === "semantic" ? [
662
+ "semantic",
663
+ e.domainId,
664
+ e.datasetId || "",
665
+ e.datasetName,
666
+ e.connectionId || ""
667
+ ].join(":") : e.kind === "physical" ? [
668
+ "physical",
669
+ e.connectionId,
670
+ e.databaseName || "",
671
+ e.schemaName || "",
672
+ e.tableName
673
+ ].join(":") : ["sql", e.connectionId, e.sql].join(":");
674
+ }
675
+ function x(e) {
676
+ return !!(e && typeof e == "object");
677
+ }
678
+ function E(e) {
679
+ return x(e) && (e.kind === "semantic" || e.kind === "physical" || e.kind === "sql");
680
+ }
681
+ function K(e) {
682
+ return Array.isArray(e.inputs) ? e.inputs.filter(
683
+ (t) => x(t) && typeof t.id == "string"
684
+ ) : [];
685
+ }
686
+ function U(e) {
687
+ return Array.isArray(e.sections) ? e.sections.filter(
688
+ (t) => x(t)
689
+ ) : [];
690
+ }
691
+ function J(e) {
692
+ return Array.isArray(e.views) ? e.views.filter(
693
+ (t) => x(t)
694
+ ) : [];
695
+ }
696
+ function xe(e) {
697
+ return e.kind === "semantic" ? {
698
+ kind: "semantic",
699
+ domainId: e.domainId,
700
+ datasetName: e.datasetName,
701
+ datasetId: e.datasetId,
702
+ label: e.label,
703
+ connectionId: e.connectionId
704
+ } : e.kind === "physical" ? {
705
+ kind: "physical",
706
+ connectionId: e.connectionId,
707
+ databaseName: e.databaseName,
708
+ schemaName: e.schemaName,
709
+ tableName: e.tableName,
710
+ label: e.label
711
+ } : null;
712
+ }
713
+ function ke(e) {
714
+ return (e == null ? void 0 : e.source) || null;
715
+ }
716
+ function X(e) {
717
+ const t = [];
718
+ for (const a of K(e))
719
+ E(a.source) && t.push(a.source);
720
+ for (const a of U(e))
721
+ for (const n of J(a)) {
722
+ const i = ke(n.analytics);
723
+ E(i) && t.push(i);
724
+ }
725
+ return t;
726
+ }
727
+ function Ce(e, t) {
728
+ const a = /* @__PURE__ */ new Map();
729
+ for (const i of X(e))
730
+ a.set(ve(i), i);
731
+ const n = [...a.values()].map(xe).filter((i) => !!i);
732
+ return n.length === 0 ? (t.push(
733
+ I(
734
+ "missing_materializable_dataset",
735
+ "No semantic or physical source could be converted into the current dashboard authoring dataset reference."
736
+ )
737
+ ), []) : (n.length > 1 && t.push(
738
+ I(
739
+ "multiple_datasets_out_of_scope",
740
+ "The current dashboard authoring compiler supports one selected dataset; using the first source and deferring the rest."
741
+ )
742
+ ), [n[0]]);
743
+ }
744
+ function Fe(e) {
745
+ return (Array.isArray(e.fields) ? e.fields : []).map((t) => t.name).filter((t) => {
746
+ var a;
747
+ return t !== ((a = e.dateField) == null ? void 0 : a.name);
748
+ });
749
+ }
750
+ function Ae(e) {
751
+ var t, a;
752
+ if (e) {
753
+ if (e.kind === "metric")
754
+ return {
755
+ metric: e.metric,
756
+ dateField: (t = e.dateField) == null ? void 0 : t.name
757
+ };
758
+ if (e.kind === "records")
759
+ return {
760
+ metrics: e.measures,
761
+ dateField: (a = e.dateField) == null ? void 0 : a.name,
762
+ timeGrain: e.timeGrain === "hour" ? "day" : e.timeGrain,
763
+ dimensions: Fe(e),
764
+ limit: e.limit
765
+ };
766
+ }
767
+ }
768
+ function Se(e) {
769
+ var t;
770
+ switch ((t = e.presentation) == null ? void 0 : t.kind) {
771
+ case "kpi":
772
+ return "kpi";
773
+ case "lineChart":
774
+ return "line";
775
+ case "barChart":
776
+ return "bar";
777
+ case "areaChart":
778
+ return "area";
779
+ case "table":
780
+ return "table";
781
+ case "text":
782
+ return "text";
783
+ default:
784
+ return null;
785
+ }
786
+ }
787
+ function Te(e) {
788
+ var t, a, n;
789
+ return ((t = e.presentation) == null ? void 0 : t.kind) === "kpi" ? "kpi" : ((a = e.presentation) == null ? void 0 : a.kind) === "table" ? "table" : ((n = e.presentation) == null ? void 0 : n.kind) === "text" ? "text" : "chart";
790
+ }
791
+ function $e(e) {
792
+ switch (e) {
793
+ case "not_in":
794
+ return "not in";
795
+ case "contains":
796
+ return "like";
797
+ default:
798
+ return e || "in";
799
+ }
800
+ }
801
+ function De(e) {
802
+ return x(e.field) ? e.field.dataType === "datetime" ? "date" : e.field.dataType || "string" : "string";
803
+ }
804
+ function Ne(e) {
805
+ if (!(!e || e.kind !== "physical"))
806
+ return [e.databaseName, e.schemaName, e.tableName].filter(Boolean).join(".");
807
+ }
808
+ function Me(e, t, a, n, i) {
809
+ if (e.kind !== "filter")
810
+ return i.push(
811
+ I(
812
+ "control_inputs_deferred",
813
+ `Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`
814
+ )
815
+ ), null;
816
+ if (!x(e.field) || typeof e.field.name != "string")
817
+ return i.push(
818
+ I(
819
+ "filter_requires_field",
820
+ `Filter "${e.label || e.id}" needs a field before the dashboard compiler can materialize it.`
821
+ )
822
+ ), null;
823
+ const r = e.source || t, d = (r == null ? void 0 : r.kind) === "semantic" || (r == null ? void 0 : r.kind) === "physical" || (r == null ? void 0 : r.kind) === "sql" ? r.connectionId : void 0;
824
+ if (!d)
825
+ return i.push(
826
+ I(
827
+ "filter_requires_connection_id",
828
+ `Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`
829
+ )
830
+ ), null;
831
+ const c = {
832
+ id: `filter-${G(
833
+ S(e.id, e.field.name),
834
+ n
835
+ )}`,
836
+ variableName: e.id,
837
+ connectionId: d,
838
+ title: e.label,
839
+ column: e.field.name,
840
+ dataType: De(e),
841
+ qualifiedTableName: Ne(r),
842
+ sql: "",
843
+ operation: $e(e.operator),
844
+ type: e.multi === !1 ? "single" : "multiple",
845
+ location: "dashboard",
846
+ displayMode: "toolbar",
847
+ fieldMeta: (r == null ? void 0 : r.kind) === "semantic" ? {
848
+ name: e.field.name,
849
+ qualifiedFieldName: e.field.name,
850
+ dataType: e.field.dataType,
851
+ role: e.field.role === "measure" ? "metric" : "groupby"
852
+ } : void 0,
853
+ semanticContext: (r == null ? void 0 : r.kind) === "semantic" ? {
854
+ semanticDomainId: r.domainId,
855
+ connectionId: r.connectionId
856
+ } : void 0
857
+ };
858
+ return {
859
+ id: e.id,
860
+ label: e.label,
861
+ variableName: e.id,
862
+ scope: a,
863
+ filter: c,
864
+ defaultValue: q(
865
+ c,
866
+ e.defaultValue
867
+ )
868
+ };
869
+ }
870
+ function V(e) {
871
+ const t = [], a = [];
872
+ for (const n of e.viewIds) {
873
+ const i = e.viewIdToCardId.get(n);
874
+ i ? t.push(i) : a.push(n);
875
+ }
876
+ return a.length > 0 && e.warnings.push(
877
+ I(
878
+ "input_scope_view_not_found",
879
+ `Filter "${e.inputLabel}" referenced unknown view ids: ${a.join(", ")}.`
880
+ )
881
+ ), Array.from(new Set(t));
882
+ }
883
+ function Ve(e) {
884
+ var n, i;
885
+ if (!e.protocolScope) {
886
+ const r = Array.from(new Set(e.boundCardIds));
887
+ return r.length > 0 && r.length < e.allCardIds.length ? { kind: "cards", cardIds: r } : void 0;
888
+ }
889
+ if (e.protocolScope.level === "dashboard") {
890
+ if (!((n = e.protocolScope.excludeViewIds) != null && n.length))
891
+ return;
892
+ const r = new Set(
893
+ V({
894
+ inputLabel: e.inputLabel,
895
+ viewIds: e.protocolScope.excludeViewIds,
896
+ viewIdToCardId: e.viewIdToCardId,
897
+ warnings: e.warnings
898
+ })
899
+ );
900
+ return {
901
+ kind: "cards",
902
+ cardIds: e.allCardIds.filter((d) => !r.has(d))
903
+ };
904
+ }
905
+ if (e.protocolScope.level === "view") {
906
+ const r = V({
907
+ inputLabel: e.inputLabel,
908
+ viewIds: e.protocolScope.viewIds,
909
+ viewIdToCardId: e.viewIdToCardId,
910
+ warnings: e.warnings
911
+ });
912
+ return r.length === 0 ? (e.warnings.push(
913
+ I(
914
+ "input_scope_has_no_materialized_cards",
915
+ `Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`
916
+ )
917
+ ), null) : { kind: "cards", cardIds: r };
918
+ }
919
+ const t = e.sectionIdToCardIds.get(e.protocolScope.sectionId) || [];
920
+ if (t.length === 0)
921
+ return e.warnings.push(
922
+ I(
923
+ "input_scope_section_not_found",
924
+ `Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`
925
+ )
926
+ ), null;
927
+ if (!((i = e.protocolScope.excludeViewIds) != null && i.length))
928
+ return { kind: "cards", cardIds: t };
929
+ const a = new Set(
930
+ V({
931
+ inputLabel: e.inputLabel,
932
+ viewIds: e.protocolScope.excludeViewIds,
933
+ viewIdToCardId: e.viewIdToCardId,
934
+ warnings: e.warnings
935
+ })
936
+ );
937
+ return {
938
+ kind: "cards",
939
+ cardIds: t.filter((r) => !a.has(r))
940
+ };
941
+ }
942
+ function Le(e) {
943
+ var w, C, u;
944
+ const t = [], a = Q(e);
945
+ for (const p of a.warnings)
946
+ t.push(I(p.code, p.message));
947
+ for (const p of a.errors)
948
+ t.push(I(p.code, p.message));
949
+ const n = U(e), i = K(e), r = Ce(e, t), d = X(e)[0], l = [], s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set();
950
+ let o = 0;
951
+ for (const [p, _] of n.entries()) {
952
+ const F = typeof _.title == "string" ? _.title : `Section ${p + 1}`, B = _.id || S(F, `section-${p + 1}`);
953
+ c.set(B, []);
954
+ for (const [L, h] of J(_).entries()) {
955
+ const z = Se(h), N = S(
956
+ h.id || `${F}-${h.title || `View ${L + 1}`}`,
957
+ `card-${p + 1}-${L + 1}`
958
+ );
959
+ if (!z) {
960
+ t.push(
961
+ I(
962
+ "unsupported_presentation",
963
+ `Dashboard presentation "${((w = h.presentation) == null ? void 0 : w.kind) || "unknown"}" is not supported by the dashboard authoring adapter.`,
964
+ `card-${N}`
965
+ )
966
+ );
967
+ continue;
968
+ }
969
+ if (((C = h.analytics) == null ? void 0 : C.kind) === "sql") {
970
+ t.push(
971
+ I(
972
+ "sql_intent_deferred",
973
+ "SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",
974
+ `card-${N}`
975
+ )
976
+ );
977
+ continue;
978
+ }
979
+ const j = G(N, y), T = `card-${j}`;
980
+ h.id && s.set(h.id, T), (u = c.get(B)) == null || u.push(T);
981
+ const Y = h.analytics && "inputs" in h.analytics ? h.analytics.inputs : void 0;
982
+ for (const R of Y || []) {
983
+ const O = m.get(R.inputId) || [];
984
+ O.push(T), m.set(R.inputId, O);
985
+ }
986
+ l.push({
987
+ id: T,
988
+ frameId: `frame-${j}`,
989
+ title: h.title,
990
+ description: h.description,
991
+ type: z,
992
+ role: Te(h),
993
+ priority: o,
994
+ section: F,
995
+ query: Ae(h.analytics),
996
+ text: h.text
997
+ }), o += 1;
998
+ }
999
+ }
1000
+ const b = i.map((p) => {
1001
+ const _ = Ve({
1002
+ protocolScope: p.scope,
1003
+ inputLabel: p.label,
1004
+ allCardIds: l.map((F) => F.id),
1005
+ boundCardIds: m.get(p.id) || [],
1006
+ viewIdToCardId: s,
1007
+ sectionIdToCardIds: c,
1008
+ warnings: t
1009
+ });
1010
+ return _ === null ? null : Me(
1011
+ p,
1012
+ d,
1013
+ _,
1014
+ g,
1015
+ t
1016
+ );
1017
+ }).filter((p) => !!p);
1018
+ return { plan: {
1019
+ version: 1,
1020
+ id: `plan-${S(e.title, "dashboard")}`,
1021
+ title: e.title,
1022
+ description: e.description,
1023
+ datasets: r,
1024
+ sheets: [
1025
+ {
1026
+ id: `sheet-${S(e.title, "dashboard")}`,
1027
+ title: e.title,
1028
+ description: e.description,
1029
+ kind: "dashboard",
1030
+ cards: l
1031
+ }
1032
+ ],
1033
+ filterInputs: b.length ? b : void 0,
1034
+ warnings: t.length ? t : void 0,
1035
+ unresolvedRequests: a.ok ? void 0 : a.errors.map((p) => p.message)
1036
+ }, warnings: t };
523
1037
  }
524
1038
  export {
525
- C as DASHBOARD_AUTHORING_BREAKPOINTS,
526
- G as DASHBOARD_AUTHORING_MAX_GENERATED_CARDS,
527
- W as applyDashboardChangePlan,
528
- j as compileDashboardFromPlan,
529
- D as compileResponsiveDashboardLayouts,
530
- R as validateDashboardChangePlan,
531
- F as validateDashboardPlan
1039
+ Z as DASHBOARD_AUTHORING_BREAKPOINTS,
1040
+ D as DASHBOARD_AUTHORING_MAX_GENERATED_CARDS,
1041
+ Be as applyDashboardChangePlan,
1042
+ qe as compileDashboardFromPlan,
1043
+ P as compileResponsiveDashboardLayouts,
1044
+ Le as dashboardPlanFromSemaphorDashboardIntent,
1045
+ te as validateDashboardChangePlan,
1046
+ ee as validateDashboardPlan
532
1047
  };