@dashboard-designer/core 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.d.ts CHANGED
@@ -110,6 +110,12 @@ interface ContainerLabelItem {
110
110
  fontSize?: number;
111
111
  targetDashboardId?: string;
112
112
  drillTitle?: string;
113
+ /** Hyperlink template (see resolveHyperlink). Takes precedence over targetDashboardId. */
114
+ url?: string;
115
+ /** Open url in a new browser tab (default true). */
116
+ urlNewTab?: boolean;
117
+ /** Runtime only: query row the label was built from, for {{field:...}} link tokens. */
118
+ linkRow?: Record<string, unknown>;
113
119
  }
114
120
  /** Styles and drill target applied to every label generated from a query column. */
115
121
  interface ContainerLabelTemplate {
@@ -118,6 +124,9 @@ interface ContainerLabelTemplate {
118
124
  fontSize?: number;
119
125
  targetDashboardId?: string;
120
126
  drillTitle?: string;
127
+ /** Hyperlink template; {{value}} is the label text, {{field:Column}} reads the label's row. */
128
+ url?: string;
129
+ urlNewTab?: boolean;
121
130
  }
122
131
  type LabelContainerSource = 'static' | 'query';
123
132
  interface QueryLabelDrillDown {
@@ -367,6 +376,52 @@ declare function resolveLabelClickAction(chartOptions: Record<string, unknown>,
367
376
  declare function getLabelClickUrl(chartOptions: Record<string, unknown>): string | undefined;
368
377
  /** Whether a label URL click opens a new browser tab (default true). */
369
378
  declare function labelClickOpensNewTab(chartOptions: Record<string, unknown>): boolean;
379
+ /**
380
+ * Hyperlink on a chart, table, KPI or timeline widget, stored in chartOptions:
381
+ * `hyperlinkUrl`, `hyperlinkNewTab`, `hyperlinkColumn` (table only).
382
+ *
383
+ * The URL is a template. Tokens:
384
+ * - `{{var:Name}}` dashboard / host variable value (e.g. `{{var:url}}`)
385
+ * - `{{field:Col}}` column of the clicked row / point
386
+ * - `{{value}}` clicked category, cell or label text
387
+ *
388
+ * A token at the very start of the URL is inserted as-is, so a variable can hold the whole
389
+ * base address (`{{var:url}}/record/{{field:Id}}`). Tokens anywhere else are URL-encoded.
390
+ */
391
+ interface WidgetHyperlink {
392
+ url: string;
393
+ newTab: boolean;
394
+ /** Table only: render this column's cells as links. Empty = whole row is clickable. */
395
+ column?: string;
396
+ }
397
+ interface HyperlinkContext {
398
+ variables?: Record<string, VariableValue>;
399
+ row?: Record<string, unknown>;
400
+ value?: unknown;
401
+ }
402
+ type HyperlinkResult = {
403
+ ok: true;
404
+ url: string;
405
+ } | {
406
+ ok: false;
407
+ error: string;
408
+ };
409
+ declare function getWidgetHyperlink(chartOptions: Record<string, unknown>): WidgetHyperlink | undefined;
410
+ /** Read a row value by exact key, then by bare column name (`table.col` vs `col`). */
411
+ declare function readRowField(row: Record<string, unknown> | undefined, field: string): unknown;
412
+ /** Variable names referenced by a link template (`{{var:Name}}`). */
413
+ declare function hyperlinkVariableNames(template: string): string[];
414
+ /**
415
+ * True for http(s), mailto, tel and relative links (`/path`, `#/route`, `?q=1`, `page.html`).
416
+ * Blocks `javascript:`, `data:`, `vbscript:` and other schemes.
417
+ */
418
+ declare function isSafeHyperlink(url: string): boolean;
419
+ /** Resolve a link template against variables and the clicked row. Never throws. */
420
+ declare function resolveHyperlink(template: string | undefined, context?: HyperlinkContext): HyperlinkResult;
421
+ /** Replace `{{var:Name}}` tokens in display text; unknown variables are left visible. */
422
+ declare function resolveDisplayText(text: string, variables?: Record<string, VariableValue>): string;
423
+ /** Open a resolved link the same way for every widget. */
424
+ declare function openHyperlink(url: string, newTab: boolean): void;
370
425
  /** Parsed KPI default when query returns no rows or an empty value. */
371
426
  declare function getKpiDefaultValue(chartOptions: Record<string, unknown>): unknown | undefined;
372
427
  declare function createChartAxisGuideline(axis?: ChartGuidelineAxis, value?: string): ChartAxisGuideline;
@@ -401,4 +456,4 @@ interface DashboardPrintSettings {
401
456
  }
402
457
  declare function resolvePrintHeader(title: string, settings?: DashboardPrintSettings, runtime?: DashboardPrintHeader, user?: string): DashboardPrintHeader;
403
458
 
404
- 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 DashboardPrintHeader, type DashboardPrintSettings, type DashboardTheme, type DashboardVariable, 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 ProcedureParameter, type ProcedureWhereClause, type QueryColumn, type QueryDef, type QueryLabelDrillDown, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, type VariableValue, WIDGET_TYPES, type Widget, type WidgetType, buildContainerLabelsFromQuery, buildDashboardExportFile, buildProcedureWhereClause, cloneDashboardForImport, connectionVariableNames, createChartAxisGuideline, createContainerLabelItem, createEmptyDashboard, createEmptyWidget, createId, getKpiDefaultValue, getLabelClickUrl, hasContainerLabelCustomStyles, hasContainerLabelTemplateCustomStyles, isDefaultDashboardTheme, labelClickOpensNewTab, labelWidgetShowsHeader, matchThemePreset, normalizeChartAxisGuidelines, normalizeContainerLabelTemplate, normalizeContainerLabels, normalizeQueryLabelDrillDowns, parseDashboardImport, parseStoredProcedureName, portableDashboard, resetContainerLabelItemStyles, resetContainerLabelTemplateStyles, resolveDashboardDir, resolveDashboardTheme, resolveDashboardVariables, resolveDisplayOptions, resolveEmailOptions, resolveExportOptions, resolveFilterVariables, resolveLabelClickAction, resolveLabelContainerSource, resolvePrintHeader, resolveProcedureParameterValue, resolveRequestVariables, resolveVariableValue, sanitizeLabelStyleBackground, sanitizeLabelStyleColor };
459
+ 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 DashboardPrintHeader, type DashboardPrintSettings, type DashboardTheme, type DashboardVariable, type DashboardVersion, type DashboardVersionMeta, type DataBinding, type DbProvider, type DrillDownDef, type EmbedTokenRequest, type EmbedTokenResponse, type ExecuteQueryRequest, type FilterDef, type FilterOperator, type GridItem, type HyperlinkContext, type HyperlinkResult, type JoinDef, type JoinType, LEGACY_LABEL_FOREGROUND, type LabelClickAction, type LabelContainerSource, type ProcedureParameter, type ProcedureWhereClause, type QueryColumn, type QueryDef, type QueryLabelDrillDown, type QueryResult, RTL_LOCALES, THEME_PRESETS, type User, type UserRole, type VariableValue, WIDGET_TYPES, type Widget, type WidgetHyperlink, type WidgetType, buildContainerLabelsFromQuery, buildDashboardExportFile, buildProcedureWhereClause, cloneDashboardForImport, connectionVariableNames, createChartAxisGuideline, createContainerLabelItem, createEmptyDashboard, createEmptyWidget, createId, getKpiDefaultValue, getLabelClickUrl, getWidgetHyperlink, hasContainerLabelCustomStyles, hasContainerLabelTemplateCustomStyles, hyperlinkVariableNames, isDefaultDashboardTheme, isSafeHyperlink, labelClickOpensNewTab, labelWidgetShowsHeader, matchThemePreset, normalizeChartAxisGuidelines, normalizeContainerLabelTemplate, normalizeContainerLabels, normalizeQueryLabelDrillDowns, openHyperlink, parseDashboardImport, parseStoredProcedureName, portableDashboard, readRowField, resetContainerLabelItemStyles, resetContainerLabelTemplateStyles, resolveDashboardDir, resolveDashboardTheme, resolveDashboardVariables, resolveDisplayOptions, resolveDisplayText, resolveEmailOptions, resolveExportOptions, resolveFilterVariables, resolveHyperlink, resolveLabelClickAction, resolveLabelContainerSource, resolvePrintHeader, resolveProcedureParameterValue, resolveRequestVariables, resolveVariableValue, sanitizeLabelStyleBackground, sanitizeLabelStyleColor };
package/dist/index.js CHANGED
@@ -357,7 +357,9 @@ function normalizeContainerLabels(raw) {
357
357
  ),
358
358
  fontSize: typeof o.fontSize === "number" ? o.fontSize : void 0,
359
359
  targetDashboardId: typeof o.targetDashboardId === "string" ? o.targetDashboardId : void 0,
360
- drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0
360
+ drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0,
361
+ url: typeof o.url === "string" && o.url.trim() ? o.url : void 0,
362
+ urlNewTab: o.urlNewTab === false ? false : void 0
361
363
  });
362
364
  }
363
365
  return out;
@@ -377,6 +379,8 @@ function resetContainerLabelItemStyles(item) {
377
379
  const next = { id: item.id, text: item.text };
378
380
  if (item.targetDashboardId) next.targetDashboardId = item.targetDashboardId;
379
381
  if (item.drillTitle) next.drillTitle = item.drillTitle;
382
+ if (item.url) next.url = item.url;
383
+ if (item.urlNewTab === false) next.urlNewTab = false;
380
384
  return next;
381
385
  }
382
386
  function normalizeContainerLabelTemplate(raw) {
@@ -389,7 +393,9 @@ function normalizeContainerLabelTemplate(raw) {
389
393
  ),
390
394
  fontSize: typeof o.fontSize === "number" ? o.fontSize : void 0,
391
395
  targetDashboardId: typeof o.targetDashboardId === "string" ? o.targetDashboardId : void 0,
392
- drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0
396
+ drillTitle: typeof o.drillTitle === "string" ? o.drillTitle : void 0,
397
+ url: typeof o.url === "string" && o.url.trim() ? o.url : void 0,
398
+ urlNewTab: o.urlNewTab === false ? false : void 0
393
399
  };
394
400
  }
395
401
  function hasContainerLabelTemplateCustomStyles(template) {
@@ -401,6 +407,8 @@ function resetContainerLabelTemplateStyles(template) {
401
407
  const next = {};
402
408
  if (template.targetDashboardId) next.targetDashboardId = template.targetDashboardId;
403
409
  if (template.drillTitle) next.drillTitle = template.drillTitle;
410
+ if (template.url) next.url = template.url;
411
+ if (template.urlNewTab === false) next.urlNewTab = false;
404
412
  return next;
405
413
  }
406
414
  function resolveLabelContainerSource(chartOptions) {
@@ -443,7 +451,11 @@ function buildContainerLabelsFromQuery(rows, columns, dimensionField, template,
443
451
  backgroundColor: template.backgroundColor,
444
452
  fontSize: template.fontSize,
445
453
  targetDashboardId,
446
- drillTitle
454
+ drillTitle,
455
+ // A per-value rule (open dashboard / no action) overrides the shared link.
456
+ url: override ? void 0 : template.url,
457
+ urlNewTab: template.urlNewTab,
458
+ linkRow: row
447
459
  });
448
460
  }
449
461
  return labels;
@@ -464,6 +476,86 @@ function getLabelClickUrl(chartOptions) {
464
476
  function labelClickOpensNewTab(chartOptions) {
465
477
  return chartOptions.clickUrlNewTab !== false;
466
478
  }
479
+ var HYPERLINK_TOKEN = /\{\{\s*(?:(var|field)\s*:\s*([^}]+?)|(value))\s*\}\}/g;
480
+ var SAFE_LINK_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
481
+ function getWidgetHyperlink(chartOptions) {
482
+ const url = typeof chartOptions.hyperlinkUrl === "string" ? chartOptions.hyperlinkUrl.trim() : "";
483
+ if (!url) return void 0;
484
+ const column = typeof chartOptions.hyperlinkColumn === "string" && chartOptions.hyperlinkColumn.trim() ? chartOptions.hyperlinkColumn.trim() : void 0;
485
+ return { url, newTab: chartOptions.hyperlinkNewTab !== false, column };
486
+ }
487
+ function readRowField(row, field) {
488
+ if (!row) return void 0;
489
+ if (Object.prototype.hasOwnProperty.call(row, field)) return row[field];
490
+ const bare = field.includes(".") ? field.slice(field.lastIndexOf(".") + 1) : field;
491
+ if (Object.prototype.hasOwnProperty.call(row, bare)) return row[bare];
492
+ const lower = bare.toLowerCase();
493
+ const key = Object.keys(row).find((k) => {
494
+ const kb = k.includes(".") ? k.slice(k.lastIndexOf(".") + 1) : k;
495
+ return kb.toLowerCase() === lower;
496
+ });
497
+ return key === void 0 ? void 0 : row[key];
498
+ }
499
+ function hyperlinkVariableNames(template) {
500
+ const names = /* @__PURE__ */ new Set();
501
+ for (const m of template.matchAll(HYPERLINK_TOKEN)) if (m[1] === "var") names.add(m[2].trim());
502
+ return [...names];
503
+ }
504
+ function isSafeHyperlink(url) {
505
+ const compact = url.replace(/[\u0000-\u0020\u007f]+/g, "");
506
+ if (!compact) return false;
507
+ if (compact.startsWith("//")) return true;
508
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(compact)?.[1];
509
+ if (!scheme) return !/^[a-z][a-z0-9+.-]*%3a/i.test(compact);
510
+ return SAFE_LINK_SCHEMES.has(scheme.toLowerCase());
511
+ }
512
+ function hyperlinkValueText(value) {
513
+ if (value == null) return "";
514
+ if (value instanceof Date) return value.toISOString();
515
+ if (typeof value === "object") return JSON.stringify(value);
516
+ return String(value);
517
+ }
518
+ function resolveHyperlink(template, context = {}) {
519
+ const source = (template ?? "").trim();
520
+ if (!source) return { ok: false, error: "No link URL is configured." };
521
+ const variables = context.variables ?? {};
522
+ let error;
523
+ const url = source.replace(HYPERLINK_TOKEN, (token, kind, rawName, isValue, offset) => {
524
+ let raw;
525
+ if (isValue) {
526
+ raw = context.value;
527
+ } else if (kind === "var") {
528
+ const name = rawName.trim();
529
+ if (!Object.prototype.hasOwnProperty.call(variables, name) || variables[name] === void 0) {
530
+ error ??= `Link variable "${name}" has no value.`;
531
+ return "";
532
+ }
533
+ raw = variables[name];
534
+ } else {
535
+ const name = rawName.trim();
536
+ raw = readRowField(context.row, name);
537
+ if (raw === void 0 && context.row) {
538
+ error ??= `Link field "${name}" is not in the query result.`;
539
+ return "";
540
+ }
541
+ }
542
+ const text = hyperlinkValueText(raw);
543
+ return offset === 0 ? text.trim() : encodeURIComponent(text);
544
+ }).trim();
545
+ if (error) return { ok: false, error };
546
+ if (!url) return { ok: false, error: "The link URL resolved to an empty value." };
547
+ if (!isSafeHyperlink(url)) return { ok: false, error: "This link uses a blocked URL scheme." };
548
+ return { ok: true, url };
549
+ }
550
+ function resolveDisplayText(text, variables = {}) {
551
+ if (!text.includes("{{")) return text;
552
+ return text.replace(/\{\{\s*var\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g, (token, name) => Object.prototype.hasOwnProperty.call(variables, name) && variables[name] !== void 0 ? hyperlinkValueText(variables[name]) : token);
553
+ }
554
+ function openHyperlink(url, newTab) {
555
+ if (typeof window === "undefined") return;
556
+ if (newTab) window.open(url, "_blank", "noopener,noreferrer");
557
+ else window.location.assign(url);
558
+ }
467
559
  function getKpiDefaultValue(chartOptions) {
468
560
  const raw = chartOptions.defaultValue;
469
561
  if (raw == null) return void 0;
@@ -657,9 +749,12 @@ export {
657
749
  createId,
658
750
  getKpiDefaultValue,
659
751
  getLabelClickUrl,
752
+ getWidgetHyperlink,
660
753
  hasContainerLabelCustomStyles,
661
754
  hasContainerLabelTemplateCustomStyles,
755
+ hyperlinkVariableNames,
662
756
  isDefaultDashboardTheme,
757
+ isSafeHyperlink,
663
758
  labelClickOpensNewTab,
664
759
  labelWidgetShowsHeader,
665
760
  matchThemePreset,
@@ -667,18 +762,22 @@ export {
667
762
  normalizeContainerLabelTemplate,
668
763
  normalizeContainerLabels,
669
764
  normalizeQueryLabelDrillDowns,
765
+ openHyperlink,
670
766
  parseDashboardImport,
671
767
  parseStoredProcedureName,
672
768
  portableDashboard,
769
+ readRowField,
673
770
  resetContainerLabelItemStyles,
674
771
  resetContainerLabelTemplateStyles,
675
772
  resolveDashboardDir,
676
773
  resolveDashboardTheme,
677
774
  resolveDashboardVariables,
678
775
  resolveDisplayOptions,
776
+ resolveDisplayText,
679
777
  resolveEmailOptions,
680
778
  resolveExportOptions,
681
779
  resolveFilterVariables,
780
+ resolveHyperlink,
682
781
  resolveLabelClickAction,
683
782
  resolveLabelContainerSource,
684
783
  resolvePrintHeader,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashboard-designer/core",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",