@richardmcquiston01/dashboard-widgets-toolkit 0.2.0 → 0.4.1
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/README.md +90 -8
- package/dist/core.cjs +642 -69
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +61 -18
- package/dist/core.d.ts +61 -18
- package/dist/core.js +623 -70
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +642 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +623 -70
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +1516 -86
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +155 -14
- package/dist/react.d.ts +155 -14
- package/dist/react.js +1514 -88
- package/dist/react.js.map +1 -1
- package/dist/{scale-Bhjc5Eqt.d.cts → scale-dWDGE1zW.d.cts} +327 -118
- package/dist/{scale-Bhjc5Eqt.d.ts → scale-dWDGE1zW.d.ts} +327 -118
- package/dist/styles.css +154 -6
- package/package.json +1 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as WidgetDefinition, W as WidgetSize, a as WidgetFill, D as DashboardWidget, j as WidgetContext, R as ResolveOptions, k as WidgetProviders, l as WidgetKind, m as Result, n as WidgetPayload } from './scale-dWDGE1zW.cjs';
|
|
2
|
+
export { o as AlertListItem, A as AlertListWidgetData, p as BarListItem, B as BarListWidgetData, C as CachedPayload, q as DEFAULT_COMPARISON_LABEL, r as DEFAULT_CURRENCY, s as DEFAULT_DETAIL_PAGE_SIZE, t as DEFAULT_EMPTY_TEXT, u as DETAIL_MODES, f as DashboardLayout, v as DeltaDirection, w as DeltaSentiment, x as DetailCell, y as DetailColumn, d as DetailData, z as DetailMode, E as DetailPage, F as DetailProvider, c as DetailProviderOptions, H as DetailProviders, e as DetailQuery, I as DetailSort, J as EMPTY_LAYOUT, M as EmptyWidget, O as Err, P as ErrorWidget, Q as FormatOptions, g as GaugeWidgetData, S as GraphPoint, U as GraphSeries, G as GraphWidgetData, V as KpiDelta, X as KpiDeltaOptions, K as KpiWidgetData, Y as LayoutItem, Z as LoadingWidget, L as Locale, _ as MAX_DETAIL_PAGE_SIZE, $ as MAX_GRAPH_SERIES, N as NiceDomain, a0 as Ok, a1 as OkWidget, a2 as ProviderOptions, a3 as ResolvedDetailOptions, a4 as ResolvedWidget, a5 as SortDirection, a6 as TableCell, a7 as TableColumn, T as TableWidgetData, h as TextWidgetData, a8 as VALUE_FORMATS, a9 as ValueFormat, aa as WIDGET_FILLS, ab as WIDGET_KINDS, ac as WIDGET_SIZES, ad as WidgetCache, i as WidgetData, ae as WidgetDataOf, af as WidgetDetailOptions, ag as WidgetEmptyState, ah as WidgetProvider, ai as WidgetStatus, aj as cacheKeyFor, ak as defaultDetailQuery, al as defineWidget, am as deriveDetailData, an as describeUnknownError, ao as emptyTextFor, ap as emptyWidget, aq as err, ar as failedWidget, as as formatCount, at as formatPercentChange, au as formatValue, av as hiddenWidgets, aw as hideWidget, ax as isHidden, ay as isMinimized, az as isWidgetEmptyState, aA as isWidgetKind, aB as isWidgetVisibleTo, aC as kpiDelta, aD as labelStride, aE as loadingWidgets, aF as minimizeWidget, aG as moveWidget, aH as moveWidgetBy, aI as moveWidgetDown, aJ as moveWidgetUp, aK as niceDomain, aL as niceStep, aM as ok, aN as parseDetailQuery, aO as parseLayout, aP as percentChange, aQ as pruneLayout, aR as queryRows, aS as resolveDetailOptions, aT as resolvePayload, aU as resolveWidget, aV as resolveWidgets, aW as restoreWidget, aX as serializeDetailQuery, aY as serializeLayout, aZ as shareOf, a_ as showWidget, a$ as sortDefinitions, b0 as toggleHidden, b1 as toggleMinimized, b2 as validateDetailData, b3 as visibleWidgets, b4 as widgetsFor } from './scale-dWDGE1zW.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Maker Toolkit compatibility. Its API (`apps/api/src/widgets`) serves
|
|
@@ -38,7 +38,21 @@ interface GridItem {
|
|
|
38
38
|
readonly key: string;
|
|
39
39
|
readonly defaultSize?: WidgetSize;
|
|
40
40
|
readonly fill?: WidgetFill;
|
|
41
|
+
readonly width?: number;
|
|
41
42
|
}
|
|
43
|
+
/** Columns in a grid that uses widget `width`. */
|
|
44
|
+
declare const WIDTH_COLUMNS = 12;
|
|
45
|
+
/** Smallest and largest `width`, in twelfths of a row. */
|
|
46
|
+
declare const MIN_WIDGET_WIDTH = 2;
|
|
47
|
+
declare const MAX_WIDGET_WIDTH = 12;
|
|
48
|
+
/** Whether `value` is a valid widget `width`: an integer from 2 to 12. */
|
|
49
|
+
declare function isWidgetWidth(value: unknown): value is number;
|
|
50
|
+
/** The width (in twelfths) a `defaultSize` stands for. Default `medium`. */
|
|
51
|
+
declare function widthForSize(size: WidgetSize | undefined): number;
|
|
52
|
+
/** The 12-column width of an item: its `width`, else from its size. */
|
|
53
|
+
declare function itemWidth(item: GridItem): number;
|
|
54
|
+
/** Whether a grid of `items` should use 12 columns (any item sets `width`). */
|
|
55
|
+
declare function usesWidthColumns(items: readonly GridItem[]): boolean;
|
|
42
56
|
/** Whether the widget should take the columns left over in its row. */
|
|
43
57
|
declare function fillsWidth(fill: WidgetFill | undefined): boolean;
|
|
44
58
|
/** Whether the widget should stretch to the height of its row. */
|
|
@@ -58,26 +72,55 @@ declare function baseColumnSpan(size: WidgetSize | undefined, columns: number, l
|
|
|
58
72
|
* that do not fill width keep their normal size and are not in the map.
|
|
59
73
|
*/
|
|
60
74
|
declare function fillColumnSpans(items: readonly GridItem[], columns: number, largeSpan?: number): Map<string, number>;
|
|
75
|
+
/**
|
|
76
|
+
* Like `fillColumnSpans` for a 12-column grid: each item starts at its
|
|
77
|
+
* `width` (see `itemWidth`) and width-fillers share the leftover twelfths.
|
|
78
|
+
*/
|
|
79
|
+
declare function fillWidthSpans(items: readonly GridItem[]): Map<string, number>;
|
|
61
80
|
|
|
62
81
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
82
|
+
* Loads widgets one by one, after the first render, and reports each result
|
|
83
|
+
* as it arrives. It is the logic behind the React `useWidgets` hook, kept
|
|
84
|
+
* framework-agnostic and runtime-neutral so it can be tested without a DOM
|
|
85
|
+
* and reused by other renderers. Like the rest of the core it never fetches
|
|
86
|
+
* anything itself: providers do the work.
|
|
87
|
+
*
|
|
88
|
+
* Lifecycle: `createWidgetLoader` (nothing runs yet; every widget is
|
|
89
|
+
* `loading`) then `load(key)` / `loadAll()` when you want data (immediately
|
|
90
|
+
* after mount, or when a card scrolls into view), `refresh()` to reload, and
|
|
91
|
+
* `dispose()` to cancel everything.
|
|
66
92
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly
|
|
93
|
+
|
|
94
|
+
interface WidgetLoaderOptions<C extends WidgetContext> extends ResolveOptions {
|
|
95
|
+
readonly definitions: readonly WidgetDefinition[];
|
|
96
|
+
readonly providers: WidgetProviders<C>;
|
|
97
|
+
readonly context: C;
|
|
98
|
+
}
|
|
99
|
+
interface RefreshOptions {
|
|
100
|
+
/** Leave widgets that are still loading alone instead of restarting them. */
|
|
101
|
+
readonly skipInFlight?: boolean;
|
|
70
102
|
}
|
|
71
|
-
interface
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
interface WidgetLoader {
|
|
104
|
+
/** The current widgets in display order. A new array after every change. */
|
|
105
|
+
getSnapshot(): readonly DashboardWidget[];
|
|
106
|
+
/** Calls `listener` after every change. Returns an unsubscribe function. */
|
|
107
|
+
subscribe(listener: () => void): () => void;
|
|
108
|
+
/** Starts loading one widget. Does nothing if it already started. */
|
|
109
|
+
load(key: string): void;
|
|
110
|
+
/** Starts loading every widget that has not started yet. */
|
|
111
|
+
loadAll(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Reloads started widgets (or just `key`). The previous call is aborted and
|
|
114
|
+
* its result ignored. Visible data stays until the new data arrives; an
|
|
115
|
+
* `error` widget goes back to `loading`. With `skipInFlight`, widgets that
|
|
116
|
+
* are still loading are left alone (what polling wants: a provider slower
|
|
117
|
+
* than the interval would otherwise be restarted forever and never finish).
|
|
118
|
+
*/
|
|
119
|
+
refresh(key?: string, options?: RefreshOptions): void;
|
|
120
|
+
/** Aborts everything in flight and ignores any later result. */
|
|
121
|
+
dispose(): void;
|
|
75
122
|
}
|
|
76
|
-
|
|
77
|
-
declare function ok<T>(value: T): Ok<T>;
|
|
78
|
-
declare function err(error: string): Err;
|
|
79
|
-
/** Turns an unknown thrown value into a readable message. */
|
|
80
|
-
declare function describeUnknownError(cause: unknown): string;
|
|
123
|
+
declare function createWidgetLoader<C extends WidgetContext>(options: WidgetLoaderOptions<C>): WidgetLoader;
|
|
81
124
|
|
|
82
125
|
/**
|
|
83
126
|
* Link and image URL checks. Payloads often come from an API, so a link is
|
|
@@ -116,4 +159,4 @@ declare function validateWidgetData(value: unknown, options?: ValidateWidgetData
|
|
|
116
159
|
*/
|
|
117
160
|
declare function validateWidgetDefinition(value: unknown): Result<WidgetDefinition>;
|
|
118
161
|
|
|
119
|
-
export {
|
|
162
|
+
export { DashboardWidget, type GridItem, type LegacyWidgetDefinition, MAX_REPORTED_PROBLEMS, MAX_WIDGET_WIDTH, MIN_WIDGET_WIDTH, type RefreshOptions, ResolveOptions, Result, type ValidateWidgetDataOptions, WIDTH_COLUMNS, WidgetContext, WidgetDefinition, WidgetFill, WidgetKind, type WidgetLoader, type WidgetLoaderOptions, WidgetPayload, WidgetProviders, WidgetSize, baseColumnSpan, createWidgetLoader, fillColumnSpans, fillWidthSpans, fillsHeight, fillsWidth, fromLegacyDefinition, isSafeHref, isSafeImageUrl, isWidgetWidth, itemWidth, upgradeLegacyWidgetData, usesWidthColumns, validateWidgetData, validateWidgetDefinition, widthForSize };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as WidgetDefinition, W as WidgetSize, a as WidgetFill, D as DashboardWidget, j as WidgetContext, R as ResolveOptions, k as WidgetProviders, l as WidgetKind, m as Result, n as WidgetPayload } from './scale-dWDGE1zW.js';
|
|
2
|
+
export { o as AlertListItem, A as AlertListWidgetData, p as BarListItem, B as BarListWidgetData, C as CachedPayload, q as DEFAULT_COMPARISON_LABEL, r as DEFAULT_CURRENCY, s as DEFAULT_DETAIL_PAGE_SIZE, t as DEFAULT_EMPTY_TEXT, u as DETAIL_MODES, f as DashboardLayout, v as DeltaDirection, w as DeltaSentiment, x as DetailCell, y as DetailColumn, d as DetailData, z as DetailMode, E as DetailPage, F as DetailProvider, c as DetailProviderOptions, H as DetailProviders, e as DetailQuery, I as DetailSort, J as EMPTY_LAYOUT, M as EmptyWidget, O as Err, P as ErrorWidget, Q as FormatOptions, g as GaugeWidgetData, S as GraphPoint, U as GraphSeries, G as GraphWidgetData, V as KpiDelta, X as KpiDeltaOptions, K as KpiWidgetData, Y as LayoutItem, Z as LoadingWidget, L as Locale, _ as MAX_DETAIL_PAGE_SIZE, $ as MAX_GRAPH_SERIES, N as NiceDomain, a0 as Ok, a1 as OkWidget, a2 as ProviderOptions, a3 as ResolvedDetailOptions, a4 as ResolvedWidget, a5 as SortDirection, a6 as TableCell, a7 as TableColumn, T as TableWidgetData, h as TextWidgetData, a8 as VALUE_FORMATS, a9 as ValueFormat, aa as WIDGET_FILLS, ab as WIDGET_KINDS, ac as WIDGET_SIZES, ad as WidgetCache, i as WidgetData, ae as WidgetDataOf, af as WidgetDetailOptions, ag as WidgetEmptyState, ah as WidgetProvider, ai as WidgetStatus, aj as cacheKeyFor, ak as defaultDetailQuery, al as defineWidget, am as deriveDetailData, an as describeUnknownError, ao as emptyTextFor, ap as emptyWidget, aq as err, ar as failedWidget, as as formatCount, at as formatPercentChange, au as formatValue, av as hiddenWidgets, aw as hideWidget, ax as isHidden, ay as isMinimized, az as isWidgetEmptyState, aA as isWidgetKind, aB as isWidgetVisibleTo, aC as kpiDelta, aD as labelStride, aE as loadingWidgets, aF as minimizeWidget, aG as moveWidget, aH as moveWidgetBy, aI as moveWidgetDown, aJ as moveWidgetUp, aK as niceDomain, aL as niceStep, aM as ok, aN as parseDetailQuery, aO as parseLayout, aP as percentChange, aQ as pruneLayout, aR as queryRows, aS as resolveDetailOptions, aT as resolvePayload, aU as resolveWidget, aV as resolveWidgets, aW as restoreWidget, aX as serializeDetailQuery, aY as serializeLayout, aZ as shareOf, a_ as showWidget, a$ as sortDefinitions, b0 as toggleHidden, b1 as toggleMinimized, b2 as validateDetailData, b3 as visibleWidgets, b4 as widgetsFor } from './scale-dWDGE1zW.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Maker Toolkit compatibility. Its API (`apps/api/src/widgets`) serves
|
|
@@ -38,7 +38,21 @@ interface GridItem {
|
|
|
38
38
|
readonly key: string;
|
|
39
39
|
readonly defaultSize?: WidgetSize;
|
|
40
40
|
readonly fill?: WidgetFill;
|
|
41
|
+
readonly width?: number;
|
|
41
42
|
}
|
|
43
|
+
/** Columns in a grid that uses widget `width`. */
|
|
44
|
+
declare const WIDTH_COLUMNS = 12;
|
|
45
|
+
/** Smallest and largest `width`, in twelfths of a row. */
|
|
46
|
+
declare const MIN_WIDGET_WIDTH = 2;
|
|
47
|
+
declare const MAX_WIDGET_WIDTH = 12;
|
|
48
|
+
/** Whether `value` is a valid widget `width`: an integer from 2 to 12. */
|
|
49
|
+
declare function isWidgetWidth(value: unknown): value is number;
|
|
50
|
+
/** The width (in twelfths) a `defaultSize` stands for. Default `medium`. */
|
|
51
|
+
declare function widthForSize(size: WidgetSize | undefined): number;
|
|
52
|
+
/** The 12-column width of an item: its `width`, else from its size. */
|
|
53
|
+
declare function itemWidth(item: GridItem): number;
|
|
54
|
+
/** Whether a grid of `items` should use 12 columns (any item sets `width`). */
|
|
55
|
+
declare function usesWidthColumns(items: readonly GridItem[]): boolean;
|
|
42
56
|
/** Whether the widget should take the columns left over in its row. */
|
|
43
57
|
declare function fillsWidth(fill: WidgetFill | undefined): boolean;
|
|
44
58
|
/** Whether the widget should stretch to the height of its row. */
|
|
@@ -58,26 +72,55 @@ declare function baseColumnSpan(size: WidgetSize | undefined, columns: number, l
|
|
|
58
72
|
* that do not fill width keep their normal size and are not in the map.
|
|
59
73
|
*/
|
|
60
74
|
declare function fillColumnSpans(items: readonly GridItem[], columns: number, largeSpan?: number): Map<string, number>;
|
|
75
|
+
/**
|
|
76
|
+
* Like `fillColumnSpans` for a 12-column grid: each item starts at its
|
|
77
|
+
* `width` (see `itemWidth`) and width-fillers share the leftover twelfths.
|
|
78
|
+
*/
|
|
79
|
+
declare function fillWidthSpans(items: readonly GridItem[]): Map<string, number>;
|
|
61
80
|
|
|
62
81
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
82
|
+
* Loads widgets one by one, after the first render, and reports each result
|
|
83
|
+
* as it arrives. It is the logic behind the React `useWidgets` hook, kept
|
|
84
|
+
* framework-agnostic and runtime-neutral so it can be tested without a DOM
|
|
85
|
+
* and reused by other renderers. Like the rest of the core it never fetches
|
|
86
|
+
* anything itself: providers do the work.
|
|
87
|
+
*
|
|
88
|
+
* Lifecycle: `createWidgetLoader` (nothing runs yet; every widget is
|
|
89
|
+
* `loading`) then `load(key)` / `loadAll()` when you want data (immediately
|
|
90
|
+
* after mount, or when a card scrolls into view), `refresh()` to reload, and
|
|
91
|
+
* `dispose()` to cancel everything.
|
|
66
92
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly
|
|
93
|
+
|
|
94
|
+
interface WidgetLoaderOptions<C extends WidgetContext> extends ResolveOptions {
|
|
95
|
+
readonly definitions: readonly WidgetDefinition[];
|
|
96
|
+
readonly providers: WidgetProviders<C>;
|
|
97
|
+
readonly context: C;
|
|
98
|
+
}
|
|
99
|
+
interface RefreshOptions {
|
|
100
|
+
/** Leave widgets that are still loading alone instead of restarting them. */
|
|
101
|
+
readonly skipInFlight?: boolean;
|
|
70
102
|
}
|
|
71
|
-
interface
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
interface WidgetLoader {
|
|
104
|
+
/** The current widgets in display order. A new array after every change. */
|
|
105
|
+
getSnapshot(): readonly DashboardWidget[];
|
|
106
|
+
/** Calls `listener` after every change. Returns an unsubscribe function. */
|
|
107
|
+
subscribe(listener: () => void): () => void;
|
|
108
|
+
/** Starts loading one widget. Does nothing if it already started. */
|
|
109
|
+
load(key: string): void;
|
|
110
|
+
/** Starts loading every widget that has not started yet. */
|
|
111
|
+
loadAll(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Reloads started widgets (or just `key`). The previous call is aborted and
|
|
114
|
+
* its result ignored. Visible data stays until the new data arrives; an
|
|
115
|
+
* `error` widget goes back to `loading`. With `skipInFlight`, widgets that
|
|
116
|
+
* are still loading are left alone (what polling wants: a provider slower
|
|
117
|
+
* than the interval would otherwise be restarted forever and never finish).
|
|
118
|
+
*/
|
|
119
|
+
refresh(key?: string, options?: RefreshOptions): void;
|
|
120
|
+
/** Aborts everything in flight and ignores any later result. */
|
|
121
|
+
dispose(): void;
|
|
75
122
|
}
|
|
76
|
-
|
|
77
|
-
declare function ok<T>(value: T): Ok<T>;
|
|
78
|
-
declare function err(error: string): Err;
|
|
79
|
-
/** Turns an unknown thrown value into a readable message. */
|
|
80
|
-
declare function describeUnknownError(cause: unknown): string;
|
|
123
|
+
declare function createWidgetLoader<C extends WidgetContext>(options: WidgetLoaderOptions<C>): WidgetLoader;
|
|
81
124
|
|
|
82
125
|
/**
|
|
83
126
|
* Link and image URL checks. Payloads often come from an API, so a link is
|
|
@@ -116,4 +159,4 @@ declare function validateWidgetData(value: unknown, options?: ValidateWidgetData
|
|
|
116
159
|
*/
|
|
117
160
|
declare function validateWidgetDefinition(value: unknown): Result<WidgetDefinition>;
|
|
118
161
|
|
|
119
|
-
export {
|
|
162
|
+
export { DashboardWidget, type GridItem, type LegacyWidgetDefinition, MAX_REPORTED_PROBLEMS, MAX_WIDGET_WIDTH, MIN_WIDGET_WIDTH, type RefreshOptions, ResolveOptions, Result, type ValidateWidgetDataOptions, WIDTH_COLUMNS, WidgetContext, WidgetDefinition, WidgetFill, WidgetKind, type WidgetLoader, type WidgetLoaderOptions, WidgetPayload, WidgetProviders, WidgetSize, baseColumnSpan, createWidgetLoader, fillColumnSpans, fillWidthSpans, fillsHeight, fillsWidth, fromLegacyDefinition, isSafeHref, isSafeImageUrl, isWidgetWidth, itemWidth, upgradeLegacyWidgetData, usesWidthColumns, validateWidgetData, validateWidgetDefinition, widthForSize };
|