@dashboard-designer/core 0.1.1 → 0.1.15

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Supported database providers (Phase 1 includes SQL Server). */
2
2
  type DbProvider = 'sqlite' | 'postgres' | 'mysql' | 'mssql';
3
- type WidgetType = 'bar' | 'line' | 'pie' | 'table' | 'kpi' | 'listbox';
3
+ type WidgetType = 'bar' | 'line' | 'pie' | 'table' | 'kpi' | 'listbox' | 'label' | 'labelContainer';
4
4
  type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'nin' | 'like' | 'between' | 'is_null' | 'not_null';
5
5
  type JoinType = 'inner' | 'left' | 'right' | 'full';
6
6
  type AuthMode = 'token' | 'anonymous';
@@ -80,6 +80,36 @@ interface DrillDownDef {
80
80
  passFields: string[];
81
81
  title?: string;
82
82
  }
83
+ /** One label inside a labelContainer widget (no per-label header). */
84
+ interface ContainerLabelItem {
85
+ id: string;
86
+ text: string;
87
+ color?: string;
88
+ backgroundColor?: string;
89
+ fontSize?: number;
90
+ targetDashboardId?: string;
91
+ drillTitle?: string;
92
+ }
93
+ /** Styles and drill target applied to every label generated from a query column. */
94
+ interface ContainerLabelTemplate {
95
+ color?: string;
96
+ backgroundColor?: string;
97
+ fontSize?: number;
98
+ targetDashboardId?: string;
99
+ drillTitle?: string;
100
+ }
101
+ type LabelContainerSource = 'static' | 'query';
102
+ type ContainerLabelLayout = 'vertical' | 'horizontal';
103
+ type ChartGuidelineAxis = 'x' | 'y';
104
+ /** Reference line on a bar or line chart axis. */
105
+ interface ChartAxisGuideline {
106
+ id: string;
107
+ axis: ChartGuidelineAxis;
108
+ /** Category label for X, numeric value for Y (stored as string). */
109
+ value: string;
110
+ label?: string;
111
+ color?: string;
112
+ }
83
113
  interface Widget {
84
114
  id: string;
85
115
  type: WidgetType;
@@ -104,11 +134,13 @@ interface Dashboard {
104
134
  /** Optional visual theme (accent + chart palette). Omit / reset for defaults. */
105
135
  theme?: DashboardTheme;
106
136
  /**
107
- * Toolbar export actions. When omitted, print and PDF are enabled; email is off.
108
- * Set `print: false` / `pdf: false` to hide each action; set `email: true` to show Send email.
137
+ * Toolbar export actions. When omitted, print, PDF, and JSON export are enabled; email is off.
138
+ * Set `print: false` / `pdf: false` / `json: false` to hide each action; set `email: true` to show Send email.
109
139
  * Use `emailOptions` to control dashboard PDF and extra file attachments.
110
140
  */
111
141
  exportOptions?: DashboardExportOptions;
142
+ /** View-mode display preferences (widget chrome, etc.). */
143
+ displayOptions?: DashboardDisplayOptions;
112
144
  layout: GridItem[];
113
145
  globalFilters: FilterDef[];
114
146
  widgets: Widget[];
@@ -129,13 +161,38 @@ interface DashboardExportOptions {
129
161
  print?: boolean;
130
162
  /** Show Export PDF in the toolbar (default true). */
131
163
  pdf?: boolean;
164
+ /** Show Export JSON in the toolbar (default true). */
165
+ json?: boolean;
132
166
  /** Show Send email in the toolbar (default false; requires SMTP on the API). */
133
167
  email?: boolean;
134
168
  /** Attachment behavior for Send email (ignored when email is off). */
135
169
  emailOptions?: DashboardEmailOptions;
136
170
  }
137
- declare function resolveExportOptions(options?: DashboardExportOptions | null): Required<Pick<DashboardExportOptions, 'print' | 'pdf' | 'email'>>;
171
+ interface DashboardDisplayOptions {
172
+ /** Show chart-type badge on widget headers in view / readonly mode (default false). */
173
+ showWidgetTypeBadge?: boolean;
174
+ }
175
+ declare function resolveDisplayOptions(options?: DashboardDisplayOptions | null): Required<DashboardDisplayOptions>;
176
+ declare function resolveExportOptions(options?: DashboardExportOptions | null): Required<Pick<DashboardExportOptions, 'print' | 'pdf' | 'json' | 'email'>>;
138
177
  declare function resolveEmailOptions(options?: DashboardExportOptions | null): Required<DashboardEmailOptions>;
178
+ /** Marker written into exported dashboard JSON files. */
179
+ declare const DASHBOARD_FILE_FORMAT: "dashboard-designer";
180
+ declare const DASHBOARD_FILE_VERSION = 1;
181
+ interface DashboardFileEnvelope {
182
+ format: typeof DASHBOARD_FILE_FORMAT;
183
+ version: number;
184
+ exportedAt: string;
185
+ dashboard: Dashboard;
186
+ }
187
+ /** Build a portable JSON document for download (keeps current IDs). */
188
+ declare function buildDashboardExportFile(dashboard: Dashboard): DashboardFileEnvelope;
189
+ /**
190
+ * Clone a dashboard for import: new dashboard/widget/layout/filter IDs.
191
+ * Connection IDs and cross-dashboard drill targets are preserved.
192
+ */
193
+ declare function cloneDashboardForImport(source: Dashboard, titleSuffix?: string): Dashboard;
194
+ /** Parse JSON text from an export file (or a bare Dashboard object). */
195
+ declare function parseDashboardImport(raw: unknown): Dashboard;
139
196
  interface DashboardTheme {
140
197
  /** UI accent used for buttons, links, KPI emphasis. */
141
198
  accent?: string;
@@ -198,6 +255,8 @@ interface ConnectionConfig {
198
255
  /** File path for SQLite */
199
256
  filename?: string;
200
257
  ssl?: boolean;
258
+ /** SQL Server Windows authentication (Integrated Security) */
259
+ integratedSecurity?: boolean;
201
260
  /** Allow anonymous embed to use this connection */
202
261
  allowAnonymous?: boolean;
203
262
  }
@@ -229,7 +288,35 @@ declare const DB_PROVIDERS: DbProvider[];
229
288
  /** Locales that default to RTL when dashboard.dir is unset. */
230
289
  declare const RTL_LOCALES: Set<string>;
231
290
  declare function resolveDashboardDir(dashboard: Pick<Dashboard, 'dir' | 'locale'>): 'ltr' | 'rtl';
291
+ /** Legacy hardcoded label foreground from early defaults; treat as theme default. */
292
+ declare const LEGACY_LABEL_FOREGROUND = "#1a2b2b";
293
+ declare function sanitizeLabelStyleColor(color: string | undefined): string | undefined;
294
+ declare function sanitizeLabelStyleBackground(bg: string | undefined): string | undefined;
295
+ declare function normalizeContainerLabels(raw: unknown): ContainerLabelItem[];
296
+ declare function createContainerLabelItem(text?: string): ContainerLabelItem;
297
+ declare function hasContainerLabelCustomStyles(item: ContainerLabelItem): boolean;
298
+ /** Remove per-label color, background, and font size so theme defaults apply. */
299
+ declare function resetContainerLabelItemStyles(item: ContainerLabelItem): ContainerLabelItem;
300
+ declare function normalizeContainerLabelTemplate(raw: unknown): ContainerLabelTemplate;
301
+ declare function hasContainerLabelTemplateCustomStyles(template: ContainerLabelTemplate): boolean;
302
+ declare function resetContainerLabelTemplateStyles(template: ContainerLabelTemplate): ContainerLabelTemplate;
303
+ declare function resolveLabelContainerSource(chartOptions: Record<string, unknown>): LabelContainerSource;
304
+ /** Build label items from distinct values in a query result column, applying a shared template. */
305
+ declare function buildContainerLabelsFromQuery(rows: Record<string, unknown>[], columns: string[], dimensionField: string | undefined, template: ContainerLabelTemplate): ContainerLabelItem[];
306
+ /** Whether label / labelContainer widgets show the widget title bar on the canvas (default true). */
307
+ declare function labelWidgetShowsHeader(chartOptions: Record<string, unknown>): boolean;
308
+ type LabelClickAction = 'none' | 'dashboard' | 'url';
309
+ /** Resolved click behavior for a label widget (dashboard drill-down or external URL). */
310
+ declare function resolveLabelClickAction(chartOptions: Record<string, unknown>, drillDown?: DrillDownDef): LabelClickAction;
311
+ declare function getLabelClickUrl(chartOptions: Record<string, unknown>): string | undefined;
312
+ /** Whether a label URL click opens a new browser tab (default true). */
313
+ declare function labelClickOpensNewTab(chartOptions: Record<string, unknown>): boolean;
314
+ /** Parsed KPI default when query returns no rows or an empty value. */
315
+ declare function getKpiDefaultValue(chartOptions: Record<string, unknown>): unknown | undefined;
316
+ declare function createChartAxisGuideline(axis?: ChartGuidelineAxis, value?: string): ChartAxisGuideline;
317
+ declare function normalizeChartAxisGuidelines(raw: unknown): ChartAxisGuideline[];
232
318
  declare function createEmptyDashboard(partial?: Partial<Dashboard>): Dashboard;
233
319
  declare function createEmptyWidget(type?: WidgetType): Widget;
320
+ declare function createId(): string;
234
321
 
235
- export { type AuthConfig, type AuthMode, type ConnectionConfig, DB_PROVIDERS, DEFAULT_CHART_COLORS, DEFAULT_THEME_ACCENT, type Dashboard, type DashboardAclEntry, type DashboardEmailOptions, type DashboardExportOptions, type DashboardPermission, type DashboardTheme, type DashboardVersion, type DashboardVersionMeta, type DataBinding, type DbProvider, type DrillDownDef, type EmbedTokenRequest, type EmbedTokenResponse, type ExecuteQueryRequest, type FilterDef, type FilterOperator, type GridItem, type JoinDef, type JoinType, type QueryColumn, type QueryDef, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, WIDGET_TYPES, type Widget, type WidgetType, createEmptyDashboard, createEmptyWidget, isDefaultDashboardTheme, matchThemePreset, resolveDashboardDir, resolveDashboardTheme, resolveEmailOptions, resolveExportOptions };
322
+ export { type AuthConfig, type AuthMode, type ChartAxisGuideline, type ChartGuidelineAxis, type ConnectionConfig, type ContainerLabelItem, type ContainerLabelLayout, type ContainerLabelTemplate, DASHBOARD_FILE_FORMAT, DASHBOARD_FILE_VERSION, DB_PROVIDERS, DEFAULT_CHART_COLORS, DEFAULT_THEME_ACCENT, type Dashboard, type DashboardAclEntry, type DashboardDisplayOptions, type DashboardEmailOptions, type DashboardExportOptions, type DashboardFileEnvelope, type DashboardPermission, type DashboardTheme, type DashboardVersion, type DashboardVersionMeta, type DataBinding, type DbProvider, type DrillDownDef, type EmbedTokenRequest, type EmbedTokenResponse, type ExecuteQueryRequest, type FilterDef, type FilterOperator, type GridItem, type JoinDef, type JoinType, LEGACY_LABEL_FOREGROUND, type LabelClickAction, type LabelContainerSource, type QueryColumn, type QueryDef, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, WIDGET_TYPES, type Widget, type WidgetType, buildContainerLabelsFromQuery, buildDashboardExportFile, cloneDashboardForImport, createChartAxisGuideline, createContainerLabelItem, createEmptyDashboard, createEmptyWidget, createId, getKpiDefaultValue, getLabelClickUrl, hasContainerLabelCustomStyles, hasContainerLabelTemplateCustomStyles, isDefaultDashboardTheme, labelClickOpensNewTab, labelWidgetShowsHeader, matchThemePreset, normalizeChartAxisGuidelines, normalizeContainerLabelTemplate, normalizeContainerLabels, parseDashboardImport, resetContainerLabelItemStyles, resetContainerLabelTemplateStyles, resolveDashboardDir, resolveDashboardTheme, resolveDisplayOptions, resolveEmailOptions, resolveExportOptions, resolveLabelClickAction, resolveLabelContainerSource, sanitizeLabelStyleBackground, sanitizeLabelStyleColor };
package/dist/index.js CHANGED
@@ -1,8 +1,14 @@
1
1
  // src/index.ts
2
+ function resolveDisplayOptions(options) {
3
+ return {
4
+ showWidgetTypeBadge: options?.showWidgetTypeBadge === true
5
+ };
6
+ }
2
7
  function resolveExportOptions(options) {
3
8
  return {
4
9
  print: options?.print !== false,
5
10
  pdf: options?.pdf !== false,
11
+ json: options?.json !== false,
6
12
  email: options?.email === true
7
13
  };
8
14
  }
@@ -16,6 +22,96 @@ function resolveEmailOptions(options) {
16
22
  maxExtraAttachments
17
23
  };
18
24
  }
25
+ var DASHBOARD_FILE_FORMAT = "dashboard-designer";
26
+ var DASHBOARD_FILE_VERSION = 1;
27
+ function buildDashboardExportFile(dashboard) {
28
+ return {
29
+ format: DASHBOARD_FILE_FORMAT,
30
+ version: DASHBOARD_FILE_VERSION,
31
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
32
+ dashboard: structuredClone(dashboard)
33
+ };
34
+ }
35
+ function remapFilterIds(filters, idMap) {
36
+ return filters.map((f) => {
37
+ const nextId = idMap.get(f.id) || createId();
38
+ idMap.set(f.id, nextId);
39
+ const bind = f.bindToGlobalId && idMap.has(f.bindToGlobalId) ? idMap.get(f.bindToGlobalId) : f.bindToGlobalId;
40
+ return { ...f, id: nextId, bindToGlobalId: bind };
41
+ });
42
+ }
43
+ function cloneDashboardForImport(source, titleSuffix = " (imported)") {
44
+ const idMap = /* @__PURE__ */ new Map();
45
+ const widgetIdMap = /* @__PURE__ */ new Map();
46
+ for (const w of source.widgets ?? []) {
47
+ widgetIdMap.set(w.id, createId());
48
+ }
49
+ const globalFilters = remapFilterIds(
50
+ (source.globalFilters ?? []).map((f) => ({ ...f })),
51
+ idMap
52
+ );
53
+ const widgets = (source.widgets ?? []).map((w) => {
54
+ const nextId = widgetIdMap.get(w.id) || createId();
55
+ const chartOptions = structuredClone(w.chartOptions ?? {});
56
+ const labels = normalizeContainerLabels(chartOptions.labels);
57
+ if (labels.length) {
58
+ chartOptions.labels = labels.map((item) => ({
59
+ ...item,
60
+ id: createId()
61
+ }));
62
+ }
63
+ const guidelines = normalizeChartAxisGuidelines(chartOptions.axisGuidelines);
64
+ if (guidelines.length) {
65
+ chartOptions.axisGuidelines = guidelines.map((g) => ({
66
+ ...g,
67
+ id: createId()
68
+ }));
69
+ }
70
+ const joins = (w.query.joins ?? []).map((j) => ({ ...j, id: createId() }));
71
+ return {
72
+ ...w,
73
+ id: nextId,
74
+ filters: remapFilterIds((w.filters ?? []).map((f) => ({ ...f })), idMap),
75
+ chartOptions,
76
+ query: {
77
+ ...w.query,
78
+ joins
79
+ }
80
+ };
81
+ });
82
+ const layout = (source.layout ?? []).map((item) => ({
83
+ ...item,
84
+ i: widgetIdMap.get(item.i) || createId()
85
+ }));
86
+ const now = (/* @__PURE__ */ new Date()).toISOString();
87
+ return {
88
+ ...source,
89
+ id: createId(),
90
+ title: `${source.title || "Dashboard"}${titleSuffix}`,
91
+ widgets,
92
+ layout,
93
+ globalFilters,
94
+ ownerId: void 0,
95
+ createdAt: now,
96
+ updatedAt: now
97
+ };
98
+ }
99
+ function parseDashboardImport(raw) {
100
+ if (!raw || typeof raw !== "object") {
101
+ throw new Error("Invalid dashboard file");
102
+ }
103
+ const obj = raw;
104
+ let dashboardRaw = obj;
105
+ if (obj.format === DASHBOARD_FILE_FORMAT && obj.dashboard && typeof obj.dashboard === "object") {
106
+ dashboardRaw = obj.dashboard;
107
+ }
108
+ const d = dashboardRaw;
109
+ if (!d || typeof d !== "object") throw new Error("Invalid dashboard file");
110
+ if (!Array.isArray(d.widgets) || !Array.isArray(d.layout)) {
111
+ throw new Error("Dashboard file must include widgets and layout arrays");
112
+ }
113
+ return cloneDashboardForImport(d);
114
+ }
19
115
  var DEFAULT_THEME_ACCENT = "#0d6b54";
20
116
  var DEFAULT_CHART_COLORS = [
21
117
  "#0f6e56",
@@ -77,7 +173,16 @@ function matchThemePreset(theme) {
77
173
  }
78
174
  return "custom";
79
175
  }
80
- var WIDGET_TYPES = ["bar", "line", "pie", "table", "kpi", "listbox"];
176
+ var WIDGET_TYPES = [
177
+ "bar",
178
+ "line",
179
+ "pie",
180
+ "table",
181
+ "kpi",
182
+ "listbox",
183
+ "label",
184
+ "labelContainer"
185
+ ];
81
186
  var DB_PROVIDERS = ["sqlite", "postgres", "mysql", "mssql"];
82
187
  var RTL_LOCALES = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur"]);
83
188
  function resolveDashboardDir(dashboard) {
@@ -85,6 +190,178 @@ function resolveDashboardDir(dashboard) {
85
190
  const lang = (dashboard.locale || "en").split("-")[0]?.toLowerCase() || "en";
86
191
  return RTL_LOCALES.has(lang) ? "rtl" : "ltr";
87
192
  }
193
+ var LEGACY_LABEL_FOREGROUND = "#1a2b2b";
194
+ function sanitizeLabelStyleColor(color) {
195
+ if (!color?.trim()) return void 0;
196
+ if (color.trim().toLowerCase() === LEGACY_LABEL_FOREGROUND) return void 0;
197
+ return color;
198
+ }
199
+ function sanitizeLabelStyleBackground(bg) {
200
+ if (!bg?.trim()) return void 0;
201
+ const v = bg.trim().toLowerCase();
202
+ if (v === "transparent") return void 0;
203
+ return bg.trim();
204
+ }
205
+ function normalizeContainerLabels(raw) {
206
+ if (!Array.isArray(raw)) return [];
207
+ const out = [];
208
+ for (const item of raw) {
209
+ if (!item || typeof item !== "object") continue;
210
+ const o = item;
211
+ const text = typeof o.text === "string" ? o.text : "";
212
+ const id = typeof o.id === "string" && o.id.trim() ? o.id : cryptoRandomId();
213
+ out.push({
214
+ id,
215
+ text,
216
+ color: sanitizeLabelStyleColor(typeof o.color === "string" ? o.color : void 0),
217
+ backgroundColor: sanitizeLabelStyleBackground(
218
+ typeof o.backgroundColor === "string" ? o.backgroundColor : void 0
219
+ ),
220
+ fontSize: typeof o.fontSize === "number" ? o.fontSize : void 0,
221
+ targetDashboardId: typeof o.targetDashboardId === "string" ? o.targetDashboardId : void 0,
222
+ drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0
223
+ });
224
+ }
225
+ return out;
226
+ }
227
+ function createContainerLabelItem(text = "Label") {
228
+ return {
229
+ id: cryptoRandomId(),
230
+ text
231
+ };
232
+ }
233
+ function hasContainerLabelCustomStyles(item) {
234
+ return Boolean(
235
+ sanitizeLabelStyleColor(item.color) || sanitizeLabelStyleBackground(item.backgroundColor) || typeof item.fontSize === "number"
236
+ );
237
+ }
238
+ function resetContainerLabelItemStyles(item) {
239
+ const next = { id: item.id, text: item.text };
240
+ if (item.targetDashboardId) next.targetDashboardId = item.targetDashboardId;
241
+ if (item.drillTitle) next.drillTitle = item.drillTitle;
242
+ return next;
243
+ }
244
+ function normalizeContainerLabelTemplate(raw) {
245
+ if (!raw || typeof raw !== "object") return {};
246
+ const o = raw;
247
+ return {
248
+ color: sanitizeLabelStyleColor(typeof o.color === "string" ? o.color : void 0),
249
+ backgroundColor: sanitizeLabelStyleBackground(
250
+ typeof o.backgroundColor === "string" ? o.backgroundColor : void 0
251
+ ),
252
+ fontSize: typeof o.fontSize === "number" ? o.fontSize : void 0,
253
+ targetDashboardId: typeof o.targetDashboardId === "string" ? o.targetDashboardId : void 0,
254
+ drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0
255
+ };
256
+ }
257
+ function hasContainerLabelTemplateCustomStyles(template) {
258
+ return Boolean(
259
+ sanitizeLabelStyleColor(template.color) || sanitizeLabelStyleBackground(template.backgroundColor) || typeof template.fontSize === "number"
260
+ );
261
+ }
262
+ function resetContainerLabelTemplateStyles(template) {
263
+ const next = {};
264
+ if (template.targetDashboardId) next.targetDashboardId = template.targetDashboardId;
265
+ if (template.drillTitle) next.drillTitle = template.drillTitle;
266
+ return next;
267
+ }
268
+ function resolveLabelContainerSource(chartOptions) {
269
+ return chartOptions.labelSource === "query" ? "query" : "static";
270
+ }
271
+ function resolveLabelColumnKey(field, columns) {
272
+ if (!columns.length) return field || "";
273
+ if (field && columns.includes(field)) return field;
274
+ if (field?.includes(".")) {
275
+ const bare = field.slice(field.lastIndexOf(".") + 1);
276
+ if (columns.includes(bare)) return bare;
277
+ }
278
+ if (field) {
279
+ const match = columns.find(
280
+ (c) => c === field || c.endsWith(`.${field}`) || field.endsWith(`.${c}`)
281
+ );
282
+ if (match) return match;
283
+ }
284
+ return columns[0] || field || "";
285
+ }
286
+ function buildContainerLabelsFromQuery(rows, columns, dimensionField, template) {
287
+ const dim = resolveLabelColumnKey(dimensionField, columns);
288
+ if (!dim) return [];
289
+ const seen = /* @__PURE__ */ new Set();
290
+ const labels = [];
291
+ for (const row of rows) {
292
+ const raw = row[dim];
293
+ if (raw == null || raw === "") continue;
294
+ const text = String(raw);
295
+ if (seen.has(text)) continue;
296
+ seen.add(text);
297
+ const drillTitle = template.drillTitle ? template.drillTitle.replace(/\{\{value\}\}/g, text) : text;
298
+ labels.push({
299
+ id: `query-${labels.length}-${text}`,
300
+ text,
301
+ color: template.color,
302
+ backgroundColor: template.backgroundColor,
303
+ fontSize: template.fontSize,
304
+ targetDashboardId: template.targetDashboardId,
305
+ drillTitle
306
+ });
307
+ }
308
+ return labels;
309
+ }
310
+ function labelWidgetShowsHeader(chartOptions) {
311
+ return chartOptions.showHeader !== false;
312
+ }
313
+ function resolveLabelClickAction(chartOptions, drillDown) {
314
+ const raw = chartOptions.clickAction;
315
+ if (raw === "url" || raw === "dashboard" || raw === "none") return raw;
316
+ if (drillDown?.targetDashboardId) return "dashboard";
317
+ return "none";
318
+ }
319
+ function getLabelClickUrl(chartOptions) {
320
+ const url = typeof chartOptions.clickUrl === "string" ? chartOptions.clickUrl.trim() : "";
321
+ return url || void 0;
322
+ }
323
+ function labelClickOpensNewTab(chartOptions) {
324
+ return chartOptions.clickUrlNewTab !== false;
325
+ }
326
+ function getKpiDefaultValue(chartOptions) {
327
+ const raw = chartOptions.defaultValue;
328
+ if (raw == null) return void 0;
329
+ if (typeof raw === "number" && Number.isFinite(raw)) return raw;
330
+ if (typeof raw === "string") {
331
+ const trimmed = raw.trim();
332
+ if (!trimmed) return void 0;
333
+ const n = Number(trimmed);
334
+ if (Number.isFinite(n)) return n;
335
+ return trimmed;
336
+ }
337
+ return void 0;
338
+ }
339
+ function createChartAxisGuideline(axis = "y", value = "") {
340
+ return {
341
+ id: cryptoRandomId(),
342
+ axis,
343
+ value
344
+ };
345
+ }
346
+ function normalizeChartAxisGuidelines(raw) {
347
+ if (!Array.isArray(raw)) return [];
348
+ const out = [];
349
+ for (const item of raw) {
350
+ if (!item || typeof item !== "object") continue;
351
+ const o = item;
352
+ const id = typeof o.id === "string" && o.id.trim() ? o.id : cryptoRandomId();
353
+ const axis = o.axis === "x" ? "x" : "y";
354
+ const value = typeof o.value === "number" && Number.isFinite(o.value) ? String(o.value) : typeof o.value === "string" ? o.value : "";
355
+ out.push({
356
+ id,
357
+ axis,
358
+ value,
359
+ label: typeof o.label === "string" ? o.label : void 0,
360
+ color: typeof o.color === "string" ? o.color : void 0
361
+ });
362
+ }
363
+ return out;
364
+ }
88
365
  function createEmptyDashboard(partial) {
89
366
  const id = partial?.id ?? cryptoRandomId();
90
367
  return {
@@ -97,6 +374,7 @@ function createEmptyDashboard(partial) {
97
374
  dir: partial?.dir,
98
375
  theme: partial?.theme,
99
376
  exportOptions: partial?.exportOptions,
377
+ displayOptions: partial?.displayOptions,
100
378
  layout: partial?.layout ?? [],
101
379
  globalFilters: partial?.globalFilters ?? [],
102
380
  widgets: partial?.widgets ?? [],
@@ -107,6 +385,52 @@ function createEmptyDashboard(partial) {
107
385
  }
108
386
  function createEmptyWidget(type = "bar") {
109
387
  const id = cryptoRandomId();
388
+ if (type === "label") {
389
+ return {
390
+ id,
391
+ type: "label",
392
+ title: "Label",
393
+ query: {
394
+ connectionId: "",
395
+ tables: [],
396
+ columns: [],
397
+ joins: [],
398
+ where: [],
399
+ limit: 0
400
+ },
401
+ binding: { dimensions: [], measures: [] },
402
+ chartOptions: {
403
+ text: "Your text here",
404
+ fontSize: 16
405
+ },
406
+ filters: []
407
+ };
408
+ }
409
+ if (type === "labelContainer") {
410
+ return {
411
+ id,
412
+ type: "labelContainer",
413
+ title: "Label container",
414
+ query: {
415
+ connectionId: "",
416
+ tables: [],
417
+ columns: [],
418
+ joins: [],
419
+ where: [],
420
+ limit: 0
421
+ },
422
+ binding: { dimensions: [], measures: [] },
423
+ chartOptions: {
424
+ layout: "vertical",
425
+ gap: 8,
426
+ padding: 12,
427
+ labelSource: "static",
428
+ labelTemplate: {},
429
+ labels: [createContainerLabelItem("First label"), createContainerLabelItem("Second label")]
430
+ },
431
+ filters: []
432
+ };
433
+ }
110
434
  return {
111
435
  id,
112
436
  type,
@@ -124,25 +448,65 @@ function createEmptyWidget(type = "bar") {
124
448
  filters: []
125
449
  };
126
450
  }
127
- function cryptoRandomId() {
128
- if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
129
- return crypto.randomUUID();
451
+ function createId() {
452
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
453
+ try {
454
+ return crypto.randomUUID();
455
+ } catch {
456
+ }
130
457
  }
131
- return `id_${Math.random().toString(36).slice(2, 11)}`;
458
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
459
+ const bytes = new Uint8Array(16);
460
+ crypto.getRandomValues(bytes);
461
+ bytes[6] = bytes[6] & 15 | 64;
462
+ bytes[8] = bytes[8] & 63 | 128;
463
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
464
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
465
+ }
466
+ return `id_${Math.random().toString(36).slice(2, 11)}${Date.now().toString(36)}`;
467
+ }
468
+ function cryptoRandomId() {
469
+ return createId();
132
470
  }
133
471
  export {
472
+ DASHBOARD_FILE_FORMAT,
473
+ DASHBOARD_FILE_VERSION,
134
474
  DB_PROVIDERS,
135
475
  DEFAULT_CHART_COLORS,
136
476
  DEFAULT_THEME_ACCENT,
477
+ LEGACY_LABEL_FOREGROUND,
137
478
  RTL_LOCALES,
138
479
  THEME_PRESETS,
139
480
  WIDGET_TYPES,
481
+ buildContainerLabelsFromQuery,
482
+ buildDashboardExportFile,
483
+ cloneDashboardForImport,
484
+ createChartAxisGuideline,
485
+ createContainerLabelItem,
140
486
  createEmptyDashboard,
141
487
  createEmptyWidget,
488
+ createId,
489
+ getKpiDefaultValue,
490
+ getLabelClickUrl,
491
+ hasContainerLabelCustomStyles,
492
+ hasContainerLabelTemplateCustomStyles,
142
493
  isDefaultDashboardTheme,
494
+ labelClickOpensNewTab,
495
+ labelWidgetShowsHeader,
143
496
  matchThemePreset,
497
+ normalizeChartAxisGuidelines,
498
+ normalizeContainerLabelTemplate,
499
+ normalizeContainerLabels,
500
+ parseDashboardImport,
501
+ resetContainerLabelItemStyles,
502
+ resetContainerLabelTemplateStyles,
144
503
  resolveDashboardDir,
145
504
  resolveDashboardTheme,
505
+ resolveDisplayOptions,
146
506
  resolveEmailOptions,
147
- resolveExportOptions
507
+ resolveExportOptions,
508
+ resolveLabelClickAction,
509
+ resolveLabelContainerSource,
510
+ sanitizeLabelStyleBackground,
511
+ sanitizeLabelStyleColor
148
512
  };
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
- {
2
- "name": "@dashboard-designer/core",
3
- "version": "0.1.1",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
12
- }
13
- },
14
- "files": ["dist"],
15
- "scripts": {
16
- "build": "tsup src/index.ts --format esm --dts --clean",
17
- "typecheck": "tsc --noEmit",
18
- "dev": "tsup src/index.ts --format esm --dts --watch"
19
- },
20
- "devDependencies": {
21
- "tsup": "^8.4.0",
22
- "typescript": "^5.8.2"
23
- }
24
- }
1
+ {
2
+ "name": "@dashboard-designer/core",
3
+ "version": "0.1.15",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "devDependencies": {
21
+ "tsup": "^8.4.0",
22
+ "typescript": "^5.8.2"
23
+ },
24
+ "scripts": {
25
+ "build": "tsup src/index.ts --format esm --dts --clean",
26
+ "typecheck": "tsc --noEmit",
27
+ "dev": "tsup src/index.ts --format esm --dts --watch"
28
+ }
29
+ }