@lightdash/query-sdk 1.12.0 → 1.14.0

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/features.js CHANGED
@@ -59,6 +59,12 @@ export const SDK_FEATURES = [
59
59
  label: 'Dashboard visualization context',
60
60
  description: 'Receive query context when app visualizations are embedded in dashboards.',
61
61
  },
62
+ {
63
+ key: 'viz-config-options',
64
+ label: 'Visualization config options',
65
+ description: "Let viewers adjust the visualization from the Lightdash config panel — toggles, dropdowns, numbers, text and colours — and take series colours from the chart's palette, without regenerating the app.",
66
+ wiring: 'Declare configOptions (and colorPalette, if the viz colours series) in the viz schema, then read options[name] and colorPalette from useVizContext().',
67
+ },
62
68
  ];
63
69
  export const SDK_FEATURE_KEYS = SDK_FEATURES.map((f) => f.key);
64
70
  export const SDK_MANIFEST_MESSAGE_TYPE = 'lightdash:sdk:manifest';
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.12.0";
1
+ export declare const SDK_VERSION = "1.14.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generateSdkVersion.mjs (prebuild) — do not edit.
2
- export const SDK_VERSION = '1.12.0';
2
+ export const SDK_VERSION = '1.14.0';
@@ -26,13 +26,16 @@ export type VizContextRow = Record<string, VizContextCell | undefined>;
26
26
  /**
27
27
  * A config option value. Its shape follows the option's declared type:
28
28
  * `boolean` → boolean, `number` → number, `select`/`text`/`color` → string.
29
+ * Series colours are not an option — they arrive on `colorPalette`.
29
30
  */
30
31
  export type VizContextOptionValue = boolean | number | string;
31
32
  /**
32
33
  * Pushed by the host into the iframe. `fieldMapping` maps each field name the
33
34
  * renderer declared to the query field id it resolves to; `rows` are the
34
35
  * host-fetched result rows keyed by field id; `options` holds the current
35
- * value of each config option the renderer declared.
36
+ * value of each config option the renderer declared; `colorPalette` is the
37
+ * Lightdash palette resolved for this chart, pushed whether or not the
38
+ * renderer declared one.
36
39
  */
37
40
  export type DataAppVizContextMessage = {
38
41
  type: 'lightdash:sdk:data-app-viz-context';
@@ -40,6 +43,8 @@ export type DataAppVizContextMessage = {
40
43
  rows: VizContextRow[];
41
44
  /** Absent when the installed host predates config-option delivery. */
42
45
  options?: Record<string, VizContextOptionValue>;
46
+ /** Absent when the installed host predates palette delivery. */
47
+ colorPalette?: string[];
43
48
  };
44
49
  /** Posted by the iframe on mount so the host pushes the current context. */
45
50
  export type VizContextRequestMessage = {
@@ -56,6 +61,13 @@ export type VizContext = {
56
61
  rows: VizContextRow[];
57
62
  /** Config option name → current value (the user's choice, else the declared default). */
58
63
  options: Record<string, VizContextOptionValue>;
64
+ /**
65
+ * Ordered series colours resolved from the Lightdash palette the viewer
66
+ * picked. Colour multi-series charts with
67
+ * `colorPalette[i % colorPalette.length]`. Empty only when the host
68
+ * resolved no palette; keep a fallback array in your own code for that.
69
+ */
70
+ colorPalette: string[];
59
71
  /** False until the first context arrives — render a placeholder while false. */
60
72
  ready: boolean;
61
73
  };
@@ -63,12 +75,14 @@ type VizContextValue = {
63
75
  fieldMapping: Record<string, string>;
64
76
  rows: VizContextRow[];
65
77
  options: Record<string, VizContextOptionValue>;
78
+ colorPalette: string[];
66
79
  };
67
80
  type VizContextState = VizContextValue | null;
68
81
  /**
69
82
  * Normalises an inbound host message into provider state. The payload crosses a
70
- * postMessage boundary so every key is treated as untrusted; `options` is also
71
- * absent from hosts predating it, and falls back to `{}`.
83
+ * postMessage boundary so every key is treated as untrusted; `options` and
84
+ * `colorPalette` are also absent from hosts predating them, and fall back to
85
+ * `{}` / `[]`.
72
86
  */
73
87
  export declare function toVizContextState(message: DataAppVizContextMessage): VizContextValue;
74
88
  declare const NO_PROVIDER: unique symbol;
@@ -86,7 +100,7 @@ export declare function VizContextProvider({ children }: {
86
100
  * still works standalone. Re-renders whenever the host pushes (on load, on
87
101
  * mapping change, on query change). Resolve a declared field to its bound cell
88
102
  * with `fieldMapping[name]` then `getFormatted`/`getRaw`; read a declared
89
- * config option with `options[name]`.
103
+ * config option with `options[name]`, and colour series from `colorPalette`.
90
104
  */
91
105
  export declare function useVizContext(): VizContext;
92
106
  export {};
@@ -41,14 +41,18 @@ const normalizeOptions = (options) => {
41
41
  };
42
42
  /**
43
43
  * Normalises an inbound host message into provider state. The payload crosses a
44
- * postMessage boundary so every key is treated as untrusted; `options` is also
45
- * absent from hosts predating it, and falls back to `{}`.
44
+ * postMessage boundary so every key is treated as untrusted; `options` and
45
+ * `colorPalette` are also absent from hosts predating them, and fall back to
46
+ * `{}` / `[]`.
46
47
  */
47
48
  export function toVizContextState(message) {
48
49
  return {
49
50
  fieldMapping: message.fieldMapping ?? {},
50
51
  rows: Array.isArray(message.rows) ? message.rows : [],
51
52
  options: normalizeOptions(message.options),
53
+ colorPalette: Array.isArray(message.colorPalette)
54
+ ? message.colorPalette.filter((color) => typeof color === 'string')
55
+ : [],
52
56
  };
53
57
  }
54
58
  // Distinguishes "no provider mounted" from "provider present, no context yet".
@@ -98,7 +102,7 @@ export function VizContextProvider({ children }) {
98
102
  * still works standalone. Re-renders whenever the host pushes (on load, on
99
103
  * mapping change, on query change). Resolve a declared field to its bound cell
100
104
  * with `fieldMapping[name]` then `getFormatted`/`getRaw`; read a declared
101
- * config option with `options[name]`.
105
+ * config option with `options[name]`, and colour series from `colorPalette`.
102
106
  */
103
107
  export function useVizContext() {
104
108
  const fromProvider = useContext(VizContextContext);
@@ -113,6 +117,7 @@ export function useVizContext() {
113
117
  fieldMapping: context?.fieldMapping ?? {},
114
118
  rows: context?.rows ?? [],
115
119
  options: context?.options ?? {},
120
+ colorPalette: context?.colorPalette ?? [],
116
121
  ready: context !== null,
117
122
  };
118
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/query-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SDK for building custom data apps against the Lightdash semantic layer",
@@ -35,7 +35,7 @@
35
35
  "typescript": "npm:@typescript/typescript6@6.0.1",
36
36
  "typescript-7": "npm:typescript@7.0.1-rc",
37
37
  "vitest": "4.1.6",
38
- "@lightdash/common": "1.12.0"
38
+ "@lightdash/common": "1.14.0"
39
39
  },
40
40
  "scripts": {
41
41
  "prebuild": "node ./scripts/generateSdkVersion.mjs",