@richardmcquiston01/dashboard-widgets-toolkit 0.1.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/LICENSE +202 -0
- package/README.md +324 -0
- package/dist/core.cjs +836 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +93 -0
- package/dist/core.d.ts +93 -0
- package/dist/core.js +778 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +836 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +778 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +1273 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +203 -0
- package/dist/react.d.ts +203 -0
- package/dist/react.js +1248 -0
- package/dist/react.js.map +1 -0
- package/dist/scale-WlRozDCf.d.cts +416 -0
- package/dist/scale-WlRozDCf.d.ts +416 -0
- package/dist/styles.css +550 -0
- package/package.json +121 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget data payloads, one shape per kind, discriminated by `kind`.
|
|
3
|
+
*
|
|
4
|
+
* The kind names are upper case to stay compatible with Maker Toolkit's
|
|
5
|
+
* `WidgetViewType` (`TEXT`, `GAUGE`, `TABLE`, `GRAPH`). `KPI`, `BAR_LIST`
|
|
6
|
+
* and `ALERT_LIST` are new. Every payload is plain JSON: strings, finite
|
|
7
|
+
* numbers, booleans, null, arrays and objects. No dates (send ISO strings),
|
|
8
|
+
* no functions, no class instances.
|
|
9
|
+
*/
|
|
10
|
+
/** Every widget kind, in a stable order. */
|
|
11
|
+
declare const WIDGET_KINDS: readonly ["TEXT", "KPI", "GAUGE", "TABLE", "BAR_LIST", "ALERT_LIST", "GRAPH"];
|
|
12
|
+
type WidgetKind = (typeof WIDGET_KINDS)[number];
|
|
13
|
+
declare function isWidgetKind(value: unknown): value is WidgetKind;
|
|
14
|
+
/** How a number is shown: a plain count, money, or a fraction as a percent. */
|
|
15
|
+
declare const VALUE_FORMATS: readonly ["number", "currency", "percent"];
|
|
16
|
+
type ValueFormat = (typeof VALUE_FORMATS)[number];
|
|
17
|
+
/** A single headline value as text, e.g. "12" or "Open". */
|
|
18
|
+
interface TextWidgetData {
|
|
19
|
+
readonly kind: 'TEXT';
|
|
20
|
+
readonly value: string;
|
|
21
|
+
readonly label: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A stat tile: one number, optionally compared with the previous period.
|
|
25
|
+
*
|
|
26
|
+
* `value` and `previous` are in major units for `currency` (12.5 is $12.50)
|
|
27
|
+
* and fractions for `percent` (0.25 is 25%).
|
|
28
|
+
*/
|
|
29
|
+
interface KpiWidgetData {
|
|
30
|
+
readonly kind: 'KPI';
|
|
31
|
+
readonly value: number;
|
|
32
|
+
/** The same measure for the previous period; null or absent for none. */
|
|
33
|
+
readonly previous?: number | null;
|
|
34
|
+
readonly format: ValueFormat;
|
|
35
|
+
/** ISO 4217 code for `currency`, e.g. "USD". Defaults to USD. */
|
|
36
|
+
readonly currency?: string;
|
|
37
|
+
readonly label: string;
|
|
38
|
+
/** Short context under the value, e.g. "Incl. shipping and tax". */
|
|
39
|
+
readonly hint?: string;
|
|
40
|
+
/** Whether a rise is good news (default true). Colours the change. */
|
|
41
|
+
readonly higherIsBetter?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** A value against a maximum, drawn as a meter. */
|
|
44
|
+
interface GaugeWidgetData {
|
|
45
|
+
readonly kind: 'GAUGE';
|
|
46
|
+
readonly value: number;
|
|
47
|
+
readonly max: number;
|
|
48
|
+
readonly label: string;
|
|
49
|
+
}
|
|
50
|
+
interface TableColumn {
|
|
51
|
+
readonly label: string;
|
|
52
|
+
/** Right-aligned, tabular figures. */
|
|
53
|
+
readonly numeric?: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface TableCell {
|
|
56
|
+
readonly text: string;
|
|
57
|
+
/** Renders the cell as a link (http, https, mailto or relative only). */
|
|
58
|
+
readonly href?: string;
|
|
59
|
+
}
|
|
60
|
+
interface TableWidgetData {
|
|
61
|
+
readonly kind: 'TABLE';
|
|
62
|
+
readonly columns: readonly TableColumn[];
|
|
63
|
+
/** One array of cells per row, each as long as `columns`. */
|
|
64
|
+
readonly rows: readonly (readonly TableCell[])[];
|
|
65
|
+
/** A note under the table, e.g. "and 12 more". */
|
|
66
|
+
readonly footer?: string;
|
|
67
|
+
}
|
|
68
|
+
interface BarListItem {
|
|
69
|
+
readonly label: string;
|
|
70
|
+
readonly value: number;
|
|
71
|
+
/** Text shown beside the bar; defaults to the formatted value. */
|
|
72
|
+
readonly display?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Labelled horizontal bars, e.g. ratings or purchases by country. Bars are a
|
|
76
|
+
* share of `total` when it is given, otherwise of the largest value.
|
|
77
|
+
*/
|
|
78
|
+
interface BarListWidgetData {
|
|
79
|
+
readonly kind: 'BAR_LIST';
|
|
80
|
+
readonly items: readonly BarListItem[];
|
|
81
|
+
readonly total?: number;
|
|
82
|
+
}
|
|
83
|
+
interface AlertListItem {
|
|
84
|
+
readonly title: string;
|
|
85
|
+
/** Renders the title as a link (http, https, mailto or relative only). */
|
|
86
|
+
readonly href?: string;
|
|
87
|
+
/** A small square image (http, https or relative only). */
|
|
88
|
+
readonly thumbnailUrl?: string;
|
|
89
|
+
/** The short figure on the right, e.g. "2 left" or "31 views". */
|
|
90
|
+
readonly valueLabel: string;
|
|
91
|
+
/** A secondary line under the title. */
|
|
92
|
+
readonly detail?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Things that need attention (low stock, stale listings...). `items` may be
|
|
96
|
+
* the first few of `total`; the renderer says "and N more".
|
|
97
|
+
*/
|
|
98
|
+
interface AlertListWidgetData {
|
|
99
|
+
readonly kind: 'ALERT_LIST';
|
|
100
|
+
readonly items: readonly AlertListItem[];
|
|
101
|
+
readonly total: number;
|
|
102
|
+
/** Shown when there is nothing to flag, e.g. "Nothing low on stock." */
|
|
103
|
+
readonly emptyText: string;
|
|
104
|
+
}
|
|
105
|
+
interface GraphPoint {
|
|
106
|
+
/** The category or date label on the x axis, e.g. "Oct 2026". */
|
|
107
|
+
readonly label: string;
|
|
108
|
+
readonly value: number;
|
|
109
|
+
}
|
|
110
|
+
interface GraphSeries {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly points: readonly GraphPoint[];
|
|
113
|
+
}
|
|
114
|
+
/** The most series a graph may carry: the categorical palette's eight slots. */
|
|
115
|
+
declare const MAX_GRAPH_SERIES = 8;
|
|
116
|
+
/**
|
|
117
|
+
* A bar (grouped for several series) or line chart. All series share the
|
|
118
|
+
* x labels of the first series, by position, and one y axis.
|
|
119
|
+
*/
|
|
120
|
+
interface GraphWidgetData {
|
|
121
|
+
readonly kind: 'GRAPH';
|
|
122
|
+
readonly series: readonly GraphSeries[];
|
|
123
|
+
readonly chartType: 'bar' | 'line';
|
|
124
|
+
readonly valueFormat: ValueFormat;
|
|
125
|
+
/** ISO 4217 code for `currency`. Defaults to USD. */
|
|
126
|
+
readonly currency?: string;
|
|
127
|
+
/** Heading for the label column in the table view, e.g. "Month". */
|
|
128
|
+
readonly xLabel?: string;
|
|
129
|
+
}
|
|
130
|
+
/** Any widget's data, discriminated by `kind`. */
|
|
131
|
+
type WidgetData = TextWidgetData | KpiWidgetData | GaugeWidgetData | TableWidgetData | BarListWidgetData | AlertListWidgetData | GraphWidgetData;
|
|
132
|
+
/** The payload type for one kind, e.g. `WidgetDataOf<'KPI'>`. */
|
|
133
|
+
type WidgetDataOf<K extends WidgetKind> = Extract<WidgetData, {
|
|
134
|
+
kind: K;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* A widget with nothing to show yet, with the reason as text ("No orders
|
|
138
|
+
* synced yet."). Any widget may return this instead of its kind's payload.
|
|
139
|
+
*/
|
|
140
|
+
interface WidgetEmptyState {
|
|
141
|
+
readonly empty: true;
|
|
142
|
+
readonly text: string;
|
|
143
|
+
}
|
|
144
|
+
/** What a provider or API returns for a widget: its data, or an empty state. */
|
|
145
|
+
type WidgetPayload = WidgetData | WidgetEmptyState;
|
|
146
|
+
/** The default text for an empty widget. */
|
|
147
|
+
declare const DEFAULT_EMPTY_TEXT = "Nothing to show yet.";
|
|
148
|
+
/** Builds an empty state. */
|
|
149
|
+
declare function emptyWidget(text?: string): WidgetEmptyState;
|
|
150
|
+
declare function isWidgetEmptyState(payload: WidgetPayload): payload is WidgetEmptyState;
|
|
151
|
+
/**
|
|
152
|
+
* The empty text for a payload with nothing in it (a table with no rows, a
|
|
153
|
+
* list with no items, a graph with no points), or null when it has content.
|
|
154
|
+
* TEXT, KPI and GAUGE always have content.
|
|
155
|
+
*/
|
|
156
|
+
declare function emptyTextFor(payload: WidgetPayload): string | null;
|
|
157
|
+
|
|
158
|
+
/** A size hint for grid layouts; renderers may map it to column spans. */
|
|
159
|
+
declare const WIDGET_SIZES: readonly ["small", "medium", "large", "full"];
|
|
160
|
+
type WidgetSize = (typeof WIDGET_SIZES)[number];
|
|
161
|
+
/**
|
|
162
|
+
* What a widget is, independent of its data. Mirrors Maker Toolkit's
|
|
163
|
+
* `widget` table (`widget_key`, `title`, `description`, `view_type`,
|
|
164
|
+
* `roles`, `sort_order`, `active`).
|
|
165
|
+
*/
|
|
166
|
+
interface WidgetDefinition {
|
|
167
|
+
/** Stable, unique id. Layouts and providers are keyed by it. */
|
|
168
|
+
readonly key: string;
|
|
169
|
+
readonly title: string;
|
|
170
|
+
readonly description?: string;
|
|
171
|
+
readonly kind: WidgetKind;
|
|
172
|
+
/** Lower comes first. Default 0; ties keep definition order. */
|
|
173
|
+
readonly sortOrder?: number;
|
|
174
|
+
/** Roles allowed to see it. Absent or empty means everyone. */
|
|
175
|
+
readonly roles?: readonly string[];
|
|
176
|
+
/** False hides it from every user. Default true. */
|
|
177
|
+
readonly active?: boolean;
|
|
178
|
+
readonly defaultSize?: WidgetSize;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Identity helper that keeps the literal `kind` (so typed providers can be
|
|
182
|
+
* checked against it) and gives a definition its type without a cast.
|
|
183
|
+
*/
|
|
184
|
+
declare function defineWidget<const D extends WidgetDefinition>(definition: D): D;
|
|
185
|
+
/** Definitions sorted by `sortOrder` (stable: ties keep their input order). */
|
|
186
|
+
declare function sortDefinitions<D extends WidgetDefinition>(definitions: readonly D[]): D[];
|
|
187
|
+
/** Whether a widget is active and visible to someone with these roles. */
|
|
188
|
+
declare function isWidgetVisibleTo(definition: WidgetDefinition, roles: readonly string[] | undefined): boolean;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Number formatting via `Intl`, with an injectable locale (undefined uses
|
|
192
|
+
* the runtime's default), plus KPI period-over-period deltas.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
type Locale = string | readonly string[] | undefined;
|
|
196
|
+
interface FormatOptions {
|
|
197
|
+
readonly locale?: Locale;
|
|
198
|
+
/** ISO 4217 code for `currency`. Default "USD". */
|
|
199
|
+
readonly currency?: string;
|
|
200
|
+
/** "1.2K" style, for axis ticks. */
|
|
201
|
+
readonly compact?: boolean;
|
|
202
|
+
}
|
|
203
|
+
declare const DEFAULT_CURRENCY = "USD";
|
|
204
|
+
/**
|
|
205
|
+
* Formats `value` as a count ("1,284"), money ("$12.50", major units) or a
|
|
206
|
+
* percent ("25%" from 0.25).
|
|
207
|
+
*/
|
|
208
|
+
declare function formatValue(value: number, format: ValueFormat, options?: FormatOptions): string;
|
|
209
|
+
/** A plain count, e.g. "1,284". */
|
|
210
|
+
declare function formatCount(value: number, locale?: Locale): string;
|
|
211
|
+
/** `part` as a whole percentage of `total` (0 when total is 0 or less). */
|
|
212
|
+
declare function shareOf(part: number, total: number): number;
|
|
213
|
+
/**
|
|
214
|
+
* Change from `previous` to `current` in percent (unrounded), or null when
|
|
215
|
+
* there is nothing to compare: no previous value, or a previous of 0.
|
|
216
|
+
*/
|
|
217
|
+
declare function percentChange(current: number, previous: number | null | undefined): number | null;
|
|
218
|
+
/**
|
|
219
|
+
* "+12%", "-8%", "±0%". Below 10% one decimal is kept ("+2.5%"), so small
|
|
220
|
+
* changes don't round away.
|
|
221
|
+
*/
|
|
222
|
+
declare function formatPercentChange(change: number, locale?: Locale): string;
|
|
223
|
+
type DeltaDirection = 'up' | 'down' | 'flat';
|
|
224
|
+
type DeltaSentiment = 'good' | 'bad' | 'neutral';
|
|
225
|
+
interface KpiDelta {
|
|
226
|
+
/** Percent change, unrounded. */
|
|
227
|
+
readonly percent: number;
|
|
228
|
+
readonly direction: DeltaDirection;
|
|
229
|
+
/** Direction combined with whether higher is better. */
|
|
230
|
+
readonly sentiment: DeltaSentiment;
|
|
231
|
+
/** "+12%" */
|
|
232
|
+
readonly text: string;
|
|
233
|
+
/** "+12% vs previous period" */
|
|
234
|
+
readonly description: string;
|
|
235
|
+
}
|
|
236
|
+
interface KpiDeltaOptions {
|
|
237
|
+
/** Default true. */
|
|
238
|
+
readonly higherIsBetter?: boolean;
|
|
239
|
+
readonly locale?: Locale;
|
|
240
|
+
/** What the change is against. Default "previous period". */
|
|
241
|
+
readonly comparisonLabel?: string;
|
|
242
|
+
}
|
|
243
|
+
/** The default comparison wording in delta descriptions. */
|
|
244
|
+
declare const DEFAULT_COMPARISON_LABEL = "previous period";
|
|
245
|
+
/**
|
|
246
|
+
* The period-over-period change for a KPI, or null when it can't be worked
|
|
247
|
+
* out (no previous value, or a previous of 0).
|
|
248
|
+
*/
|
|
249
|
+
declare function kpiDelta(current: number, previous: number | null | undefined, options?: KpiDeltaOptions): KpiDelta | null;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* A viewer's dashboard customisation: order, hidden and minimised widgets.
|
|
253
|
+
* Pure functions over a small JSON-serialisable object. Persist it however
|
|
254
|
+
* you like (a settings table, localStorage); `parseLayout` tolerates
|
|
255
|
+
* anything, so a corrupt saved value never breaks the dashboard.
|
|
256
|
+
*
|
|
257
|
+
* Generalised from Maker Toolkit's desktop `dashboard-layout.ts`.
|
|
258
|
+
*/
|
|
259
|
+
/** What layout functions need from a widget definition. */
|
|
260
|
+
interface LayoutItem {
|
|
261
|
+
readonly key: string;
|
|
262
|
+
readonly sortOrder?: number;
|
|
263
|
+
}
|
|
264
|
+
interface DashboardLayout {
|
|
265
|
+
/** Widget keys in display order. Keys not listed follow, by sortOrder. */
|
|
266
|
+
readonly order: readonly string[];
|
|
267
|
+
/** Widget keys removed from the dashboard (restorable). */
|
|
268
|
+
readonly hidden: readonly string[];
|
|
269
|
+
/** Widget keys collapsed to their header. */
|
|
270
|
+
readonly minimized: readonly string[];
|
|
271
|
+
}
|
|
272
|
+
declare const EMPTY_LAYOUT: DashboardLayout;
|
|
273
|
+
/**
|
|
274
|
+
* Reads a saved layout: a JSON string or an already-parsed object. Missing,
|
|
275
|
+
* corrupt or wrongly typed values give the empty layout (or empty lists for
|
|
276
|
+
* the fields that are wrong); non-string and duplicate keys are dropped.
|
|
277
|
+
*/
|
|
278
|
+
declare function parseLayout(raw: unknown): DashboardLayout;
|
|
279
|
+
/** The JSON string to persist. */
|
|
280
|
+
declare function serializeLayout(layout: DashboardLayout): string;
|
|
281
|
+
/**
|
|
282
|
+
* The widgets to show, in order: saved keys first (when still present),
|
|
283
|
+
* then widgets the layout doesn't know yet, by sortOrder. Hidden widgets
|
|
284
|
+
* are left out.
|
|
285
|
+
*/
|
|
286
|
+
declare function visibleWidgets<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout): T[];
|
|
287
|
+
/** Hidden widgets, by sortOrder, for a "restore" menu. */
|
|
288
|
+
declare function hiddenWidgets<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout): T[];
|
|
289
|
+
/**
|
|
290
|
+
* Moves `key` to `toIndex` within the current visible order. Returns the
|
|
291
|
+
* same layout object when the key isn't visible or the index is out of
|
|
292
|
+
* range, so callers can skip a save.
|
|
293
|
+
*/
|
|
294
|
+
declare function moveWidget<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout, key: string, toIndex: number): DashboardLayout;
|
|
295
|
+
/** Moves `key` by `offset` places (negative is earlier). Clamped at the ends. */
|
|
296
|
+
declare function moveWidgetBy<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout, key: string, offset: number): DashboardLayout;
|
|
297
|
+
/** Moves `key` one place earlier. */
|
|
298
|
+
declare function moveWidgetUp<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout, key: string): DashboardLayout;
|
|
299
|
+
/** Moves `key` one place later. */
|
|
300
|
+
declare function moveWidgetDown<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout, key: string): DashboardLayout;
|
|
301
|
+
declare function isHidden(layout: DashboardLayout, key: string): boolean;
|
|
302
|
+
declare function isMinimized(layout: DashboardLayout, key: string): boolean;
|
|
303
|
+
/** Hides `key`. No-op (same object) if already hidden. */
|
|
304
|
+
declare function hideWidget(layout: DashboardLayout, key: string): DashboardLayout;
|
|
305
|
+
/** Shows `key` again, expanded. No-op (same object) if not hidden. */
|
|
306
|
+
declare function showWidget(layout: DashboardLayout, key: string): DashboardLayout;
|
|
307
|
+
/** Hides or shows `key` (showing also clears its minimised state). */
|
|
308
|
+
declare function toggleHidden(layout: DashboardLayout, key: string): DashboardLayout;
|
|
309
|
+
/** Collapses `key` to its header. No-op (same object) if already minimised. */
|
|
310
|
+
declare function minimizeWidget(layout: DashboardLayout, key: string): DashboardLayout;
|
|
311
|
+
/** Expands `key`. No-op (same object) if not minimised. */
|
|
312
|
+
declare function restoreWidget(layout: DashboardLayout, key: string): DashboardLayout;
|
|
313
|
+
/** Minimises or restores `key`. */
|
|
314
|
+
declare function toggleMinimized(layout: DashboardLayout, key: string): DashboardLayout;
|
|
315
|
+
/**
|
|
316
|
+
* Drops keys for widgets that no longer exist. Only pass the full list of
|
|
317
|
+
* definitions (not a role-filtered one), or a viewer's settings for widgets
|
|
318
|
+
* they temporarily can't see are lost.
|
|
319
|
+
*/
|
|
320
|
+
declare function pruneLayout<T extends LayoutItem>(definitions: readonly T[], layout: DashboardLayout): DashboardLayout;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Runs each widget's data provider and collects the outcome per widget, so
|
|
324
|
+
* one failing provider never breaks the rest of the dashboard. The package
|
|
325
|
+
* never fetches anything itself: providers are the consumer's functions
|
|
326
|
+
* (a Prisma query, an HTTP call, a computed value).
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
/** The minimum a resolve context carries; add whatever your providers need. */
|
|
330
|
+
interface WidgetContext {
|
|
331
|
+
/** The viewer's roles. Widgets with `roles` need at least one of them. */
|
|
332
|
+
readonly roles?: readonly string[];
|
|
333
|
+
}
|
|
334
|
+
/** Loads one widget's payload. May be sync or async; may throw. */
|
|
335
|
+
type WidgetProvider<C = WidgetContext> = (context: C, definition: WidgetDefinition) => WidgetPayload | Promise<WidgetPayload>;
|
|
336
|
+
/** Providers keyed by widget key. */
|
|
337
|
+
type WidgetProviders<C = WidgetContext> = Readonly<Record<string, WidgetProvider<C>>>;
|
|
338
|
+
interface OkWidget {
|
|
339
|
+
readonly definition: WidgetDefinition;
|
|
340
|
+
readonly status: 'ok';
|
|
341
|
+
readonly data: WidgetData;
|
|
342
|
+
}
|
|
343
|
+
interface EmptyWidget {
|
|
344
|
+
readonly definition: WidgetDefinition;
|
|
345
|
+
readonly status: 'empty';
|
|
346
|
+
/** Why there is nothing to show, e.g. "No orders synced yet." */
|
|
347
|
+
readonly emptyText: string;
|
|
348
|
+
}
|
|
349
|
+
interface ErrorWidget {
|
|
350
|
+
readonly definition: WidgetDefinition;
|
|
351
|
+
readonly status: 'error';
|
|
352
|
+
/** Names the widget and what failed. */
|
|
353
|
+
readonly error: string;
|
|
354
|
+
}
|
|
355
|
+
/** One widget after its provider ran. */
|
|
356
|
+
type ResolvedWidget = OkWidget | EmptyWidget | ErrorWidget;
|
|
357
|
+
/** A widget whose data hasn't arrived yet (for client-side loading states). */
|
|
358
|
+
interface LoadingWidget {
|
|
359
|
+
readonly definition: WidgetDefinition;
|
|
360
|
+
readonly status: 'loading';
|
|
361
|
+
}
|
|
362
|
+
/** Anything a dashboard can render: resolved, or still loading. */
|
|
363
|
+
type DashboardWidget = ResolvedWidget | LoadingWidget;
|
|
364
|
+
type WidgetStatus = DashboardWidget['status'];
|
|
365
|
+
interface ResolveOptions {
|
|
366
|
+
/**
|
|
367
|
+
* Validate each provider's payload with `validateWidgetData` (and check
|
|
368
|
+
* its kind matches the definition). Default true; turn off only for
|
|
369
|
+
* trusted, typed providers.
|
|
370
|
+
*/
|
|
371
|
+
readonly validate?: boolean;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Turns a payload (typically JSON from an API) into a resolved widget:
|
|
375
|
+
* validated against the definition's kind, and marked empty when it has
|
|
376
|
+
* nothing to show.
|
|
377
|
+
*/
|
|
378
|
+
declare function resolvePayload(definition: WidgetDefinition, payload: unknown, options?: ResolveOptions): ResolvedWidget;
|
|
379
|
+
/** A widget that failed, with the reason. */
|
|
380
|
+
declare function failedWidget(definition: WidgetDefinition, error: string): ErrorWidget;
|
|
381
|
+
/** Loading placeholders for definitions, before their data arrives. */
|
|
382
|
+
declare function loadingWidgets(definitions: readonly WidgetDefinition[]): LoadingWidget[];
|
|
383
|
+
/** Runs one widget's provider, capturing a throw or bad payload as an error. */
|
|
384
|
+
declare function resolveWidget<C extends WidgetContext>(definition: WidgetDefinition, provider: WidgetProvider<C> | undefined, context: C, options?: ResolveOptions): Promise<ResolvedWidget>;
|
|
385
|
+
/**
|
|
386
|
+
* The widgets a viewer can see: active, allowed for `roles`, in sort order.
|
|
387
|
+
*/
|
|
388
|
+
declare function widgetsFor(definitions: readonly WidgetDefinition[], roles: readonly string[] | undefined): WidgetDefinition[];
|
|
389
|
+
/**
|
|
390
|
+
* Resolves every widget the context's roles may see, in parallel. Inactive
|
|
391
|
+
* and role-filtered widgets are skipped (and their providers never run).
|
|
392
|
+
* Results come back in sort order; a provider that throws, is missing or
|
|
393
|
+
* returns a bad payload yields an `error` widget and never rejects.
|
|
394
|
+
*/
|
|
395
|
+
declare function resolveWidgets<C extends WidgetContext>(definitions: readonly WidgetDefinition[], providers: WidgetProviders<C>, context: C, options?: ResolveOptions): Promise<ResolvedWidget[]>;
|
|
396
|
+
|
|
397
|
+
/** Axis maths for charts: clean domains and tick values. Pure. */
|
|
398
|
+
/** The smallest 1, 2 or 5 × 10^n that is at least `value` (1 for 0 or less). */
|
|
399
|
+
declare function niceStep(value: number): number;
|
|
400
|
+
interface NiceDomain {
|
|
401
|
+
readonly min: number;
|
|
402
|
+
readonly max: number;
|
|
403
|
+
/** From min to max inclusive, evenly spaced on a clean step. */
|
|
404
|
+
readonly ticks: readonly number[];
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* A y-axis domain that always includes 0 (bars grow from a single
|
|
408
|
+
* baseline), rounded out to a clean step, with about `tickCount` intervals.
|
|
409
|
+
*/
|
|
410
|
+
declare function niceDomain(values: readonly number[], tickCount?: number): NiceDomain;
|
|
411
|
+
/**
|
|
412
|
+
* Show every `n`th x label so at most `maxLabels` appear (always at least 1).
|
|
413
|
+
*/
|
|
414
|
+
declare function labelStride(count: number, maxLabels?: number): number;
|
|
415
|
+
|
|
416
|
+
export { formatCount as $, type AlertListWidgetData as A, type BarListWidgetData as B, WIDGET_KINDS as C, type DashboardWidget as D, EMPTY_LAYOUT as E, type FormatOptions as F, type GraphWidgetData as G, WIDGET_SIZES as H, type WidgetContext as I, type WidgetDataOf as J, type KpiWidgetData as K, type Locale as L, MAX_GRAPH_SERIES as M, type NiceDomain as N, type OkWidget as O, type WidgetEmptyState as P, type WidgetProvider as Q, type ResolveOptions as R, type WidgetProviders as S, type TableWidgetData as T, type WidgetStatus as U, VALUE_FORMATS as V, type WidgetSize as W, defineWidget as X, emptyTextFor as Y, emptyWidget as Z, failedWidget as _, type DashboardLayout as a, formatPercentChange as a0, formatValue as a1, hiddenWidgets as a2, hideWidget as a3, isHidden as a4, isMinimized as a5, isWidgetEmptyState as a6, isWidgetKind as a7, isWidgetVisibleTo as a8, kpiDelta as a9, labelStride as aa, loadingWidgets as ab, minimizeWidget as ac, moveWidget as ad, moveWidgetBy as ae, moveWidgetDown as af, moveWidgetUp as ag, niceDomain as ah, niceStep as ai, parseLayout as aj, percentChange as ak, pruneLayout as al, resolvePayload as am, resolveWidget as an, resolveWidgets as ao, restoreWidget as ap, serializeLayout as aq, shareOf as ar, showWidget as as, sortDefinitions as at, toggleHidden as au, toggleMinimized as av, visibleWidgets as aw, widgetsFor as ax, type GaugeWidgetData as b, type TextWidgetData as c, type WidgetData as d, type WidgetDefinition as e, type WidgetKind as f, type WidgetPayload as g, type AlertListItem as h, type BarListItem as i, DEFAULT_COMPARISON_LABEL as j, DEFAULT_CURRENCY as k, DEFAULT_EMPTY_TEXT as l, type DeltaDirection as m, type DeltaSentiment as n, type EmptyWidget as o, type ErrorWidget as p, type GraphPoint as q, type GraphSeries as r, type KpiDelta as s, type KpiDeltaOptions as t, type LayoutItem as u, type LoadingWidget as v, type ResolvedWidget as w, type TableCell as x, type TableColumn as y, type ValueFormat as z };
|