@dashboard-designer/ui 0.2.3 → 0.2.4

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/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // src/designer/DashboardDesigner.tsx
2
+ import { resolvePrintHeader } from "@dashboard-designer/core";
3
+ import { connectionVariableNames as connectionVariableNames2 } from "@dashboard-designer/core";
4
+
1
5
  // src/components/PrintOptionsDialog.tsx
2
6
  import { useEffect, useRef, useState } from "react";
3
7
 
@@ -18,8 +22,8 @@ function printWidgetWidths(widths, pageWidth, layout) {
18
22
  const total = widths.reduce((sum, width) => sum + Math.max(1, width), 0);
19
23
  return widths.map((width) => layout === "designed" ? available * Math.max(1, width) / total : available / widths.length);
20
24
  }
21
- function designedPrintGeometry(rects, sourceLeft, sourceWidth, pageWidth) {
22
- const scale = Math.min(1, pageWidth / Math.max(1, sourceWidth));
25
+ function designedPrintGeometry(rects, sourceLeft, sourceWidth, pageWidth, pageHeight = Infinity) {
26
+ const scale = Math.min(1, pageWidth / Math.max(1, sourceWidth), pageHeight / Math.max(1, ...rects.map((r) => r.height)));
23
27
  const top = Math.min(...rects.map((r) => r.top));
24
28
  return {
25
29
  scale,
@@ -68,6 +72,9 @@ async function buildPrintSnapshot(canvas, options, signal) {
68
72
  const target = document.createElement("div");
69
73
  target.className = "dd-print-snapshot";
70
74
  const page = printPageSize(options.orientation);
75
+ const printHeader = await createPrintHeader(options, page.width);
76
+ if (signal?.aborted) return;
77
+ const chartPageHeight = Math.max(100, page.height - (printHeader?.height ?? 0));
71
78
  target.style.setProperty("--dd-print-scale", "1");
72
79
  target.style.width = `${page.width}px`;
73
80
  const widgets = Array.from(canvas.querySelectorAll(".dd-widget")).filter((el) => !el.parentElement?.closest(".dd-widget")).map((el) => ({
@@ -85,14 +92,35 @@ async function buildPrintSnapshot(canvas, options, signal) {
85
92
  const row = document.createElement("div");
86
93
  const repack = compact(pending[0]);
87
94
  if (options.layout === "designed" && !repack) {
88
- const geometry = designedPrintGeometry(pending.map((w) => w.rect), sourceLeft, sourceWidth, page.width);
95
+ const geometry = designedPrintGeometry(pending.map((w) => w.rect), sourceLeft, sourceWidth, page.width, chartPageHeight);
89
96
  row.className = "dd-print-designed-block";
90
- Object.assign(row.style, { position: "relative", width: `${page.width}px`, height: `${geometry.height}px`, marginBottom: "12px", breakInside: "avoid" });
97
+ const xs = [.../* @__PURE__ */ new Set([0, page.width, ...geometry.items.flatMap((r) => [r.left, r.left + r.width])])].sort((a, b) => a - b);
98
+ const ys = [.../* @__PURE__ */ new Set([0, ...geometry.items.flatMap((r) => [r.top, r.top + r.height])])].sort((a, b) => a - b);
99
+ Object.assign(row.style, {
100
+ display: "grid",
101
+ width: `${page.width}px`,
102
+ marginBottom: "12px",
103
+ breakInside: "auto",
104
+ pageBreakInside: "auto",
105
+ gridTemplateColumns: xs.slice(1).map((x, i) => `${x - xs[i]}px`).join(" "),
106
+ gridTemplateRows: ys.slice(1).map((y, i) => `${y - ys[i]}px`).join(" ")
107
+ });
91
108
  pending.forEach((widget, index) => {
92
109
  const placement = geometry.items[index];
93
110
  const cell = document.createElement("div");
94
- Object.assign(cell.style, { position: "absolute", left: `${placement.left}px`, top: `${placement.top}px`, width: `${placement.width}px`, height: `${placement.height}px` });
95
- Object.assign(widget.copy.style, { position: "relative", left: "0", top: "0", right: "auto", bottom: "auto", transform: "none", margin: "0", width: `${widget.rect.width}px`, height: `${widget.rect.height}px`, zoom: String(geometry.scale) });
111
+ cell.className = "dd-print-designed-cell";
112
+ Object.assign(cell.style, {
113
+ position: "relative",
114
+ minWidth: "0",
115
+ minHeight: "0",
116
+ width: `${placement.width}px`,
117
+ height: `${placement.height}px`,
118
+ gridColumn: `${xs.indexOf(placement.left) + 1} / ${xs.indexOf(placement.left + placement.width) + 1}`,
119
+ gridRow: `${ys.indexOf(placement.top) + 1} / ${ys.indexOf(placement.top + placement.height) + 1}`,
120
+ breakInside: "avoid",
121
+ pageBreakInside: "avoid"
122
+ });
123
+ Object.assign(widget.copy.style, { position: "relative", left: "0", top: "0", right: "auto", bottom: "auto", transform: "none", margin: "0", width: `${widget.rect.width}px`, height: `${widget.rect.height}px`, zoom: String(geometry.scale), breakInside: "avoid", pageBreakInside: "avoid" });
96
124
  cell.appendChild(widget.copy);
97
125
  row.appendChild(cell);
98
126
  });
@@ -107,7 +135,7 @@ async function buildPrintSnapshot(canvas, options, signal) {
107
135
  const cell = document.createElement("div");
108
136
  cell.className = "dd-print-widget-cell";
109
137
  cell.style.width = `${cellWidth}px`;
110
- Object.assign(widget.copy.style, { position: "relative", left: "0", top: "0", right: "auto", bottom: "auto", transform: "none", margin: "0", width: `${widget.rect.width}px`, height: `${widget.rect.height}px`, zoom: String(repack ? cellWidth / Math.max(1, widget.rect.width) : Math.min(1, cellWidth / Math.max(1, widget.rect.width))) });
138
+ Object.assign(widget.copy.style, { position: "relative", left: "0", top: "0", right: "auto", bottom: "auto", transform: "none", margin: "0", width: `${widget.rect.width}px`, height: `${widget.rect.height}px`, zoom: String(Math.min(chartPageHeight / Math.max(1, widget.rect.height), repack ? cellWidth / Math.max(1, widget.rect.width) : Math.min(1, cellWidth / Math.max(1, widget.rect.width)))), breakInside: "avoid", pageBreakInside: "avoid" });
111
139
  cell.appendChild(widget.copy);
112
140
  row.appendChild(cell);
113
141
  }
@@ -141,6 +169,22 @@ async function buildPrintSnapshot(canvas, options, signal) {
141
169
  }
142
170
  }
143
171
  flush();
172
+ if (printHeader) {
173
+ if (options.header?.repeat !== false) {
174
+ const table = document.createElement("table");
175
+ table.className = "dd-report-print-frame";
176
+ Object.assign(table.style, { width: "100%", borderCollapse: "collapse", tableLayout: "fixed", border: "0" });
177
+ const head = table.createTHead();
178
+ head.style.display = "table-header-group";
179
+ const headCell = head.insertRow().insertCell();
180
+ headCell.style.padding = "0";
181
+ headCell.appendChild(printHeader.element);
182
+ const cell = table.createTBody().insertRow().insertCell();
183
+ Object.assign(cell.style, { padding: "0", verticalAlign: "top", border: "0" });
184
+ while (target.firstChild) cell.appendChild(target.firstChild);
185
+ target.appendChild(table);
186
+ } else target.prepend(printHeader.element);
187
+ }
144
188
  return target;
145
189
  }
146
190
  function loadingStatus(message) {
@@ -202,7 +246,7 @@ async function runPrint(canvas, title, options = defaultPrintOptions) {
202
246
  document.body.appendChild(busy);
203
247
  let target;
204
248
  try {
205
- target = await buildPrintSnapshot(canvas, options);
249
+ target = await buildPrintSnapshot(canvas, { ...options, printedAt: (/* @__PURE__ */ new Date()).toISOString() });
206
250
  } catch {
207
251
  window.alert("Unable to prepare print. Please try again.");
208
252
  } finally {
@@ -240,17 +284,83 @@ async function runPrint(canvas, title, options = defaultPrintOptions) {
240
284
  function printDashboard(canvas, title, options = defaultPrintOptions) {
241
285
  runPrint(canvas, title, options);
242
286
  }
243
- function exportDashboardPdf(canvas, title) {
244
- runPrint(canvas, `${slugifyTitle(title)}.pdf`);
287
+ function exportDashboardPdf(canvas, title, options = defaultPrintOptions) {
288
+ runPrint(canvas, `${slugifyTitle(title)}.pdf`, options);
289
+ }
290
+ async function createPrintHeader(options, width) {
291
+ const config = options.header;
292
+ if (!config || config.enabled === false) return;
293
+ const header = document.createElement("div");
294
+ header.className = "dd-report-print-header";
295
+ Object.assign(header.style, { display: "flex", alignItems: "center", flexWrap: "wrap", gap: "16px 20px", padding: "18px 16px", marginBottom: "16px", borderTop: "3px solid #254c40", borderBottom: "1px solid #b8c9c4", color: "#20352d", font: "12px Arial, sans-serif", boxSizing: "border-box", width: `${width}px`, breakInside: "avoid" });
296
+ if (config.logoUrl) {
297
+ const logo = document.createElement("img");
298
+ logo.alt = "Report logo";
299
+ Object.assign(logo.style, { width: "112px", height: "60px", objectFit: "contain", flex: "none", paddingRight: "20px", borderRight: "1px solid #d5dfda", boxSizing: "content-box" });
300
+ logo.src = config.logoUrl;
301
+ header.appendChild(logo);
302
+ let timer;
303
+ const loaded = await Promise.race([logo.decode().then(() => true, () => false), new Promise((resolve) => {
304
+ timer = setTimeout(() => resolve(false), 3e3);
305
+ })]);
306
+ clearTimeout(timer);
307
+ if (!loaded) logo.remove();
308
+ }
309
+ const content = document.createElement("div");
310
+ content.style.flex = "1 1 220px";
311
+ content.style.minWidth = "0";
312
+ const line = (text, bold = false) => {
313
+ const el = document.createElement("div");
314
+ el.textContent = text;
315
+ Object.assign(el.style, { overflowWrap: "anywhere", marginBottom: "4px", fontWeight: bold ? "700" : "400", fontSize: bold ? "22px" : "12px", lineHeight: "1.3", color: bold ? "#172b24" : "#52665e" });
316
+ content.appendChild(el);
317
+ };
318
+ if (config.organization) line(config.organization);
319
+ if (config.title) line(config.title, true);
320
+ const details = document.createElement("div");
321
+ Object.assign(details.style, { display: "flex", flexDirection: "column", gap: "7px", overflowWrap: "anywhere", maxWidth: "260px", paddingLeft: "20px", borderLeft: "1px solid #d5dfda", fontSize: "12px", lineHeight: "1.5", color: "#52665e" });
322
+ const field = (label, value) => {
323
+ if (!value) return;
324
+ const el = document.createElement("span");
325
+ el.textContent = `${label}: ${value}`;
326
+ details.appendChild(el);
327
+ };
328
+ field("Printed by", config.printedBy ?? "");
329
+ if (config.showPrintedOn !== false) field("Printed on", new Date(options.printedAt ?? Date.now()).toLocaleString());
330
+ header.appendChild(content);
331
+ if (details.childElementCount) header.appendChild(details);
332
+ const extras = document.createElement("div");
333
+ Object.assign(extras.style, { display: "flex", flexWrap: "wrap", gap: "8px 24px", flexBasis: "100%", borderTop: "1px solid #e0e7e3", paddingTop: "10px", fontSize: "12px", lineHeight: "1.5", color: "#52665e", overflowWrap: "anywhere" });
334
+ for (const item of config.fields ?? []) {
335
+ if (!item.value) continue;
336
+ const entry = document.createElement("span");
337
+ entry.textContent = `${item.label}: ${item.value}`;
338
+ extras.appendChild(entry);
339
+ }
340
+ if (extras.childElementCount) header.appendChild(extras);
341
+ const measure = document.createElement("div");
342
+ Object.assign(measure.style, { position: "fixed", left: "-100000px", top: "0", visibility: "hidden", width: `${width}px` });
343
+ measure.appendChild(header);
344
+ document.body.appendChild(measure);
345
+ const height = header.getBoundingClientRect().height + 16;
346
+ header.remove();
347
+ measure.remove();
348
+ return { element: header, height };
349
+ }
350
+ function parsePrintHeaderFields(text) {
351
+ return text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => {
352
+ const separator = line.indexOf(":");
353
+ return separator > 0 ? { label: line.slice(0, separator).trim(), value: line.slice(separator + 1).trim() } : { label: "Note", value: line };
354
+ });
245
355
  }
246
356
 
247
357
  // src/components/PrintOptionsDialog.tsx
248
358
  import { jsx, jsxs } from "react/jsx-runtime";
249
- function PrintOptionsDialog({ onPrint, onClose }) {
359
+ function PrintOptionsDialog({ onPrint, onClose, header, defaults }) {
250
360
  const ref = useRef(null);
251
361
  const previewRef = useRef(null);
252
362
  const [busy, setBusy] = useState(true);
253
- const [options, setOptions] = useState(defaultPrintOptions);
363
+ const [options, setOptions] = useState(() => ({ ...defaultPrintOptions, ...defaults, header: { enabled: true, repeat: true, showPrintedOn: true, ...header }, printedAt: (/* @__PURE__ */ new Date()).toISOString() }));
254
364
  useEffect(() => {
255
365
  const dialog = ref.current;
256
366
  dialog.showModal();
@@ -723,7 +833,7 @@ function VariablePicker({ onSelect }) {
723
833
  if (event.target.value) onSelect(`{{var:${event.target.value}}}`);
724
834
  }, children: [
725
835
  /* @__PURE__ */ jsx5("option", { value: "", children: "Use variable\u2026" }),
726
- definitions.map((variable) => /* @__PURE__ */ jsx5("option", { value: variable.name, children: variable.name }, variable.name))
836
+ definitions.filter((v) => v.type !== "connection").map((variable) => /* @__PURE__ */ jsx5("option", { value: variable.name, children: variable.name }, variable.name))
727
837
  ] });
728
838
  }
729
839
 
@@ -947,7 +1057,52 @@ function FilterBar({
947
1057
  }
948
1058
 
949
1059
  // src/designer/DashboardDesigner.tsx
950
- import React24, { useCallback as useCallback3, useEffect as useEffect21, useMemo as useMemo11, useState as useState22 } from "react";
1060
+ import React24, { useCallback as useCallback3, useEffect as useEffect21, useMemo as useMemo12, useState as useState22 } from "react";
1061
+
1062
+ // src/charts/localTimestamp.ts
1063
+ function formatLocalTimestamp(value, locale) {
1064
+ let date;
1065
+ if (value instanceof Date) {
1066
+ date = value;
1067
+ } else if (typeof value === "string") {
1068
+ const text = value.trim();
1069
+ const iso = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})?$/i;
1070
+ const utc = /^(?:[A-Za-z]{3},?\s+)?\d{1,2}\s+[A-Za-z]{3}\s+\d{4}\s+\d{2}:\d{2}:\d{2}\s+(?:GMT|UTC)$/i;
1071
+ const utcIso = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?\s+(?:UTC|GMT)$/i;
1072
+ if (!iso.test(text) && !utc.test(text) && !utcIso.test(text)) return void 0;
1073
+ const normalized = utcIso.test(text) ? text.replace(/\s+(UTC|GMT)$/i, "Z").replace(" ", "T") : iso.test(text) ? text.replace(" ", "T") : text;
1074
+ date = new Date(normalized);
1075
+ } else {
1076
+ return void 0;
1077
+ }
1078
+ if (!Number.isFinite(date.getTime())) return void 0;
1079
+ return new Intl.DateTimeFormat(locale, {
1080
+ year: "numeric",
1081
+ month: "2-digit",
1082
+ day: "2-digit",
1083
+ hour: "2-digit",
1084
+ minute: "2-digit",
1085
+ second: "2-digit"
1086
+ }).format(date);
1087
+ }
1088
+
1089
+ // src/components/searchTableRows.ts
1090
+ function searchTableRows(rows, columns, search) {
1091
+ const term = search.trim().toLocaleLowerCase();
1092
+ if (!term) return rows;
1093
+ return rows.filter((row) => columns.some((column) => {
1094
+ const value = row[column];
1095
+ if (value == null) return false;
1096
+ let text;
1097
+ try {
1098
+ text = typeof value === "object" ? JSON.stringify(value) : String(value);
1099
+ } catch {
1100
+ text = String(value);
1101
+ }
1102
+ const local = formatLocalTimestamp(value);
1103
+ return text.toLocaleLowerCase().includes(term) || !!local?.toLocaleLowerCase().includes(term);
1104
+ }));
1105
+ }
951
1106
 
952
1107
  // src/components/useTableSort.ts
953
1108
  import { useMemo as useMemo3, useState as useState6 } from "react";
@@ -986,36 +1141,9 @@ function useTableSort(rows, options) {
986
1141
  }
987
1142
 
988
1143
  // src/components/ChartDataPopup.tsx
989
- import { useEffect as useEffect6, useRef as useRef5, useState as useState7 } from "react";
1144
+ import { useEffect as useEffect6, useMemo as useMemo4, useRef as useRef5, useState as useState7 } from "react";
990
1145
  import { createPortal as createPortal2 } from "react-dom";
991
- import { ChevronLeft, ChevronRight, Clock3 } from "lucide-react";
992
-
993
- // src/charts/localTimestamp.ts
994
- function formatLocalTimestamp(value, locale) {
995
- let date;
996
- if (value instanceof Date) {
997
- date = value;
998
- } else if (typeof value === "string") {
999
- const text = value.trim();
1000
- const iso = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})?$/i;
1001
- const utc = /^(?:[A-Za-z]{3},?\s+)?\d{1,2}\s+[A-Za-z]{3}\s+\d{4}\s+\d{2}:\d{2}:\d{2}\s+(?:GMT|UTC)$/i;
1002
- const utcIso = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?\s+(?:UTC|GMT)$/i;
1003
- if (!iso.test(text) && !utc.test(text) && !utcIso.test(text)) return void 0;
1004
- const normalized = utcIso.test(text) ? text.replace(/\s+(UTC|GMT)$/i, "Z").replace(" ", "T") : iso.test(text) ? text.replace(" ", "T") : text;
1005
- date = new Date(normalized);
1006
- } else {
1007
- return void 0;
1008
- }
1009
- if (!Number.isFinite(date.getTime())) return void 0;
1010
- return new Intl.DateTimeFormat(locale, {
1011
- year: "numeric",
1012
- month: "2-digit",
1013
- day: "2-digit",
1014
- hour: "2-digit",
1015
- minute: "2-digit",
1016
- second: "2-digit"
1017
- }).format(date);
1018
- }
1146
+ import { ChevronLeft, ChevronRight, Clock3, Search as Search2, X as X3 } from "lucide-react";
1019
1147
 
1020
1148
  // src/components/TableSortHeader.tsx
1021
1149
  import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
@@ -1084,10 +1212,12 @@ function QueryResultTable({ data, maxRows = 200, className, renderActions, showM
1084
1212
  }
1085
1213
 
1086
1214
  // src/components/ChartDataPopup.tsx
1087
- import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
1215
+ import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
1088
1216
  function ChartDataPopup({ data, widget, dashboardId, category, actions = [], onClose }) {
1089
1217
  const [page, setPage] = useState7(0);
1090
- const { sortedRows, rules: sorting, onSort } = useTableSort(data.rows, widget.chartOptions);
1218
+ const [search, setSearch] = useState7("");
1219
+ const filteredRows = useMemo4(() => searchTableRows(data.rows, data.columns, search), [data.rows, data.columns, search]);
1220
+ const { sortedRows, rules: sorting, onSort } = useTableSort(filteredRows, widget.chartOptions);
1091
1221
  const [pending, setPending] = useState7(false);
1092
1222
  const busy = useRef5(false);
1093
1223
  const [error, setError] = useState7("");
@@ -1135,8 +1265,9 @@ function ChartDataPopup({ data, widget, dashboardId, category, actions = [], onC
1135
1265
  setPending(false);
1136
1266
  }
1137
1267
  };
1138
- const pages = Math.max(1, Math.ceil(data.rows.length / 100));
1139
- const rows = sortedRows.slice(page * 100, (page + 1) * 100);
1268
+ const pages = Math.max(1, Math.ceil(filteredRows.length / 100));
1269
+ const currentPage = Math.min(page, pages - 1);
1270
+ const rows = sortedRows.slice(currentPage * 100, (currentPage + 1) * 100);
1140
1271
  return createPortal2(/* @__PURE__ */ jsx9("div", { className: "dd-modal-backdrop dd-chart-data-popup", onClick: (event) => {
1141
1272
  event.stopPropagation();
1142
1273
  onClose();
@@ -1147,9 +1278,21 @@ function ChartDataPopup({ data, widget, dashboardId, category, actions = [], onC
1147
1278
  " \u2014 ",
1148
1279
  String(category ?? "(empty)")
1149
1280
  ] }),
1281
+ /* @__PURE__ */ jsx9("div", { className: "dd-popup-search-bar", children: /* @__PURE__ */ jsxs9("div", { className: "dd-popup-search-control", children: [
1282
+ /* @__PURE__ */ jsx9(Search2, { size: 16, "aria-hidden": true }),
1283
+ /* @__PURE__ */ jsx9("input", { type: "search", "aria-label": "Search all columns", placeholder: "Search all columns\u2026", value: search, onChange: (event) => {
1284
+ setSearch(event.target.value);
1285
+ setPage(0);
1286
+ } }),
1287
+ search && /* @__PURE__ */ jsx9("button", { type: "button", className: "dd-btn dd-btn-icon", "aria-label": "Clear search", title: "Clear search", onClick: () => {
1288
+ setSearch("");
1289
+ setPage(0);
1290
+ }, children: /* @__PURE__ */ jsx9(X3, { size: 16, "aria-hidden": true }) })
1291
+ ] }) }),
1150
1292
  /* @__PURE__ */ jsx9("button", { ref: close, type: "button", className: "dd-btn", onClick: onClose, children: "Close" })
1151
1293
  ] }),
1152
1294
  /* @__PURE__ */ jsxs9("div", { className: "dd-chart-data-body", children: [
1295
+ search.trim() && !filteredRows.length && /* @__PURE__ */ jsx9("p", { role: "status", className: "dd-muted", children: "No records match your search." }),
1153
1296
  /* @__PURE__ */ jsx9(QueryResultTable, { sortRules: sorting, onSort: onSort ? (column) => {
1154
1297
  onSort(column);
1155
1298
  setPage(0);
@@ -1161,13 +1304,18 @@ function ChartDataPopup({ data, widget, dashboardId, category, actions = [], onC
1161
1304
  /* @__PURE__ */ jsxs9("div", { className: "dd-chart-data-stats", children: [
1162
1305
  /* @__PURE__ */ jsxs9("span", { "aria-live": "polite", children: [
1163
1306
  /* @__PURE__ */ jsxs9("strong", { children: [
1164
- rows.length ? (page * 100 + 1).toLocaleString() : "0",
1307
+ rows.length ? (currentPage * 100 + 1).toLocaleString() : "0",
1165
1308
  "\u2013",
1166
- Math.min((page + 1) * 100, data.rows.length).toLocaleString()
1309
+ Math.min((currentPage + 1) * 100, filteredRows.length).toLocaleString()
1167
1310
  ] }),
1168
1311
  " of ",
1169
- /* @__PURE__ */ jsx9("strong", { children: data.rows.length.toLocaleString() }),
1170
- " rows"
1312
+ /* @__PURE__ */ jsx9("strong", { children: filteredRows.length.toLocaleString() }),
1313
+ " rows",
1314
+ search.trim() && /* @__PURE__ */ jsxs9(Fragment4, { children: [
1315
+ " (filtered from ",
1316
+ data.rows.length.toLocaleString(),
1317
+ ")"
1318
+ ] })
1171
1319
  ] }),
1172
1320
  Number.isFinite(data.durationMs) && data.durationMs >= 0 && /* @__PURE__ */ jsxs9("span", { className: "dd-chart-data-time", title: "Execution time of the query that loaded the chart data", children: [
1173
1321
  /* @__PURE__ */ jsx9(Clock3, { size: 14, "aria-hidden": true }),
@@ -1176,17 +1324,17 @@ function ChartDataPopup({ data, widget, dashboardId, category, actions = [], onC
1176
1324
  ] })
1177
1325
  ] }),
1178
1326
  /* @__PURE__ */ jsxs9("nav", { className: "dd-chart-data-pagination", "aria-label": "Chart data pagination", children: [
1179
- /* @__PURE__ */ jsxs9("button", { type: "button", className: "dd-btn", disabled: page === 0, onClick: () => setPage(page - 1), children: [
1327
+ /* @__PURE__ */ jsxs9("button", { type: "button", className: "dd-btn", disabled: currentPage === 0, onClick: () => setPage(currentPage - 1), children: [
1180
1328
  /* @__PURE__ */ jsx9(ChevronLeft, { size: 16, "aria-hidden": true }),
1181
1329
  "Previous"
1182
1330
  ] }),
1183
1331
  /* @__PURE__ */ jsxs9("span", { children: [
1184
1332
  "Page ",
1185
- /* @__PURE__ */ jsx9("strong", { children: page + 1 }),
1333
+ /* @__PURE__ */ jsx9("strong", { children: currentPage + 1 }),
1186
1334
  " of ",
1187
1335
  pages
1188
1336
  ] }),
1189
- /* @__PURE__ */ jsxs9("button", { type: "button", className: "dd-btn", disabled: page + 1 >= pages, onClick: () => setPage(page + 1), children: [
1337
+ /* @__PURE__ */ jsxs9("button", { type: "button", className: "dd-btn", disabled: currentPage + 1 >= pages, onClick: () => setPage(currentPage + 1), children: [
1190
1338
  "Next",
1191
1339
  /* @__PURE__ */ jsx9(ChevronRight, { size: 16, "aria-hidden": true })
1192
1340
  ] })
@@ -1285,6 +1433,17 @@ var DashboardApiClient = class {
1285
1433
  listConnections() {
1286
1434
  return this.req("/api/connections");
1287
1435
  }
1436
+ async listConnectionSources() {
1437
+ const result = await this.listConnections();
1438
+ const aliases = Object.entries(result.connectionVariables ?? {}).flatMap(([name, id]) => {
1439
+ const connection = result.connections.find((c) => c.id === id);
1440
+ return connection ? [{ ...connection, id: `connvar:${name}`, name: `Variable: ${name}`, variableName: name }] : [];
1441
+ });
1442
+ return { connections: [...result.connections, ...aliases] };
1443
+ }
1444
+ createConnectionVariable(name, connectionId) {
1445
+ return this.req("/api/connection-variables", { method: "POST", body: JSON.stringify({ name, connectionId }) });
1446
+ }
1288
1447
  saveConnection(connection) {
1289
1448
  const method = connection.id ? "PUT" : "POST";
1290
1449
  const path = connection.id ? `/api/connections/${connection.id}` : "/api/connections";
@@ -1386,12 +1545,34 @@ var DashboardApiClient = class {
1386
1545
  };
1387
1546
 
1388
1547
  // src/variables/VariablesModal.tsx
1548
+ import { connectionVariableNames } from "@dashboard-designer/core";
1389
1549
  import { useEffect as useEffect7, useState as useState8 } from "react";
1390
1550
  import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
1391
- function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1392
- const [variables, setVariables] = useState8(() => (dashboard.variables ?? []).map((v) => ({ ...v })));
1551
+ function VariablesModal({ dashboard, predefined, api, onBindingsChanged, onSave, onClose }) {
1552
+ const [variables, setVariables] = useState8(() => [...(dashboard.variables ?? []).map((v) => ({ ...v })), ...connectionVariableNames(dashboard).filter((name) => !(dashboard.variables ?? []).some((v) => v.name === name) && !predefined.some((v) => v.name === name)).map((name) => ({ name, type: "connection" }))]);
1393
1553
  const [defaults, setDefaults] = useState8({ ...dashboard.variableDefaults });
1394
1554
  const [error, setError] = useState8("");
1555
+ const [connections, setConnections] = useState8([]);
1556
+ const [bindings, setBindings] = useState8(/* @__PURE__ */ Object.create(null));
1557
+ const [selections, setSelections] = useState8(/* @__PURE__ */ Object.create(null));
1558
+ const [loading, setLoading] = useState8(true);
1559
+ const [saving, setSaving] = useState8(false);
1560
+ useEffect7(() => {
1561
+ let active = true;
1562
+ api.listConnections().then((r) => {
1563
+ if (active) {
1564
+ setConnections(r.connections);
1565
+ setBindings(Object.assign(/* @__PURE__ */ Object.create(null), r.connectionVariables));
1566
+ }
1567
+ }).catch((e) => {
1568
+ if (active) setError(e.message);
1569
+ }).finally(() => {
1570
+ if (active) setLoading(false);
1571
+ });
1572
+ return () => {
1573
+ active = false;
1574
+ };
1575
+ }, [api]);
1395
1576
  useEffect7(() => {
1396
1577
  const onKey = (event) => {
1397
1578
  if (event.key === "Escape") onClose();
@@ -1399,9 +1580,11 @@ function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1399
1580
  window.addEventListener("keydown", onKey);
1400
1581
  return () => window.removeEventListener("keydown", onKey);
1401
1582
  }, [onClose]);
1402
- const save = () => {
1583
+ const save = async () => {
1584
+ if (saving || loading) return;
1403
1585
  const names = new Set(predefined.map((v) => v.name));
1404
1586
  const parse = (variable, value) => {
1587
+ if (variable.type === "connection") return void 0;
1405
1588
  if (value == null) return value;
1406
1589
  if (variable.type === "number") {
1407
1590
  if (String(value).trim() === "" || !Number.isFinite(Number(value))) throw new Error(`${variable.name}: enter a valid numeric default.`);
@@ -1420,13 +1603,35 @@ function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1420
1603
  return { ...variable, defaultValue: parse(variable, variable.defaultValue) };
1421
1604
  });
1422
1605
  const parsedDefaults = Object.fromEntries(predefined.filter((v) => Object.prototype.hasOwnProperty.call(defaults, v.name)).map((v) => [v.name, parse(v, defaults[v.name])]));
1606
+ const connectionVars = [...next, ...predefined].filter((v) => v.type === "connection");
1607
+ for (const v of connectionVars) if (!bindings[v.name] && !selections[v.name]) throw new Error(`Choose a connection for ${v.name}.`);
1608
+ setSaving(true);
1609
+ for (const v of connectionVars) if (!bindings[v.name]) {
1610
+ await api.createConnectionVariable(v.name, selections[v.name]);
1611
+ }
1612
+ for (const v of connectionVars) delete parsedDefaults[v.name];
1613
+ onBindingsChanged();
1423
1614
  onSave({ variables: next, variableDefaults: parsedDefaults });
1424
1615
  onClose();
1425
1616
  } catch (err) {
1426
1617
  setError(err.message);
1618
+ } finally {
1619
+ setSaving(false);
1427
1620
  }
1428
1621
  };
1429
- const defaultInput = (variable, value, change) => /* @__PURE__ */ jsxs10("div", { className: "dd-field-row", children: [
1622
+ const defaultInput = (variable, value, change) => variable.type === "connection" ? /* @__PURE__ */ jsxs10("div", { className: "dd-field-row", children: [
1623
+ /* @__PURE__ */ jsx10("label", { children: "Environment connection" }),
1624
+ /* @__PURE__ */ jsxs10("select", { className: "dd-input", "aria-label": `${variable.name} connection`, disabled: loading || !!bindings[variable.name], value: bindings[variable.name] ?? selections[variable.name] ?? "", onChange: (e) => setSelections(Object.assign(/* @__PURE__ */ Object.create(null), selections, { [variable.name]: e.target.value })), children: [
1625
+ /* @__PURE__ */ jsx10("option", { value: "", children: "Select a registered connection\u2026" }),
1626
+ connections.map((c) => /* @__PURE__ */ jsxs10("option", { value: c.id, children: [
1627
+ c.name,
1628
+ " (",
1629
+ c.provider,
1630
+ ")"
1631
+ ] }, c.id))
1632
+ ] }),
1633
+ /* @__PURE__ */ jsx10("p", { className: "dd-hint", children: "Shared in this server environment. Existing bindings are reused and cannot be overwritten by an import. Connection credentials are not exported." })
1634
+ ] }) : /* @__PURE__ */ jsxs10("div", { className: "dd-field-row", children: [
1430
1635
  /* @__PURE__ */ jsxs10("select", { className: "dd-input", "aria-label": `${variable.name} default mode`, value: value === void 0 ? "unset" : value === null ? "null" : "value", onChange: (e) => change(e.target.value === "unset" ? void 0 : e.target.value === "null" ? null : ""), children: [
1431
1636
  /* @__PURE__ */ jsx10("option", { value: "unset", children: "No default" }),
1432
1637
  /* @__PURE__ */ jsx10("option", { value: "value", children: "Default value" }),
@@ -1445,6 +1650,8 @@ function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1445
1650
  "{{var:name}}",
1446
1651
  " in query values, parameters or filters. Runtime values supplied by the application override these defaults."
1447
1652
  ] }),
1653
+ /* @__PURE__ */ jsx10("p", { className: "dd-hint", children: "For portable data sources, add a Connection variable and select it in widget configuration." }),
1654
+ loading && /* @__PURE__ */ jsx10("p", { role: "status", children: "Loading connections\u2026" }),
1448
1655
  /* @__PURE__ */ jsx10("h3", { children: "Report variables" }),
1449
1656
  variables.map((variable, index) => /* @__PURE__ */ jsxs10("div", { className: "dd-join-block", children: [
1450
1657
  /* @__PURE__ */ jsxs10("div", { className: "dd-field-row", children: [
@@ -1452,7 +1659,8 @@ function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1452
1659
  /* @__PURE__ */ jsxs10("select", { className: "dd-input", "aria-label": "Variable type", value: variable.type, onChange: (e) => setVariables(variables.map((v, i) => i === index ? { ...v, type: e.target.value } : v)), children: [
1453
1660
  /* @__PURE__ */ jsx10("option", { value: "string", children: "Text" }),
1454
1661
  /* @__PURE__ */ jsx10("option", { value: "number", children: "Number" }),
1455
- /* @__PURE__ */ jsx10("option", { value: "boolean", children: "Boolean" })
1662
+ /* @__PURE__ */ jsx10("option", { value: "boolean", children: "Boolean" }),
1663
+ /* @__PURE__ */ jsx10("option", { value: "connection", children: "Connection" })
1456
1664
  ] }),
1457
1665
  /* @__PURE__ */ jsx10("button", { className: "dd-btn", onClick: () => setVariables(variables.filter((_, i) => i !== index)), children: "Remove" })
1458
1666
  ] }),
@@ -1477,7 +1685,7 @@ function VariablesModal({ dashboard, predefined, onSave, onClose }) {
1477
1685
  ] }),
1478
1686
  /* @__PURE__ */ jsxs10("footer", { className: "dd-modal-footer", children: [
1479
1687
  /* @__PURE__ */ jsx10("button", { className: "dd-btn", onClick: onClose, children: "Cancel" }),
1480
- /* @__PURE__ */ jsx10("button", { className: "dd-btn dd-btn-primary", onClick: save, children: "Save" })
1688
+ /* @__PURE__ */ jsx10("button", { className: "dd-btn dd-btn-primary", disabled: saving || loading, onClick: () => void save(), children: saving ? "Saving\u2026" : "Save" })
1481
1689
  ] })
1482
1690
  ] }) });
1483
1691
  }
@@ -2418,7 +2626,7 @@ function timelineStages(rows, field) {
2418
2626
  }
2419
2627
 
2420
2628
  // src/charts/ChartRenderer.tsx
2421
- import { useEffect as useEffect10, useMemo as useMemo6, useRef as useRef7, useState as useState11 } from "react";
2629
+ import { useEffect as useEffect10, useMemo as useMemo7, useRef as useRef7, useState as useState11 } from "react";
2422
2630
 
2423
2631
  // src/filters/frontendFilters.ts
2424
2632
  import { resolveFilterVariables } from "@dashboard-designer/core";
@@ -2804,7 +3012,7 @@ function LabelChart({ widget, onDrillDown }) {
2804
3012
  }
2805
3013
 
2806
3014
  // src/charts/LabelContainerChart.tsx
2807
- import { useMemo as useMemo4 } from "react";
3015
+ import { useMemo as useMemo5 } from "react";
2808
3016
  import {
2809
3017
  buildContainerLabelsFromQuery,
2810
3018
  normalizeContainerLabelTemplate,
@@ -2865,7 +3073,7 @@ function LabelItem({
2865
3073
  }
2866
3074
  function LabelContainerChart({ widget, data, onDrillDown }) {
2867
3075
  const source = resolveLabelContainerSource2(widget.chartOptions);
2868
- const labels = useMemo4(() => {
3076
+ const labels = useMemo5(() => {
2869
3077
  if (source === "query" && data) {
2870
3078
  return buildContainerLabelsFromQuery(
2871
3079
  data.rows ?? [],
@@ -2897,9 +3105,9 @@ function LabelContainerChart({ widget, data, onDrillDown }) {
2897
3105
  }
2898
3106
 
2899
3107
  // src/charts/ListBoxChart.tsx
2900
- import { useMemo as useMemo5 } from "react";
3108
+ import { useMemo as useMemo6 } from "react";
2901
3109
  import { useTranslation as useTranslation7 } from "react-i18next";
2902
- import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
3110
+ import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
2903
3111
  function resolveDim(field, columns) {
2904
3112
  if (field && columns.includes(field)) return field;
2905
3113
  if (field?.includes(".")) {
@@ -2924,7 +3132,7 @@ function ListBoxChart({
2924
3132
  const dim = resolveDim(widget.binding.dimensions[0], columns);
2925
3133
  const multiSelect = widget.chartOptions.multiSelect !== false;
2926
3134
  const showAll = widget.chartOptions.showAllOption !== false;
2927
- const options = useMemo5(() => {
3135
+ const options = useMemo6(() => {
2928
3136
  const seen = /* @__PURE__ */ new Set();
2929
3137
  const list = [];
2930
3138
  for (const row of data.rows ?? []) {
@@ -2971,7 +3179,7 @@ function ListBoxChart({
2971
3179
  return /* @__PURE__ */ jsx13("div", { className: "dd-muted dd-listbox-empty", children: t("listboxEmpty") });
2972
3180
  }
2973
3181
  return /* @__PURE__ */ jsx13("div", { className: "dd-listbox", role: "group", "aria-label": widget.title, children: /* @__PURE__ */ jsxs11("div", { className: "dd-listbox-scroll", children: [
2974
- showAll && /* @__PURE__ */ jsxs11(Fragment4, { children: [
3182
+ showAll && /* @__PURE__ */ jsxs11(Fragment5, { children: [
2975
3183
  /* @__PURE__ */ jsxs11("label", { className: "dd-listbox-item dd-listbox-all", children: [
2976
3184
  /* @__PURE__ */ jsx13("input", { type: "checkbox", checked: isAllMode, onChange: toggleAll }),
2977
3185
  /* @__PURE__ */ jsx13("span", { className: "dd-listbox-label", children: t("listboxAll") })
@@ -3173,7 +3381,7 @@ function TableChart({ widget, data, locale = "en" }) {
3173
3381
  // src/charts/ChartAxisGuidelines.tsx
3174
3382
  import { ReferenceLine } from "recharts";
3175
3383
  import { normalizeChartAxisGuidelines } from "@dashboard-designer/core";
3176
- import { Fragment as Fragment5, jsx as jsx16 } from "react/jsx-runtime";
3384
+ import { Fragment as Fragment6, jsx as jsx16 } from "react/jsx-runtime";
3177
3385
  var DEFAULT_GUIDELINE_COLOR = "#94a3b8";
3178
3386
  function parseGuidelineColor(raw) {
3179
3387
  if (typeof raw === "string" && /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(raw.trim())) {
@@ -3190,7 +3398,7 @@ function parseXValue(value) {
3190
3398
  }
3191
3399
  function ChartAxisGuidelines({ guidelines }) {
3192
3400
  const items = normalizeChartAxisGuidelines(guidelines);
3193
- return /* @__PURE__ */ jsx16(Fragment5, { children: items.map((g) => {
3401
+ return /* @__PURE__ */ jsx16(Fragment6, { children: items.map((g) => {
3194
3402
  const color = parseGuidelineColor(g.color);
3195
3403
  const labelText = g.label?.trim();
3196
3404
  const label = labelText ? {
@@ -3576,7 +3784,7 @@ function useWidgetData(api, widget, globalFilters = EMPTY_FILTERS, refreshKey =
3576
3784
  cancelled = true;
3577
3785
  };
3578
3786
  }, [api, canRun, signature, variableSignature]);
3579
- const filtered = useMemo6(() => {
3787
+ const filtered = useMemo7(() => {
3580
3788
  try {
3581
3789
  return { data: data ? applyFrontendFilters(data, resolveFilterVariables2(widget.frontendFilters, variables.values)) : void 0 };
3582
3790
  } catch (err) {
@@ -3600,9 +3808,9 @@ var CHART_TYPE_OPTIONS = [
3600
3808
  // src/filters/GlobalFiltersPopover.tsx
3601
3809
  import { useCallback, useEffect as useEffect11, useId as useId4, useLayoutEffect as useLayoutEffect2, useRef as useRef8, useState as useState12 } from "react";
3602
3810
  import { createPortal as createPortal3 } from "react-dom";
3603
- import { Filter as Filter3, FilterX, Maximize2, PanelLeftClose, Pin, PinOff, X as X3 } from "lucide-react";
3811
+ import { Filter as Filter3, FilterX, Maximize2, PanelLeftClose, Pin, PinOff, X as X4 } from "lucide-react";
3604
3812
  import { useTranslation as useTranslation10 } from "react-i18next";
3605
- import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
3813
+ import { Fragment as Fragment7, jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
3606
3814
  function isFilterApplied(filter) {
3607
3815
  if (filter.operator === "is_null" || filter.operator === "not_null") return true;
3608
3816
  if (filter.value === void 0 || filter.value === null || filter.value === "") return false;
@@ -3683,7 +3891,7 @@ function GlobalFiltersSidePanel({
3683
3891
  title: t("closeFiltersPanel"),
3684
3892
  "aria-label": t("closeFiltersPanel"),
3685
3893
  onClick: () => onPanelChange({ open: false, collapsed: false, pinned: false }),
3686
- children: /* @__PURE__ */ jsx18(X3, { size: ICON_SIZE })
3894
+ children: /* @__PURE__ */ jsx18(X4, { size: ICON_SIZE })
3687
3895
  }
3688
3896
  )
3689
3897
  ] });
@@ -3741,7 +3949,7 @@ function GlobalFiltersSidePanel({
3741
3949
  title: t("closeFiltersPanel"),
3742
3950
  "aria-label": t("closeFiltersPanel"),
3743
3951
  onClick: () => onPanelChange({ open: false, collapsed: false, pinned: false }),
3744
- children: /* @__PURE__ */ jsx18(X3, { size: ICON_SIZE })
3952
+ children: /* @__PURE__ */ jsx18(X4, { size: ICON_SIZE })
3745
3953
  }
3746
3954
  )
3747
3955
  ] })
@@ -3862,7 +4070,7 @@ function GlobalFiltersPopover({
3862
4070
  }
3863
4071
  ),
3864
4072
  open && !panel.open && createPortal3(
3865
- /* @__PURE__ */ jsxs15(Fragment6, { children: [
4073
+ /* @__PURE__ */ jsxs15(Fragment7, { children: [
3866
4074
  position && /* @__PURE__ */ jsx18(
3867
4075
  "span",
3868
4076
  {
@@ -3981,7 +4189,7 @@ function readJsonFile(file) {
3981
4189
  // src/designer/WidgetEditorModal.tsx
3982
4190
  import { useEffect as useEffect14, useId as useId5, useRef as useRef10, useState as useState16 } from "react";
3983
4191
  import { useTranslation as useTranslation14 } from "react-i18next";
3984
- import { Save, X as X4 } from "lucide-react";
4192
+ import { Save, X as X5 } from "lucide-react";
3985
4193
  import {
3986
4194
  createEmptyWidget,
3987
4195
  resolveLabelClickAction as resolveLabelClickAction3
@@ -4059,7 +4267,7 @@ function TableFormattingEditor({ value, columns, onChange }) {
4059
4267
  }
4060
4268
 
4061
4269
  // src/designer/WidgetConfigForm.tsx
4062
- import { useEffect as useEffect13, useMemo as useMemo8, useRef as useRef9, useState as useState15 } from "react";
4270
+ import { useEffect as useEffect13, useMemo as useMemo9, useRef as useRef9, useState as useState15 } from "react";
4063
4271
  import {
4064
4272
  createContainerLabelItem,
4065
4273
  parseStoredProcedureName,
@@ -4083,7 +4291,7 @@ import { useTranslation as useTranslation13 } from "react-i18next";
4083
4291
  import { useEffect as useEffect12, useState as useState13 } from "react";
4084
4292
  import { useTranslation as useTranslation11 } from "react-i18next";
4085
4293
  import { buildProcedureWhereClause, createId as createId2, resolveFilterVariables as resolveFilterVariables3 } from "@dashboard-designer/core";
4086
- import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs18 } from "react/jsx-runtime";
4294
+ import { Fragment as Fragment8, jsx as jsx21, jsxs as jsxs18 } from "react/jsx-runtime";
4087
4295
  function ProcedureParametersEditor({ api, connectionId, name, values = {}, onChange, idPrefix, fieldOptions }) {
4088
4296
  const { t } = useTranslation11();
4089
4297
  const variables = useVariables();
@@ -4185,7 +4393,7 @@ function ProcedureParametersEditor({ api, connectionId, name, values = {}, onCha
4185
4393
  )
4186
4394
  ] }),
4187
4395
  mode === "variable" && /* @__PURE__ */ jsx21(VariablePicker, { onSelect: (token) => onChange({ ...values, [parameter.name]: token }) }),
4188
- clause && /* @__PURE__ */ jsxs18(Fragment7, { children: [
4396
+ clause && /* @__PURE__ */ jsxs18(Fragment8, { children: [
4189
4397
  /* @__PURE__ */ jsx21("p", { className: "dd-hint", children: t("procedureWhereClauseHint") }),
4190
4398
  /* @__PURE__ */ jsx21(
4191
4399
  FilterBar,
@@ -4218,13 +4426,13 @@ function ProcedureParametersEditor({ api, connectionId, name, values = {}, onCha
4218
4426
  }
4219
4427
 
4220
4428
  // src/designer/QueryLabelDrillDownEditor.tsx
4221
- import { useMemo as useMemo7, useState as useState14 } from "react";
4429
+ import { useMemo as useMemo8, useState as useState14 } from "react";
4222
4430
  import { useTranslation as useTranslation12 } from "react-i18next";
4223
4431
  import { buildContainerLabelsFromQuery as buildContainerLabelsFromQuery2, normalizeQueryLabelDrillDowns as normalizeQueryLabelDrillDowns2 } from "@dashboard-designer/core";
4224
- import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs19 } from "react/jsx-runtime";
4432
+ import { Fragment as Fragment9, jsx as jsx22, jsxs as jsxs19 } from "react/jsx-runtime";
4225
4433
  function QueryLabelDrillDownEditor({ data, field, rules: rawRules, dashboards, onChange }) {
4226
4434
  const { t } = useTranslation12();
4227
- const rules = useMemo7(() => normalizeQueryLabelDrillDowns2(rawRules), [rawRules]);
4435
+ const rules = useMemo8(() => normalizeQueryLabelDrillDowns2(rawRules), [rawRules]);
4228
4436
  const column = field || data?.columns[0] || "";
4229
4437
  const [extraValue, setExtraValue] = useState14("");
4230
4438
  const values = [.../* @__PURE__ */ new Set([
@@ -4257,7 +4465,7 @@ function QueryLabelDrillDownEditor({ data, field, rules: rawRules, dashboards, o
4257
4465
  /* @__PURE__ */ jsx22("option", { value: "dashboard", children: t("labelOpenDashboard") }),
4258
4466
  /* @__PURE__ */ jsx22("option", { value: "none", children: t("queryLabelDisableDrill") })
4259
4467
  ] }),
4260
- rule?.action === "dashboard" && /* @__PURE__ */ jsxs19(Fragment8, { children: [
4468
+ rule?.action === "dashboard" && /* @__PURE__ */ jsxs19(Fragment9, { children: [
4261
4469
  /* @__PURE__ */ jsx22(FieldLabel, { children: t("drillTargetDashboard") }),
4262
4470
  /* @__PURE__ */ jsxs19(
4263
4471
  "select",
@@ -4339,7 +4547,7 @@ function parseRawSqlSelectAliases(rawSql) {
4339
4547
  }
4340
4548
 
4341
4549
  // src/designer/WidgetConfigForm.tsx
4342
- import { Fragment as Fragment9, jsx as jsx23, jsxs as jsxs20 } from "react/jsx-runtime";
4550
+ import { Fragment as Fragment10, jsx as jsx23, jsxs as jsxs20 } from "react/jsx-runtime";
4343
4551
  var GUIDELINE_DEFAULT_COLOR = "#94a3b8";
4344
4552
  function GuidelineRow({
4345
4553
  item,
@@ -4437,14 +4645,14 @@ function WidgetConfigForm({
4437
4645
  const queryInFlight = useRef9(false);
4438
4646
  const [resultColumns, setResultColumns] = useState15([]);
4439
4647
  const [rawQueryResult, setQueryResult] = useState15(null);
4440
- const queryResult = useMemo8(
4648
+ const queryResult = useMemo9(
4441
4649
  () => variables.ready && ranVariableSignature === variableSignature ? filterVariableResult(rawQueryResult, widget.frontendFilters, variables.values).result : void 0,
4442
4650
  [rawQueryResult, widget.frontendFilters, variableSignature, ranVariableSignature, variables.ready]
4443
4651
  );
4444
4652
  const [showQueryData, setShowQueryData] = useState15(false);
4445
4653
  const [dashboardOptions, setDashboardOptions] = useState15([]);
4446
4654
  const selectedTables = widget.query.tables ?? [];
4447
- const joinTables = useMemo8(() => {
4655
+ const joinTables = useMemo9(() => {
4448
4656
  const set = /* @__PURE__ */ new Set();
4449
4657
  for (const j of widget.query.joins || []) {
4450
4658
  if (j.leftTable) set.add(j.leftTable);
@@ -4455,10 +4663,10 @@ function WidgetConfigForm({
4455
4663
  useEffect13(() => {
4456
4664
  api.listDashboards().then((r) => setDashboardOptions(r.dashboards.map((d) => ({ id: d.id, title: d.title })))).catch(() => setDashboardOptions([]));
4457
4665
  }, [api]);
4458
- const tablesNeedingColumnsKey = useMemo8(() => {
4666
+ const tablesNeedingColumnsKey = useMemo9(() => {
4459
4667
  return [.../* @__PURE__ */ new Set([...selectedTables, ...joinTables])].sort().join("\0");
4460
4668
  }, [selectedTables, joinTables]);
4461
- const tablesNeedingColumns = useMemo8(
4669
+ const tablesNeedingColumns = useMemo9(
4462
4670
  () => tablesNeedingColumnsKey ? tablesNeedingColumnsKey.split("\0") : [],
4463
4671
  [tablesNeedingColumnsKey]
4464
4672
  );
@@ -4547,7 +4755,7 @@ function WidgetConfigForm({
4547
4755
  }
4548
4756
  });
4549
4757
  }, [widget.id, widget.type, widget.binding.dimensions, widget.binding.measures]);
4550
- const schemaColumnOptions = useMemo8(() => {
4758
+ const schemaColumnOptions = useMemo9(() => {
4551
4759
  const opts = [];
4552
4760
  const sourceTables = [.../* @__PURE__ */ new Set([...selectedTables, ...joinTables])];
4553
4761
  const qualify = sourceTables.length > 1 || sourceTables.some((t2) => t2.includes("."));
@@ -4558,7 +4766,7 @@ function WidgetConfigForm({
4558
4766
  }
4559
4767
  return opts;
4560
4768
  }, [selectedTables, joinTables, columnsByTable]);
4561
- const rawSqlAliases = useMemo8(
4769
+ const rawSqlAliases = useMemo9(
4562
4770
  () => parseRawSqlSelectAliases(widget.query.rawSql),
4563
4771
  [widget.query.rawSql]
4564
4772
  );
@@ -4613,15 +4821,15 @@ function WidgetConfigForm({
4613
4821
  variables.ready,
4614
4822
  variableSignature
4615
4823
  ]);
4616
- const resultFieldOptions = useMemo8(() => {
4824
+ const resultFieldOptions = useMemo9(() => {
4617
4825
  return [
4618
4826
  .../* @__PURE__ */ new Set([...previewColumns || [], ...resultColumns, ...rawSqlAliases])
4619
4827
  ].filter(Boolean);
4620
4828
  }, [previewColumns, resultColumns, rawSqlAliases]);
4621
- const columnOptions = useMemo8(() => {
4829
+ const columnOptions = useMemo9(() => {
4622
4830
  return [.../* @__PURE__ */ new Set([...schemaColumnOptions, ...resultFieldOptions])].filter(Boolean);
4623
4831
  }, [schemaColumnOptions, resultFieldOptions]);
4624
- const columnSelectEmptyLabel = useMemo8(() => {
4832
+ const columnSelectEmptyLabel = useMemo9(() => {
4625
4833
  if (!widget.query.connectionId) return t("selectDataSourceFirst");
4626
4834
  if (!hasColumnSource) return t("selectTableOrSqlFirst");
4627
4835
  return t("noColumnsFound");
@@ -4788,14 +4996,14 @@ function WidgetConfigForm({
4788
4996
  );
4789
4997
  const labelContainerQuery = widget.type === "labelContainer" && resolveLabelContainerSource3(widget.chartOptions) === "query";
4790
4998
  const singleField = widget.type === "pie" || widget.type === "kpi" || widget.type === "listbox" || labelContainerQuery;
4791
- const passFieldOptions = useMemo8(() => {
4999
+ const passFieldOptions = useMemo9(() => {
4792
5000
  const fromBinding = [...widget.binding.dimensions, ...widget.binding.measures];
4793
5001
  const fromColumns = (widget.query.columns || []).map((c) => c.alias || c.column);
4794
5002
  return [
4795
5003
  .../* @__PURE__ */ new Set([...fromBinding, ...fromColumns, ...columnOptions, ...resultFieldOptions])
4796
5004
  ].filter(Boolean);
4797
5005
  }, [widget.binding, widget.query.columns, columnOptions, resultFieldOptions]);
4798
- const orderByColumnOptions = useMemo8(() => {
5006
+ const orderByColumnOptions = useMemo9(() => {
4799
5007
  const aliases = (widget.query.columns || []).map((c) => c.alias || c.column);
4800
5008
  return [
4801
5009
  .../* @__PURE__ */ new Set([
@@ -4943,7 +5151,7 @@ function WidgetConfigForm({
4943
5151
  );
4944
5152
  }) })
4945
5153
  ] }),
4946
- widget.type === "label" && /* @__PURE__ */ jsxs20(Fragment9, { children: [
5154
+ widget.type === "label" && /* @__PURE__ */ jsxs20(Fragment10, { children: [
4947
5155
  /* @__PURE__ */ jsxs20("div", { className: "dd-field dd-check-field", children: [
4948
5156
  /* @__PURE__ */ jsxs20("label", { className: "dd-check-row", htmlFor: `${idPrefix}-label-show-header`, children: [
4949
5157
  /* @__PURE__ */ jsx23(
@@ -5209,7 +5417,7 @@ function WidgetConfigForm({
5209
5417
  }
5210
5418
  )
5211
5419
  ] }),
5212
- widget.type === "labelContainer" && /* @__PURE__ */ jsxs20(Fragment9, { children: [
5420
+ widget.type === "labelContainer" && /* @__PURE__ */ jsxs20(Fragment10, { children: [
5213
5421
  /* @__PURE__ */ jsxs20("div", { className: "dd-field dd-check-field", children: [
5214
5422
  /* @__PURE__ */ jsxs20("label", { className: "dd-check-row", htmlFor: `${idPrefix}-lc-show-header`, children: [
5215
5423
  /* @__PURE__ */ jsx23(
@@ -5492,7 +5700,7 @@ function WidgetConfigForm({
5492
5700
  ),
5493
5701
  /* @__PURE__ */ jsx23("span", { className: "dd-check-row-text", children: t("labelOpenDashboard") })
5494
5702
  ] }) }),
5495
- template.targetDashboardId && /* @__PURE__ */ jsxs20(Fragment9, { children: [
5703
+ template.targetDashboardId && /* @__PURE__ */ jsxs20(Fragment10, { children: [
5496
5704
  /* @__PURE__ */ jsxs20("div", { className: "dd-field dd-field-tight", children: [
5497
5705
  /* @__PURE__ */ jsx23(FieldLabel, { htmlFor: `${idPrefix}-lc-tpl-target`, children: t("drillTargetDashboard") }),
5498
5706
  /* @__PURE__ */ jsxs20(
@@ -5769,7 +5977,7 @@ function WidgetConfigForm({
5769
5977
  ] })
5770
5978
  ] })
5771
5979
  ] }),
5772
- widget.type !== "label" && (widget.type !== "labelContainer" || labelContainerQuery) && /* @__PURE__ */ jsxs20(Fragment9, { children: [
5980
+ widget.type !== "label" && (widget.type !== "labelContainer" || labelContainerQuery) && /* @__PURE__ */ jsxs20(Fragment10, { children: [
5773
5981
  /* @__PURE__ */ jsxs20("details", { className: "dd-config-section", open: true, children: [
5774
5982
  /* @__PURE__ */ jsxs20("summary", { children: [
5775
5983
  /* @__PURE__ */ jsx23("span", { children: "Data & columns" }),
@@ -6168,7 +6376,7 @@ function WidgetConfigForm({
6168
6376
  ))
6169
6377
  ] })
6170
6378
  ] }),
6171
- widget.type === "listbox" && /* @__PURE__ */ jsxs20(Fragment9, { children: [
6379
+ widget.type === "listbox" && /* @__PURE__ */ jsxs20(Fragment10, { children: [
6172
6380
  /* @__PURE__ */ jsxs20("div", { className: "dd-field", children: [
6173
6381
  /* @__PURE__ */ jsx23(FieldLabel, { htmlFor: `${idPrefix}-filter-field`, help: t("helpListboxFilterField"), children: t("listboxFilterField") }),
6174
6382
  /* @__PURE__ */ jsx23(
@@ -6696,7 +6904,7 @@ function WidgetEditorModal({
6696
6904
  onClick: onCancel,
6697
6905
  "aria-label": t("cancel"),
6698
6906
  title: t("cancel"),
6699
- children: /* @__PURE__ */ jsx24(X4, { size: 18 })
6907
+ children: /* @__PURE__ */ jsx24(X5, { size: 18 })
6700
6908
  }
6701
6909
  )
6702
6910
  ] }),
@@ -6820,7 +7028,7 @@ function WidgetEditorModal({
6820
7028
  ] }),
6821
7029
  /* @__PURE__ */ jsxs21("footer", { className: "dd-modal-footer", children: [
6822
7030
  /* @__PURE__ */ jsxs21("button", { type: "button", className: "dd-btn", onClick: onCancel, children: [
6823
- /* @__PURE__ */ jsx24(X4, { size: ICON_SIZE }),
7031
+ /* @__PURE__ */ jsx24(X5, { size: ICON_SIZE }),
6824
7032
  t("cancel")
6825
7033
  ] }),
6826
7034
  /* @__PURE__ */ jsxs21("button", { type: "button", className: "dd-btn dd-btn-primary", onClick: () => onSave(draft), children: [
@@ -6834,9 +7042,9 @@ function WidgetEditorModal({
6834
7042
  }
6835
7043
 
6836
7044
  // src/designer/HistoryPanel.tsx
6837
- import React19, { useEffect as useEffect15, useMemo as useMemo9, useState as useState17 } from "react";
7045
+ import React19, { useEffect as useEffect15, useMemo as useMemo10, useState as useState17 } from "react";
6838
7046
  import { useTranslation as useTranslation15 } from "react-i18next";
6839
- import { GitBranch, History, RotateCcw as RotateCcw2, X as X5 } from "lucide-react";
7047
+ import { GitBranch, History, RotateCcw as RotateCcw2, X as X6 } from "lucide-react";
6840
7048
  import { jsx as jsx25, jsxs as jsxs22 } from "react/jsx-runtime";
6841
7049
  var LANE_GAP = 18;
6842
7050
  var ROW_H = 72;
@@ -6910,7 +7118,7 @@ function HistoryPanel({
6910
7118
  const [previewLoading, setPreviewLoading] = useState17(false);
6911
7119
  const [restoring, setRestoring] = useState17(false);
6912
7120
  const [error, setError] = useState17(null);
6913
- const graph = useMemo9(() => buildGitGraph(versions), [versions]);
7121
+ const graph = useMemo10(() => buildGitGraph(versions), [versions]);
6914
7122
  const laneCount = Math.max(1, ...graph.map((r) => Math.max(0, ...r.activeLanes) + 1));
6915
7123
  const load = () => {
6916
7124
  setLoading(true);
@@ -6994,7 +7202,7 @@ function HistoryPanel({
6994
7202
  className: "dd-btn dd-btn-ghost dd-btn-icon",
6995
7203
  onClick: onClose,
6996
7204
  "aria-label": t("cancel"),
6997
- children: /* @__PURE__ */ jsx25(X5, { size: 18 })
7205
+ children: /* @__PURE__ */ jsx25(X6, { size: 18 })
6998
7206
  }
6999
7207
  )
7000
7208
  ] }),
@@ -7176,7 +7384,7 @@ function HistoryPanel({
7176
7384
 
7177
7385
  // src/designer/SharePanel.tsx
7178
7386
  import { useEffect as useEffect16, useState as useState18 } from "react";
7179
- import { Plus as Plus3, Trash2 as Trash22, X as X6 } from "lucide-react";
7387
+ import { Plus as Plus3, Trash2 as Trash22, X as X7 } from "lucide-react";
7180
7388
  import { useTranslation as useTranslation16 } from "react-i18next";
7181
7389
  import { jsx as jsx26, jsxs as jsxs23 } from "react/jsx-runtime";
7182
7390
  function SharePanel({ open, onClose, dashboardId, api }) {
@@ -7263,7 +7471,7 @@ function SharePanel({ open, onClose, dashboardId, api }) {
7263
7471
  className: "dd-btn dd-btn-ghost dd-btn-icon",
7264
7472
  onClick: onClose,
7265
7473
  "aria-label": t("cancel"),
7266
- children: /* @__PURE__ */ jsx26(X6, { size: ICON_SIZE })
7474
+ children: /* @__PURE__ */ jsx26(X7, { size: ICON_SIZE })
7267
7475
  }
7268
7476
  )
7269
7477
  ] }),
@@ -7366,7 +7574,7 @@ function SharePanel({ open, onClose, dashboardId, api }) {
7366
7574
 
7367
7575
  // src/designer/EmailComposePanel.tsx
7368
7576
  import { useEffect as useEffect18, useId as useId6, useRef as useRef12, useState as useState19 } from "react";
7369
- import { Mail, Paperclip, Plus as Plus4, Trash2 as Trash23, X as X7 } from "lucide-react";
7577
+ import { Mail, Paperclip, Plus as Plus4, Trash2 as Trash23, X as X8 } from "lucide-react";
7370
7578
  import { useTranslation as useTranslation18 } from "react-i18next";
7371
7579
  import { createId as createId4, resolveEmailOptions } from "@dashboard-designer/core";
7372
7580
 
@@ -7786,7 +7994,7 @@ function EmailComposePanel({
7786
7994
  className: "dd-btn dd-btn-ghost dd-btn-icon",
7787
7995
  onClick: onClose,
7788
7996
  "aria-label": t("cancel"),
7789
- children: /* @__PURE__ */ jsx28(X7, { size: ICON_SIZE })
7997
+ children: /* @__PURE__ */ jsx28(X8, { size: ICON_SIZE })
7790
7998
  }
7791
7999
  )
7792
8000
  ] }),
@@ -7928,8 +8136,8 @@ function EmailComposePanel({
7928
8136
  }
7929
8137
 
7930
8138
  // src/designer/DashboardSettingsPanel.tsx
7931
- import { useEffect as useEffect19, useMemo as useMemo10, useState as useState20 } from "react";
7932
- import { Plus as Plus5, RotateCcw as RotateCcw3, Trash2 as Trash24, X as X8 } from "lucide-react";
8139
+ import { useEffect as useEffect19, useMemo as useMemo11, useState as useState20 } from "react";
8140
+ import { Plus as Plus5, RotateCcw as RotateCcw3, Trash2 as Trash24, X as X9 } from "lucide-react";
7933
8141
  import { useTranslation as useTranslation19 } from "react-i18next";
7934
8142
  import {
7935
8143
  matchThemePreset,
@@ -7939,7 +8147,7 @@ import {
7939
8147
  resolveExportOptions,
7940
8148
  THEME_PRESETS
7941
8149
  } from "@dashboard-designer/core";
7942
- import { jsx as jsx29, jsxs as jsxs26 } from "react/jsx-runtime";
8150
+ import { Fragment as Fragment11, jsx as jsx29, jsxs as jsxs26 } from "react/jsx-runtime";
7943
8151
  var CURRENCIES = ["USD", "EUR", "GBP", "INR", "JPY", "CAD", "AUD", "MXN"];
7944
8152
  var TIMEZONES = [
7945
8153
  "UTC",
@@ -7958,6 +8166,7 @@ function draftFromDashboard(dashboard) {
7958
8166
  const emailOpts = resolveEmailOptions2(dashboard.exportOptions);
7959
8167
  const displayOpts = resolveDisplayOptions(dashboard.displayOptions);
7960
8168
  return {
8169
+ printSettings: { orientation: "landscape", layout: "designed", ...dashboard.printSettings, header: { enabled: true, repeat: true, showPrintedOn: true, showPrintedBy: true, ...structuredClone(dashboard.printSettings?.header ?? {}) } },
7961
8170
  locale: dashboard.locale || "en",
7962
8171
  currency: dashboard.currency || "USD",
7963
8172
  timeZone: dashboard.timeZone || "",
@@ -7996,9 +8205,11 @@ function DashboardSettingsPanel({
7996
8205
  }) {
7997
8206
  const { t } = useTranslation19();
7998
8207
  const [draft, setDraft] = useState20(() => draftFromDashboard(dashboard));
8208
+ const [printFields, setPrintFields] = useState20("");
7999
8209
  useEffect19(() => {
8000
8210
  if (!open) return;
8001
8211
  setDraft(draftFromDashboard(dashboard));
8212
+ setPrintFields((dashboard.printSettings?.header?.fields ?? []).map((f) => `${f.label}: ${f.value}`).join("\n"));
8002
8213
  }, [
8003
8214
  open,
8004
8215
  dashboard.id,
@@ -8008,9 +8219,11 @@ function DashboardSettingsPanel({
8008
8219
  dashboard.dir,
8009
8220
  dashboard.theme,
8010
8221
  dashboard.exportOptions,
8011
- dashboard.displayOptions
8222
+ dashboard.displayOptions,
8223
+ dashboard.printSettings
8012
8224
  ]);
8013
- const presetId = useMemo10(() => {
8225
+ const updateHeader = (patch) => setDraft((d) => ({ ...d, printSettings: { ...d.printSettings, header: { ...d.printSettings.header, ...patch } } }));
8226
+ const presetId = useMemo11(() => {
8014
8227
  const theme = { accent: draft.accent, chartColors: draft.chartColors };
8015
8228
  return matchThemePreset(theme);
8016
8229
  }, [draft.accent, draft.chartColors]);
@@ -8054,6 +8267,7 @@ function DashboardSettingsPanel({
8054
8267
  };
8055
8268
  const displayOptions = draft.showWidgetTypeBadge ? { showWidgetTypeBadge: true } : void 0;
8056
8269
  onChange({
8270
+ printSettings: draft.printSettings,
8057
8271
  locale: draft.locale,
8058
8272
  currency: draft.currency,
8059
8273
  timeZone: draft.timeZone || void 0,
@@ -8082,12 +8296,85 @@ function DashboardSettingsPanel({
8082
8296
  className: "dd-btn dd-btn-ghost dd-btn-icon",
8083
8297
  onClick: onClose,
8084
8298
  "aria-label": t("cancel"),
8085
- children: /* @__PURE__ */ jsx29(X8, { size: ICON_SIZE })
8299
+ children: /* @__PURE__ */ jsx29(X9, { size: ICON_SIZE })
8086
8300
  }
8087
8301
  )
8088
8302
  ] }),
8089
8303
  /* @__PURE__ */ jsxs26("div", { className: "dd-dialog-body", children: [
8090
8304
  /* @__PURE__ */ jsx29("p", { className: "dd-hint", children: t("dashboardSettingsHint") }),
8305
+ /* @__PURE__ */ jsxs26("section", { className: "dd-theme-section", children: [
8306
+ /* @__PURE__ */ jsx29("h3", { children: "Print settings" }),
8307
+ /* @__PURE__ */ jsx29("p", { className: "dd-hint", children: "Saved with this dashboard. Apply these settings, then save the dashboard. User and print time are filled automatically." }),
8308
+ /* @__PURE__ */ jsxs26("div", { className: "dd-settings-grid", children: [
8309
+ /* @__PURE__ */ jsxs26("label", { className: "dd-field", children: [
8310
+ "Default orientation",
8311
+ /* @__PURE__ */ jsxs26("select", { className: "dd-input", value: draft.printSettings.orientation, onChange: (e) => setDraft((d) => ({ ...d, printSettings: { ...d.printSettings, orientation: e.target.value } })), children: [
8312
+ /* @__PURE__ */ jsx29("option", { value: "portrait", children: "Portrait" }),
8313
+ /* @__PURE__ */ jsx29("option", { value: "landscape", children: "Landscape" })
8314
+ ] })
8315
+ ] }),
8316
+ /* @__PURE__ */ jsxs26("label", { className: "dd-field", children: [
8317
+ "Default layout",
8318
+ /* @__PURE__ */ jsxs26("select", { className: "dd-input", value: draft.printSettings.layout, onChange: (e) => setDraft((d) => ({ ...d, printSettings: { ...d.printSettings, layout: e.target.value } })), children: [
8319
+ /* @__PURE__ */ jsx29("option", { value: "designed", children: "As designed" }),
8320
+ /* @__PURE__ */ jsx29("option", { value: "one-column", children: "1 column" }),
8321
+ /* @__PURE__ */ jsx29("option", { value: "two-column", children: "2 columns" })
8322
+ ] })
8323
+ ] })
8324
+ ] }),
8325
+ " ",
8326
+ /* @__PURE__ */ jsxs26("fieldset", { className: "dd-print-header-settings", children: [
8327
+ /* @__PURE__ */ jsx29("legend", { children: "Report header" }),
8328
+ /* @__PURE__ */ jsxs26("label", { className: "dd-print-header-toggle", children: [
8329
+ /* @__PURE__ */ jsx29("input", { type: "checkbox", checked: draft.printSettings.header?.enabled !== false, onChange: (e) => updateHeader({ enabled: e.target.checked }) }),
8330
+ "Show header"
8331
+ ] }),
8332
+ draft.printSettings.header?.enabled !== false && /* @__PURE__ */ jsxs26(Fragment11, { children: [
8333
+ /* @__PURE__ */ jsxs26("label", { children: [
8334
+ "Report title",
8335
+ /* @__PURE__ */ jsx29("input", { className: "dd-input", value: draft.printSettings.header?.title ?? "", onChange: (e) => updateHeader({ title: e.target.value }) })
8336
+ ] }),
8337
+ /* @__PURE__ */ jsxs26("label", { children: [
8338
+ "Organization",
8339
+ /* @__PURE__ */ jsx29("input", { className: "dd-input", value: draft.printSettings.header?.organization ?? "", onChange: (e) => updateHeader({ organization: e.target.value }) })
8340
+ ] }),
8341
+ /* @__PURE__ */ jsxs26("label", { children: [
8342
+ "Logo URL",
8343
+ /* @__PURE__ */ jsx29("input", { className: "dd-input", placeholder: "https://\u2026 or an image path", value: draft.printSettings.header?.logoUrl ?? "", onChange: (e) => updateHeader({ logoUrl: e.target.value }) })
8344
+ ] }),
8345
+ /* @__PURE__ */ jsxs26("label", { children: [
8346
+ "Upload logo",
8347
+ /* @__PURE__ */ jsx29("input", { type: "file", accept: "image/png,image/jpeg,image/webp,image/svg+xml", onChange: (e) => {
8348
+ const file = e.target.files?.[0];
8349
+ if (!file) return;
8350
+ const reader = new FileReader();
8351
+ reader.onload = () => updateHeader({ logoUrl: String(reader.result) });
8352
+ reader.readAsDataURL(file);
8353
+ } })
8354
+ ] }),
8355
+ /* @__PURE__ */ jsxs26("label", { className: "dd-print-header-toggle", children: [
8356
+ /* @__PURE__ */ jsx29("input", { type: "checkbox", checked: draft.printSettings.header?.showPrintedBy !== false, onChange: (e) => updateHeader({ showPrintedBy: e.target.checked }) }),
8357
+ "Show printed-by user (set automatically)"
8358
+ ] }),
8359
+ /* @__PURE__ */ jsxs26("label", { className: "dd-print-header-toggle", children: [
8360
+ /* @__PURE__ */ jsx29("input", { type: "checkbox", checked: draft.printSettings.header?.showPrintedOn !== false, onChange: (e) => updateHeader({ showPrintedOn: e.target.checked }) }),
8361
+ "Include print date and time"
8362
+ ] }),
8363
+ /* @__PURE__ */ jsxs26("label", { className: "dd-print-header-toggle", children: [
8364
+ /* @__PURE__ */ jsx29("input", { type: "checkbox", checked: draft.printSettings.header?.repeat !== false, onChange: (e) => updateHeader({ repeat: e.target.checked }) }),
8365
+ "Repeat on every page"
8366
+ ] }),
8367
+ /* @__PURE__ */ jsxs26("label", { children: [
8368
+ "Additional fields",
8369
+ /* @__PURE__ */ jsx29("textarea", { className: "dd-input", rows: 3, placeholder: "Department: Quality\nReference: RPT-001", value: printFields, onChange: (e) => {
8370
+ setPrintFields(e.target.value);
8371
+ updateHeader({ fields: parsePrintHeaderFields(e.target.value) });
8372
+ } })
8373
+ ] }),
8374
+ /* @__PURE__ */ jsx29("p", { className: "dd-hint", children: "One Label: value per line. The timestamp is set when Print is clicked." })
8375
+ ] })
8376
+ ] })
8377
+ ] }),
8091
8378
  /* @__PURE__ */ jsxs26("div", { className: "dd-settings-grid", children: [
8092
8379
  /* @__PURE__ */ jsxs26("div", { className: "dd-field", children: [
8093
8380
  /* @__PURE__ */ jsx29(FieldLabel, { htmlFor: "dd-dash-locale", help: t("helpLocale"), children: t("locale") }),
@@ -8657,7 +8944,7 @@ function useDashboardHistory(initial, onChange, readOnly = false) {
8657
8944
  }
8658
8945
 
8659
8946
  // src/designer/DashboardDesigner.tsx
8660
- import { Fragment as Fragment10, jsx as jsx30, jsxs as jsxs27 } from "react/jsx-runtime";
8947
+ import { Fragment as Fragment12, jsx as jsx30, jsxs as jsxs27 } from "react/jsx-runtime";
8661
8948
  function listboxFilterField(widget) {
8662
8949
  const override = widget.chartOptions.filterField;
8663
8950
  if (typeof override === "string" && override.trim()) return override.trim();
@@ -8742,7 +9029,7 @@ function WidgetCard({
8742
9029
  const filterSignature = JSON.stringify(configuredFilters);
8743
9030
  useEffect21(() => setFilterValues(null), [filterSignature]);
8744
9031
  const widgetFilters = filterValues ?? configuredFilters;
8745
- const filteredWidget = useMemo11(() => ({ ...widget, frontendFilters: [...widget.frontendFilters ?? [], ...widgetFilters] }), [widget, filterValues, filterSignature]);
9032
+ const filteredWidget = useMemo12(() => ({ ...widget, frontendFilters: [...widget.frontendFilters ?? [], ...widgetFilters] }), [widget, filterValues, filterSignature]);
8746
9033
  const { data, suggestionData, error, loading } = useWidgetData(api, filteredWidget, globalFilters, refreshKey, { dashboardId, manualRefreshKey });
8747
9034
  useEffect21(() => {
8748
9035
  onRefreshState(widget.id, { scope: refreshScope, loading: loading || !data && !error, error: Boolean(error), fetchedAt: data?.fetchedAt });
@@ -8781,7 +9068,7 @@ function WidgetCard({
8781
9068
  /* @__PURE__ */ jsx30(TypeIcon, { size: 12, strokeWidth: 2.25, "aria-hidden": true }),
8782
9069
  widget.type
8783
9070
  ] }),
8784
- !readOnly && /* @__PURE__ */ jsxs27(Fragment10, { children: [
9071
+ !readOnly && /* @__PURE__ */ jsxs27(Fragment12, { children: [
8785
9072
  /* @__PURE__ */ jsx30(
8786
9073
  "button",
8787
9074
  {
@@ -8891,6 +9178,7 @@ function WidgetCard({
8891
9178
  }
8892
9179
  function DashboardDesigner({
8893
9180
  dashboard: initial,
9181
+ printHeader,
8894
9182
  apiBaseUrl,
8895
9183
  auth,
8896
9184
  locale = "en",
@@ -8909,8 +9197,8 @@ function DashboardDesigner({
8909
9197
  }) {
8910
9198
  ensureI18n(locale);
8911
9199
  const { t, i18n: i18n2 } = useTranslation20();
8912
- const api = useMemo11(() => new DashboardApiClient(apiBaseUrl, auth), [apiBaseUrl, auth]);
8913
- const seed = useMemo11(() => initial ?? createEmptyDashboard(), [initial]);
9200
+ const api = useMemo12(() => new DashboardApiClient(apiBaseUrl, auth), [apiBaseUrl, auth]);
9201
+ const seed = useMemo12(() => initial ?? createEmptyDashboard(), [initial]);
8914
9202
  const {
8915
9203
  dashboard,
8916
9204
  commitDashboard,
@@ -8928,7 +9216,7 @@ function DashboardDesigner({
8928
9216
  canRedo,
8929
9217
  canReset
8930
9218
  } = useDashboardHistory(seed, onChange, readOnly);
8931
- const variableContext = useVariableRuntime(dashboard, { predefinedVariables, variableValues, variablesReady, resolveVariables });
9219
+ const baseVariableContext = useVariableRuntime(dashboard, { predefinedVariables, variableValues, variablesReady, resolveVariables });
8932
9220
  const [variablesOpen, setVariablesOpen] = useState22(false);
8933
9221
  const [editingTitle, setEditingTitle] = useState22(false);
8934
9222
  const [historyOpen, setHistoryOpen] = useState22(false);
@@ -8952,6 +9240,13 @@ function DashboardDesigner({
8952
9240
  }, [readOnly]);
8953
9241
  const [selectedId, setSelectedId] = useState22(null);
8954
9242
  const [connections, setConnections] = useState22([]);
9243
+ const [connectionSourcesLoaded, setConnectionSourcesLoaded] = useState22(false);
9244
+ const missingConnections = connectionVariableNames2(dashboard).filter((name) => !connections.some((c) => c.id === `connvar:${name}`));
9245
+ const variableContext = {
9246
+ ...baseVariableContext,
9247
+ ready: baseVariableContext.ready && missingConnections.length === 0,
9248
+ error: baseVariableContext.error || (connectionSourcesLoaded && missingConnections.length ? `Configure connection variables: ${missingConnections.join(", ")} in Variables.` : void 0)
9249
+ };
8955
9250
  const [refreshKey, setRefreshKey] = useState22(0);
8956
9251
  const [manualRefreshKey, setManualRefreshKey] = useState22(0);
8957
9252
  const [widgetRefreshStates, setWidgetRefreshStates] = useState22({});
@@ -9016,7 +9311,7 @@ function DashboardDesigner({
9016
9311
  toolbarRefreshWaiters.current.forEach((waiter) => waiter.resolve());
9017
9312
  toolbarRefreshWaiters.current = [];
9018
9313
  }, []);
9019
- const layoutForGrid = useMemo11(() => {
9314
+ const layoutForGrid = useMemo12(() => {
9020
9315
  if (effectiveReadOnly) {
9021
9316
  return dashboard.layout.map((item) => ({
9022
9317
  i: item.i,
@@ -9050,10 +9345,23 @@ function DashboardDesigner({
9050
9345
  const themeStyle = dashboardThemeCssVars(dashboard.theme);
9051
9346
  const exportOpts = resolveExportOptions2(dashboard.exportOptions);
9052
9347
  const displayOpts = resolveDisplayOptions2(dashboard.displayOptions);
9348
+ const [printUser, setPrintUser] = useState22("");
9349
+ useEffect21(() => {
9350
+ let active = true;
9351
+ setPrintUser("");
9352
+ if (auth.mode !== "anonymous") void api.me().then((r) => {
9353
+ if (active) setPrintUser(r.user.name);
9354
+ }).catch(() => {
9355
+ });
9356
+ return () => {
9357
+ active = false;
9358
+ };
9359
+ }, [api]);
9360
+ const headerDefaults = resolvePrintHeader(dashboard.title, dashboard.printSettings, printHeader, printUser);
9053
9361
  const [printOptionsOpen, setPrintOptionsOpen] = useState22(false);
9054
9362
  const handlePrint = () => setPrintOptionsOpen(true);
9055
9363
  const handleExportPdf = () => {
9056
- exportDashboardPdf(document.getElementById("dd-canvas"), dashboard.title);
9364
+ exportDashboardPdf(document.getElementById("dd-canvas"), dashboard.title, { orientation: dashboard.printSettings?.orientation ?? "landscape", layout: dashboard.printSettings?.layout ?? "designed", header: headerDefaults });
9057
9365
  };
9058
9366
  const handleExportJson = () => {
9059
9367
  downloadDashboardJson(dashboard);
@@ -9074,8 +9382,24 @@ function DashboardDesigner({
9074
9382
  void i18n2.changeLanguage(effectiveLocale);
9075
9383
  }, [effectiveLocale, i18n2]);
9076
9384
  useEffect21(() => {
9077
- api.listConnections().then((r) => setConnections(r.connections)).catch(() => setConnections([]));
9078
- }, [api]);
9385
+ let active = true;
9386
+ setConnectionSourcesLoaded(false);
9387
+ setConnections([]);
9388
+ api.listConnectionSources().then((r) => {
9389
+ if (!active) return;
9390
+ setConnectionSourcesLoaded(true);
9391
+ setConnections(r.connections);
9392
+ if (!effectiveReadOnly && connectionVariableNames2(dashboard).some((name) => !r.connections.some((c) => c.id === `connvar:${name}`))) setVariablesOpen(true);
9393
+ }).catch(() => {
9394
+ if (active) {
9395
+ setConnections([]);
9396
+ setConnectionSourcesLoaded(true);
9397
+ }
9398
+ });
9399
+ return () => {
9400
+ active = false;
9401
+ };
9402
+ }, [api, dashboard.id, effectiveReadOnly]);
9079
9403
  useEffect21(() => {
9080
9404
  const el = document.getElementById("dd-canvas");
9081
9405
  if (!el) return;
@@ -9310,7 +9634,7 @@ function DashboardDesigner({
9310
9634
  children: /* @__PURE__ */ jsxs27(VariableContext.Provider, { value: variableContext, children: [
9311
9635
  variableContext.error && /* @__PURE__ */ jsx30("div", { className: "dd-error", role: "alert", children: variableContext.error }),
9312
9636
  !variableContext.ready && !variableContext.error && /* @__PURE__ */ jsx30("div", { role: "status", className: "dd-hint", children: "Loading variables\u2026" }),
9313
- printOptionsOpen && /* @__PURE__ */ jsx30(PrintOptionsDialog, { onClose: () => setPrintOptionsOpen(false), onPrint: (options) => {
9637
+ printOptionsOpen && /* @__PURE__ */ jsx30(PrintOptionsDialog, { defaults: { orientation: dashboard.printSettings?.orientation ?? "landscape", layout: dashboard.printSettings?.layout ?? "designed" }, header: headerDefaults, onClose: () => setPrintOptionsOpen(false), onPrint: (options) => {
9314
9638
  setPrintOptionsOpen(false);
9315
9639
  printDashboard(document.getElementById("dd-canvas"), dashboard.title, options);
9316
9640
  } }),
@@ -9397,7 +9721,7 @@ function DashboardDesigner({
9397
9721
  ),
9398
9722
  toolbarVisibility.lastRefresh !== false && /* @__PURE__ */ jsxs27("span", { className: "dd-hint", role: "status", title: t("lastRefreshHint"), children: [
9399
9723
  refreshing ? t("refreshingDashboard") : refreshFailed ? t("dashboardRefreshFailed") : "",
9400
- lastRefresh?.dashboardId === dashboard.id && /* @__PURE__ */ jsxs27(Fragment10, { children: [
9724
+ lastRefresh?.dashboardId === dashboard.id && /* @__PURE__ */ jsxs27(Fragment12, { children: [
9401
9725
  " ",
9402
9726
  t("lastRefresh"),
9403
9727
  ": ",
@@ -9477,7 +9801,7 @@ function DashboardDesigner({
9477
9801
  ]
9478
9802
  }
9479
9803
  ),
9480
- !effectiveReadOnly && /* @__PURE__ */ jsxs27(Fragment10, { children: [
9804
+ !effectiveReadOnly && /* @__PURE__ */ jsxs27(Fragment12, { children: [
9481
9805
  toolbarVisibility.share !== false && /* @__PURE__ */ jsxs27(
9482
9806
  "button",
9483
9807
  {
@@ -9707,6 +10031,13 @@ function DashboardDesigner({
9707
10031
  variablesOpen && !effectiveReadOnly && /* @__PURE__ */ jsx30(
9708
10032
  VariablesModal,
9709
10033
  {
10034
+ api,
10035
+ onBindingsChanged: () => {
10036
+ void api.listConnectionSources().then((r) => {
10037
+ setConnections(r.connections);
10038
+ setRefreshKey((k) => k + 1);
10039
+ });
10040
+ },
9710
10041
  dashboard,
9711
10042
  predefined: predefinedVariables ?? [],
9712
10043
  onClose: () => setVariablesOpen(false),