@devicechain/widget-sdk 0.24.0 → 0.25.0-rc.2
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 +15 -0
- package/dist/chunks/{chunk-A5BJ2ALW.js → chunk-G6I5HKQM.js} +36 -105
- package/dist/chunks/chunk-G6I5HKQM.js.map +7 -0
- package/dist/chunks/chunk-IG6DBHKZ.js +109 -0
- package/dist/chunks/chunk-IG6DBHKZ.js.map +7 -0
- package/dist/chunks/chunk-PECV5KDV.js +154 -0
- package/dist/chunks/chunk-PECV5KDV.js.map +7 -0
- package/dist/chunks/export-menu-727YDRIA.js +184 -0
- package/dist/chunks/export-menu-727YDRIA.js.map +7 -0
- package/dist/context.d.ts +22 -0
- package/dist/echarts.js +9 -3
- package/dist/echarts.js.map +2 -2
- package/dist/empty-state.d.ts +38 -0
- package/dist/empty-state.js +105 -0
- package/dist/empty-state.js.map +7 -0
- package/dist/export-csv.d.ts +12 -0
- package/dist/export-menu.d.ts +24 -0
- package/dist/frame.d.ts +3 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +103 -166
- package/dist/index.js.map +4 -4
- package/dist/widget-export.d.ts +7 -0
- package/package.json +7 -3
- package/dist/chunks/chunk-A5BJ2ALW.js.map +0 -7
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
fontVar,
|
|
4
|
+
spaceVar,
|
|
5
|
+
viewerLocale
|
|
6
|
+
} from "./chunks/chunk-PECV5KDV.js";
|
|
7
|
+
import {
|
|
8
|
+
useWidgetBodySize
|
|
9
|
+
} from "./chunks/chunk-G6I5HKQM.js";
|
|
10
|
+
|
|
11
|
+
// src/empty-state.tsx
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var WIDGET_EMPTY_STRINGS = {
|
|
14
|
+
en: {
|
|
15
|
+
unbound: { title: "No device chosen", detail: "Choose a device for this widget to show its data." },
|
|
16
|
+
notReported: {
|
|
17
|
+
title: "Not reported by this device",
|
|
18
|
+
detail: (m) => `This device's profile does not include ${m ? `"${m}"` : "this measurement"}, so it will not report it.`
|
|
19
|
+
},
|
|
20
|
+
noData: {
|
|
21
|
+
title: "No data in this range",
|
|
22
|
+
detail: (m) => `Nothing was reported${m ? ` for "${m}"` : ""} in the selected time range.`
|
|
23
|
+
},
|
|
24
|
+
forbidden: { title: "No access", detail: "You do not have access to this data." },
|
|
25
|
+
error: { title: "Data unavailable", detail: "The data source did not answer." }
|
|
26
|
+
},
|
|
27
|
+
es: {
|
|
28
|
+
unbound: { title: "Sin dispositivo elegido", detail: "Elija un dispositivo para que este widget muestre sus datos." },
|
|
29
|
+
notReported: {
|
|
30
|
+
title: "Este dispositivo no lo informa",
|
|
31
|
+
detail: (m) => `El perfil de este dispositivo no incluye ${m ? `"${m}"` : "esta medici\xF3n"}, por lo que no la informar\xE1.`
|
|
32
|
+
},
|
|
33
|
+
noData: {
|
|
34
|
+
title: "Sin datos en este rango",
|
|
35
|
+
detail: (m) => `No se inform\xF3 nada${m ? ` de "${m}"` : ""} en el rango de tiempo elegido.`
|
|
36
|
+
},
|
|
37
|
+
forbidden: { title: "Sin acceso", detail: "No tiene acceso a estos datos." },
|
|
38
|
+
error: { title: "Datos no disponibles", detail: "El origen de datos no respondi\xF3." }
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function widgetEmptyStrings(locale = viewerLocale()) {
|
|
42
|
+
return locale?.toLowerCase().split("-")[0] === "es" ? WIDGET_EMPTY_STRINGS.es : WIDGET_EMPTY_STRINGS.en;
|
|
43
|
+
}
|
|
44
|
+
var GLYPH = {
|
|
45
|
+
unbound: "\u25CB",
|
|
46
|
+
"not-reported": "\u2205",
|
|
47
|
+
"no-data": "\u2205",
|
|
48
|
+
forbidden: "\u2298",
|
|
49
|
+
error: "\u2026"
|
|
50
|
+
};
|
|
51
|
+
var DETAIL_MIN = { width: 150, height: 84 };
|
|
52
|
+
var HINT_MIN = { width: 150, height: 100 };
|
|
53
|
+
var GLYPH_MIN_HEIGHT = 56;
|
|
54
|
+
function WidgetEmptyState({ kind, measurement, hint, detail, locale }) {
|
|
55
|
+
const size = useWidgetBodySize();
|
|
56
|
+
const words = widgetEmptyStrings(locale);
|
|
57
|
+
const copy = kind === "unbound" ? { title: words.unbound.title, detail: words.unbound.detail } : kind === "not-reported" ? { title: words.notReported.title, detail: words.notReported.detail(measurement) } : kind === "no-data" ? { title: words.noData.title, detail: words.noData.detail(measurement) } : kind === "forbidden" ? words.forbidden : words.error;
|
|
58
|
+
const measured = size.width > 0 && size.height > 0;
|
|
59
|
+
const room = (min) => !measured || size.width >= min.width && size.height >= min.height;
|
|
60
|
+
const text = detail ?? copy.detail;
|
|
61
|
+
const lines = { overflowWrap: "anywhere" };
|
|
62
|
+
return /* @__PURE__ */ jsxs(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
role: "status",
|
|
66
|
+
"data-empty-state": kind,
|
|
67
|
+
title: `${copy.title}. ${text}`,
|
|
68
|
+
style: {
|
|
69
|
+
display: "flex",
|
|
70
|
+
flexDirection: "column",
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
justifyContent: "center",
|
|
73
|
+
gap: spaceVar(1),
|
|
74
|
+
width: "100%",
|
|
75
|
+
height: "100%",
|
|
76
|
+
boxSizing: "border-box",
|
|
77
|
+
padding: spaceVar(2),
|
|
78
|
+
textAlign: "center",
|
|
79
|
+
overflow: "hidden",
|
|
80
|
+
color: css("muted-foreground")
|
|
81
|
+
},
|
|
82
|
+
children: [
|
|
83
|
+
!measured || size.height >= GLYPH_MIN_HEIGHT ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", style: { fontSize: fontVar("lg"), lineHeight: 1 }, children: GLYPH[kind] }) : null,
|
|
84
|
+
/* @__PURE__ */ jsx("div", { "data-empty-title": "", style: { ...lines, fontSize: fontVar("sm"), fontWeight: 600 }, children: copy.title }),
|
|
85
|
+
room(DETAIL_MIN) ? /* @__PURE__ */ jsx("div", { "data-empty-detail": "", style: { ...lines, fontSize: fontVar("xs"), opacity: 0.85 }, children: text }) : null,
|
|
86
|
+
hint && room(HINT_MIN) ? /* @__PURE__ */ jsx("div", { "data-empty-hint": "", style: { ...lines, fontSize: fontVar("xs"), fontVariantNumeric: "tabular-nums" }, children: hint }) : null
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
var LAST_VALUE_STRINGS = {
|
|
92
|
+
en: { lastValue: (value, age) => `Last value ${value} \xB7 ${age}` },
|
|
93
|
+
es: { lastValue: (value, age) => `\xDAltimo valor ${value} \xB7 ${age}` }
|
|
94
|
+
};
|
|
95
|
+
function lastValueHint(value, age, locale = viewerLocale()) {
|
|
96
|
+
return (locale?.toLowerCase().split("-")[0] === "es" ? LAST_VALUE_STRINGS.es : LAST_VALUE_STRINGS.en).lastValue(value, age);
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
LAST_VALUE_STRINGS,
|
|
100
|
+
WIDGET_EMPTY_STRINGS,
|
|
101
|
+
WidgetEmptyState,
|
|
102
|
+
lastValueHint,
|
|
103
|
+
widgetEmptyStrings
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=empty-state.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/empty-state.tsx"],
|
|
4
|
+
"sourcesContent": ["// Copyright The DeviceChain Authors\n// SPDX-License-Identifier: Apache-2.0\n\n// An EXPLAINED empty state: the body a widget shows when it has nothing to draw, saying which of the\n// few reasons it is. A bare dash or a blank card cannot tell \"nobody picked a device\" from \"this\n// device never reports that\" from \"the device is quiet right now\", and a board that does not say\n// looks broken. The kinds are:\n//\n// unbound no device (or slot binding) is chosen: the author's job\n// not-reported the device's active profile does not declare this measurement: it will never report it\n// no-data declared, but nothing arrived in the window; `hint` can say what the last value was\n// forbidden the platform refused the read for this viewer\n// error the source failed to answer\n//\n// Styling is deliberately NEUTRAL (ISA-101): the muted foreground, a quiet glyph, no severity hue and no\n// warning symbol. Alarm colour means an alarm on a board, so a state that is not one never borrows it.\n// It sizes by the frame's content column: a small widget keeps the title, a roomy one adds the\n// explanation and the hint.\n\nimport type { CSSProperties } from 'react';\n\nimport { useWidgetBodySize } from './context';\nimport { viewerLocale } from './freshness';\nimport { css } from './theme';\nimport { fontVar, spaceVar } from './tokens';\n\nexport type WidgetEmptyKind = 'unbound' | 'not-reported' | 'no-data' | 'forbidden' | 'error';\n\nexport interface WidgetEmptyStrings {\n unbound: { title: string; detail: string };\n notReported: { title: string; detail: (measurement: string | undefined) => string };\n noData: { title: string; detail: (measurement: string | undefined) => string };\n forbidden: { title: string; detail: string };\n error: { title: string; detail: string };\n}\n\nexport const WIDGET_EMPTY_STRINGS: Record<'en' | 'es', WidgetEmptyStrings> = {\n en: {\n unbound: { title: 'No device chosen', detail: 'Choose a device for this widget to show its data.' },\n notReported: {\n title: 'Not reported by this device',\n detail: (m) => `This device's profile does not include ${m ? `\"${m}\"` : 'this measurement'}, so it will not report it.`,\n },\n noData: {\n title: 'No data in this range',\n detail: (m) => `Nothing was reported${m ? ` for \"${m}\"` : ''} in the selected time range.`,\n },\n forbidden: { title: 'No access', detail: 'You do not have access to this data.' },\n error: { title: 'Data unavailable', detail: 'The data source did not answer.' },\n },\n es: {\n unbound: { title: 'Sin dispositivo elegido', detail: 'Elija un dispositivo para que este widget muestre sus datos.' },\n notReported: {\n title: 'Este dispositivo no lo informa',\n detail: (m) => `El perfil de este dispositivo no incluye ${m ? `\"${m}\"` : 'esta medici\u00F3n'}, por lo que no la informar\u00E1.`,\n },\n noData: {\n title: 'Sin datos en este rango',\n detail: (m) => `No se inform\u00F3 nada${m ? ` de \"${m}\"` : ''} en el rango de tiempo elegido.`,\n },\n forbidden: { title: 'Sin acceso', detail: 'No tiene acceso a estos datos.' },\n error: { title: 'Datos no disponibles', detail: 'El origen de datos no respondi\u00F3.' },\n },\n};\n\nexport function widgetEmptyStrings(locale: string | undefined = viewerLocale()): WidgetEmptyStrings {\n return locale?.toLowerCase().split('-')[0] === 'es' ? WIDGET_EMPTY_STRINGS.es : WIDGET_EMPTY_STRINGS.en;\n}\n\n// The glyph per kind. Quiet and non-alarming; the access refusal keeps the circle-slash the board's\n// other settled panes use.\nconst GLYPH: Record<WidgetEmptyKind, string> = {\n unbound: '\u25CB',\n 'not-reported': '\u2205',\n 'no-data': '\u2205',\n forbidden: '\u2298',\n error: '\u2026',\n};\n\n// The sizes (px of the content column) at which the explanation and the hint make room for the title.\nconst DETAIL_MIN = { width: 150, height: 84 };\nconst HINT_MIN = { width: 150, height: 100 };\nconst GLYPH_MIN_HEIGHT = 56;\n\nexport interface WidgetEmptyStateProps {\n kind: WidgetEmptyKind;\n // The measurement the widget was asked for, named in the explanation.\n measurement?: string;\n // One line after the explanation: for no-data, the last value known and when (\"Last value 21.4 \u00B0C \u00B7 3 hr. ago\").\n hint?: string;\n // Replaces the stock explanation (an error's own message, say).\n detail?: string;\n locale?: string;\n}\n\nexport function WidgetEmptyState({ kind, measurement, hint, detail, locale }: WidgetEmptyStateProps) {\n const size = useWidgetBodySize();\n const words = widgetEmptyStrings(locale);\n const copy =\n kind === 'unbound'\n ? { title: words.unbound.title, detail: words.unbound.detail }\n : kind === 'not-reported'\n ? { title: words.notReported.title, detail: words.notReported.detail(measurement) }\n : kind === 'no-data'\n ? { title: words.noData.title, detail: words.noData.detail(measurement) }\n : kind === 'forbidden'\n ? words.forbidden\n : words.error;\n // Unmeasured (first frame, jsdom) shows everything.\n const measured = size.width > 0 && size.height > 0;\n const room = (min: { width: number; height: number }) => !measured || (size.width >= min.width && size.height >= min.height);\n const text = detail ?? copy.detail;\n const lines: CSSProperties = { overflowWrap: 'anywhere' };\n return (\n <div\n role=\"status\"\n data-empty-state={kind}\n title={`${copy.title}. ${text}`}\n style={{\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: spaceVar(1),\n width: '100%',\n height: '100%',\n boxSizing: 'border-box',\n padding: spaceVar(2),\n textAlign: 'center',\n overflow: 'hidden',\n color: css('muted-foreground'),\n }}\n >\n {!measured || size.height >= GLYPH_MIN_HEIGHT ? (\n <div aria-hidden=\"true\" style={{ fontSize: fontVar('lg'), lineHeight: 1 }}>\n {GLYPH[kind]}\n </div>\n ) : null}\n <div data-empty-title=\"\" style={{ ...lines, fontSize: fontVar('sm'), fontWeight: 600 }}>\n {copy.title}\n </div>\n {room(DETAIL_MIN) ? (\n <div data-empty-detail=\"\" style={{ ...lines, fontSize: fontVar('xs'), opacity: 0.85 }}>\n {text}\n </div>\n ) : null}\n {hint && room(HINT_MIN) ? (\n <div data-empty-hint=\"\" style={{ ...lines, fontSize: fontVar('xs'), fontVariantNumeric: 'tabular-nums' }}>\n {hint}\n </div>\n ) : null}\n </div>\n );\n}\n\n// The words of the hint, in the widget packages' two languages.\nexport interface LastValueStrings {\n lastValue: (value: string, age: string) => string;\n}\n\nexport const LAST_VALUE_STRINGS: Record<'en' | 'es', LastValueStrings> = {\n en: { lastValue: (value, age) => `Last value ${value} \u00B7 ${age}` },\n es: { lastValue: (value, age) => `\u00DAltimo valor ${value} \u00B7 ${age}` },\n};\n\nexport function lastValueHint(value: string, age: string, locale: string | undefined = viewerLocale()): string {\n return (locale?.toLowerCase().split('-')[0] === 'es' ? LAST_VALUE_STRINGS.es : LAST_VALUE_STRINGS.en).lastValue(value, age);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WidgetExportCell, WidgetExportTable } from './widget-export';
|
|
2
|
+
/** True when a spreadsheet could read the text as a formula. */
|
|
3
|
+
export declare function formulaLike(text: string): boolean;
|
|
4
|
+
/** Encodes one cell: formula-guarded, then quoted when RFC 4180 requires it. */
|
|
5
|
+
export declare function csvCell(value: WidgetExportCell): string;
|
|
6
|
+
/** The table as CSV text: headings first, CRLF line endings, a trailing CRLF. */
|
|
7
|
+
export declare function toCsv(table: Pick<WidgetExportTable, 'columns' | 'rows'>): string;
|
|
8
|
+
export declare function safeFileStem(name: string, fallback?: string): string;
|
|
9
|
+
/** Saves bytes as a file download. */
|
|
10
|
+
export declare function downloadBlob(filename: string, blob: Blob): void;
|
|
11
|
+
/** Saves the table as `<name>.csv`: UTF-8 with a byte-order mark (see the top of this file). */
|
|
12
|
+
export declare function downloadCsv(table: WidgetExportTable): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WidgetImageSource } from './context';
|
|
2
|
+
import type { WidgetExportResult } from './widget-export';
|
|
3
|
+
export interface ExportMenuOptions {
|
|
4
|
+
exportRows: (() => WidgetExportResult) | undefined;
|
|
5
|
+
image: WidgetImageSource | undefined;
|
|
6
|
+
title: string | undefined;
|
|
7
|
+
frameElement: () => Element | null;
|
|
8
|
+
onClose: (refocus: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function opaqueBackground(el: Element | null): string;
|
|
11
|
+
export declare function fileStamp(at: Date): string;
|
|
12
|
+
/**
|
|
13
|
+
* Opens the menu inside `host` (the positioned box around the button) and focuses its first item.
|
|
14
|
+
* Returns a function that closes it without calling `onClose` (the frame unmounting, or the button
|
|
15
|
+
* pressed again).
|
|
16
|
+
*/
|
|
17
|
+
export declare function openExportMenu(host: HTMLElement, o: ExportMenuOptions): () => void;
|
|
18
|
+
export type ExportSource = Omit<ExportMenuOptions, 'onClose'>;
|
|
19
|
+
/**
|
|
20
|
+
* Draws the export button (`size` px square) inside `host`, the box the frame reserves for it in the
|
|
21
|
+
* title bar. The button opens and closes the menu. Returns a function that removes both (the frame
|
|
22
|
+
* unmounting, or no longer having anything to export).
|
|
23
|
+
*/
|
|
24
|
+
export declare function mountExportButton(host: HTMLElement, size: number, source: () => ExportSource): () => void;
|
package/dist/frame.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
2
|
import { type WidgetScale } from './scale';
|
|
3
|
+
import type { WidgetExportResult } from './widget-export';
|
|
3
4
|
export declare const FRAME_SUBTITLE_MIN_HEIGHT = 120;
|
|
4
5
|
export declare const FRAME_TITLE_MIN_HEIGHT = 76;
|
|
5
6
|
export interface WidgetFrameProps {
|
|
@@ -9,5 +10,6 @@ export interface WidgetFrameProps {
|
|
|
9
10
|
bodyStyle?: CSSProperties;
|
|
10
11
|
flush?: boolean;
|
|
11
12
|
sampleTime?: string | null;
|
|
13
|
+
exportRows?: () => WidgetExportResult;
|
|
12
14
|
}
|
|
13
|
-
export declare function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }: WidgetFrameProps): import("react").JSX.Element;
|
|
15
|
+
export declare function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime, exportRows }: WidgetFrameProps): import("react").JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export { defineWidget } from './define-widget';
|
|
|
2
2
|
export type { ErasedComponent, ErasedWidgetDefinition, WidgetDefinition, WidgetImplementation } from './define-widget';
|
|
3
3
|
export { createWidgetRegistry, WidgetRegistryError, type WidgetRegistry } from './registry';
|
|
4
4
|
export type { EditorCommandChoice, EditorCommandChoices, WidgetComponent, WidgetEditorProps, WidgetEditorServices, WidgetProps, } from './widget';
|
|
5
|
-
export { WidgetCandidatesProvider, WidgetDensityProvider, WidgetFrameStyleProvider, WidgetFreshnessProvider, WidgetSelectProvider, WidgetSubjectProvider, WidgetThemeRootProvider, WidgetTimeRangeProvider, WidgetTimeZoneProvider, useWidgetCandidates, useWidgetFrameStyle, useWidgetFreshness, useWidgetSelect, useWidgetSubject, useWidgetThemeRoot, useWidgetTimeRange, useWidgetTimeZone, type WidgetBodySize, type WidgetCandidates, type WidgetFreshness, type WidgetSelect, } from './context';
|
|
5
|
+
export { WidgetCandidatesProvider, WidgetDeclaredMetricsProvider, WidgetDensityProvider, WidgetFrameStyleProvider, WidgetFreshnessProvider, WidgetSelectProvider, WidgetSubjectProvider, WidgetThemeRootProvider, WidgetTimeRangeProvider, WidgetTimeZoneProvider, useWidgetCandidates, useWidgetDeclaredMetrics, useWidgetFrameStyle, useWidgetFreshness, useWidgetSelect, useWidgetSubject, useWidgetThemeRoot, useWidgetTimeRange, useWidgetTimeZone, type WidgetBodySize, type WidgetCandidates, type WidgetDeclaredMetrics, type WidgetFreshness, type WidgetSelect, } from './context';
|
|
6
6
|
export { WidgetFrame, type WidgetFrameProps } from './frame';
|
|
7
|
+
export type { WidgetExportCell, WidgetExportResult, WidgetExportTable } from './widget-export';
|
|
7
8
|
export { css, type ThemeVar } from './theme';
|
|
8
9
|
export { FIT_MIN_FONT_PX, fitValueFont, fitValueFontCss, type FitOptions } from './fit-text';
|
|
9
10
|
export { FONT_TOKENS, SPACE_TOKENS, WidgetTokenStyles, densityScale, fontVar, spaceVar, tokenPx, tokenStyle, type FontToken, type SizeToken, type SpaceToken, } from './tokens';
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,64 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
FONT_TOKENS,
|
|
3
|
+
SPACE_TOKENS,
|
|
4
|
+
WidgetTokenStyles,
|
|
5
|
+
ageSeconds,
|
|
6
|
+
css,
|
|
7
|
+
densityScale,
|
|
8
|
+
fontVar,
|
|
9
|
+
formatAge,
|
|
10
|
+
freshnessStrings,
|
|
11
|
+
isStale,
|
|
12
|
+
newestSampleTime,
|
|
13
|
+
optBoolean,
|
|
14
|
+
optNumber,
|
|
15
|
+
optString,
|
|
16
|
+
pickSample,
|
|
17
|
+
primaryMeasurementName,
|
|
18
|
+
resolveStaleAfterSeconds,
|
|
19
|
+
spaceVar,
|
|
20
|
+
tokenPx,
|
|
21
|
+
tokenStyle,
|
|
22
|
+
viewerLocale
|
|
23
|
+
} from "./chunks/chunk-PECV5KDV.js";
|
|
24
|
+
import {
|
|
3
25
|
FIT_MIN_FONT_PX,
|
|
26
|
+
bandAt,
|
|
27
|
+
fitValueFont,
|
|
28
|
+
fitValueFontCss,
|
|
29
|
+
formatDateTime,
|
|
30
|
+
formatTimestamp,
|
|
31
|
+
formatValue,
|
|
32
|
+
optThresholds,
|
|
33
|
+
parseThresholds,
|
|
34
|
+
stickyChars,
|
|
35
|
+
thresholdBands
|
|
36
|
+
} from "./chunks/chunk-IG6DBHKZ.js";
|
|
37
|
+
import {
|
|
38
|
+
ALARM_LEVELS,
|
|
4
39
|
SEVERITY_LEVELS,
|
|
5
40
|
SEVERITY_TOKENS,
|
|
6
41
|
WidgetBodySizeProvider,
|
|
7
42
|
WidgetCandidatesProvider,
|
|
43
|
+
WidgetDeclaredMetricsProvider,
|
|
8
44
|
WidgetDensityProvider,
|
|
9
45
|
WidgetFrameStyleProvider,
|
|
10
46
|
WidgetFreshnessProvider,
|
|
47
|
+
WidgetImageRegistrarProvider,
|
|
11
48
|
WidgetSelectProvider,
|
|
12
49
|
WidgetSubjectProvider,
|
|
13
50
|
WidgetThemeRootProvider,
|
|
14
51
|
WidgetTimeRangeProvider,
|
|
15
52
|
WidgetTimeZoneProvider,
|
|
16
|
-
bandAt,
|
|
17
|
-
fitValueFont,
|
|
18
|
-
fitValueFontCss,
|
|
19
|
-
formatDateTime,
|
|
20
|
-
formatTimestamp,
|
|
21
|
-
formatValue,
|
|
22
53
|
isAlarmLevel,
|
|
23
54
|
isSeverityLevel,
|
|
24
55
|
levelColor,
|
|
25
|
-
optThresholds,
|
|
26
|
-
parseThresholds,
|
|
27
56
|
severityTokenCss,
|
|
28
57
|
severityVar,
|
|
29
|
-
stickyChars,
|
|
30
|
-
thresholdBands,
|
|
31
58
|
useSeverityColors,
|
|
32
59
|
useWidgetBodySize,
|
|
33
60
|
useWidgetCandidates,
|
|
61
|
+
useWidgetDeclaredMetrics,
|
|
34
62
|
useWidgetDensityScale,
|
|
35
63
|
useWidgetFrameStyle,
|
|
36
64
|
useWidgetFreshness,
|
|
@@ -39,7 +67,7 @@ import {
|
|
|
39
67
|
useWidgetThemeRoot,
|
|
40
68
|
useWidgetTimeRange,
|
|
41
69
|
useWidgetTimeZone
|
|
42
|
-
} from "./chunks/chunk-
|
|
70
|
+
} from "./chunks/chunk-G6I5HKQM.js";
|
|
43
71
|
|
|
44
72
|
// src/define-widget.ts
|
|
45
73
|
function defineWidget(definition) {
|
|
@@ -109,139 +137,11 @@ function createWidgetRegistry(definitions) {
|
|
|
109
137
|
|
|
110
138
|
// src/frame.tsx
|
|
111
139
|
import { resolveFrame, sameLabel } from "@devicechain/dashboards";
|
|
112
|
-
import { useMemo as useMemo3 } from "react";
|
|
140
|
+
import { useCallback, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
113
141
|
|
|
114
142
|
// src/freshness-readout.tsx
|
|
115
143
|
import { useEffect, useState } from "react";
|
|
116
|
-
|
|
117
|
-
// src/widget-options.ts
|
|
118
|
-
function pickSample(latest, name) {
|
|
119
|
-
return name ? latest[name] : Object.values(latest)[0];
|
|
120
|
-
}
|
|
121
|
-
function optString(options, key) {
|
|
122
|
-
const value = options?.[key];
|
|
123
|
-
return typeof value === "string" ? value : void 0;
|
|
124
|
-
}
|
|
125
|
-
function optNumber(options, key) {
|
|
126
|
-
const value = options?.[key];
|
|
127
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
128
|
-
}
|
|
129
|
-
function optBoolean(options, key) {
|
|
130
|
-
return options?.[key] === true;
|
|
131
|
-
}
|
|
132
|
-
function primaryMeasurementName(widget) {
|
|
133
|
-
const explicit = optString(widget.options, "measurement");
|
|
134
|
-
if (explicit) return explicit;
|
|
135
|
-
const ds = widget.datasource;
|
|
136
|
-
if (ds && ds.measurements.length > 0) return ds.measurements[0];
|
|
137
|
-
return void 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/freshness.ts
|
|
141
|
-
function resolveStaleAfterSeconds(options) {
|
|
142
|
-
const configured = optNumber(options, "staleAfterSeconds");
|
|
143
|
-
return configured !== void 0 && configured > 0 ? configured : void 0;
|
|
144
|
-
}
|
|
145
|
-
function newestSampleTime(latest, names) {
|
|
146
|
-
let newest;
|
|
147
|
-
for (const [name, sample] of Object.entries(latest)) {
|
|
148
|
-
if (names && names.length > 0 && !names.includes(name)) continue;
|
|
149
|
-
if (!sample.occurredTime) continue;
|
|
150
|
-
const at = Date.parse(sample.occurredTime);
|
|
151
|
-
if (Number.isNaN(at)) continue;
|
|
152
|
-
if (newest === void 0 || at > newest) newest = at;
|
|
153
|
-
}
|
|
154
|
-
return newest;
|
|
155
|
-
}
|
|
156
|
-
function ageSeconds(at, now) {
|
|
157
|
-
return Math.max(0, Math.floor((now - at) / 1e3));
|
|
158
|
-
}
|
|
159
|
-
function isStale(age, staleAfter) {
|
|
160
|
-
return staleAfter !== void 0 && age > staleAfter;
|
|
161
|
-
}
|
|
162
|
-
function viewerLocale() {
|
|
163
|
-
if (typeof document !== "undefined" && document.documentElement.lang) return document.documentElement.lang;
|
|
164
|
-
if (typeof navigator !== "undefined" && navigator.language) return navigator.language;
|
|
165
|
-
return void 0;
|
|
166
|
-
}
|
|
167
|
-
var formatters = /* @__PURE__ */ new Map();
|
|
168
|
-
function relativeTimeFormat(locale) {
|
|
169
|
-
const key = locale ?? "";
|
|
170
|
-
let formatter = formatters.get(key);
|
|
171
|
-
if (!formatter) {
|
|
172
|
-
try {
|
|
173
|
-
formatter = new Intl.RelativeTimeFormat(locale, { numeric: "auto", style: "short" });
|
|
174
|
-
} catch {
|
|
175
|
-
formatter = new Intl.RelativeTimeFormat(void 0, { numeric: "auto", style: "short" });
|
|
176
|
-
}
|
|
177
|
-
formatters.set(key, formatter);
|
|
178
|
-
}
|
|
179
|
-
return formatter;
|
|
180
|
-
}
|
|
181
|
-
function formatAge(age, locale = viewerLocale()) {
|
|
182
|
-
const formatter = relativeTimeFormat(locale);
|
|
183
|
-
if (age < 60) return formatter.format(-age, "second");
|
|
184
|
-
if (age < 3600) return formatter.format(-Math.floor(age / 60), "minute");
|
|
185
|
-
if (age < 86400) return formatter.format(-Math.floor(age / 3600), "hour");
|
|
186
|
-
return formatter.format(-Math.floor(age / 86400), "day");
|
|
187
|
-
}
|
|
188
|
-
var FRESHNESS_STRINGS = {
|
|
189
|
-
en: { stale: "stale", ageLabel: "Last sample" },
|
|
190
|
-
es: { stale: "obsoleto", ageLabel: "\xDAltima muestra" }
|
|
191
|
-
};
|
|
192
|
-
function freshnessStrings(locale = viewerLocale()) {
|
|
193
|
-
const base = locale?.toLowerCase().split("-")[0];
|
|
194
|
-
return base === "es" ? FRESHNESS_STRINGS.es : FRESHNESS_STRINGS.en;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// src/theme.ts
|
|
198
|
-
function css(name) {
|
|
199
|
-
return `hsl(var(--${name}))`;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// src/tokens.tsx
|
|
203
|
-
import { DENSITY_SCALE, SPACE_TOKEN_PX } from "@devicechain/dashboards";
|
|
204
|
-
import { jsx } from "react/jsx-runtime";
|
|
205
|
-
var FONT_TOKENS = {
|
|
206
|
-
xs: 11,
|
|
207
|
-
sm: 12,
|
|
208
|
-
md: 13,
|
|
209
|
-
lg: 16,
|
|
210
|
-
xl: 20,
|
|
211
|
-
display: 28
|
|
212
|
-
};
|
|
213
|
-
var SPACE_TOKENS = {
|
|
214
|
-
1: SPACE_TOKEN_PX["space-1"],
|
|
215
|
-
2: SPACE_TOKEN_PX["space-2"],
|
|
216
|
-
3: SPACE_TOKEN_PX["space-3"],
|
|
217
|
-
4: SPACE_TOKEN_PX["space-4"]
|
|
218
|
-
};
|
|
219
|
-
function densityScale(density) {
|
|
220
|
-
return DENSITY_SCALE[density ?? "comfortable"];
|
|
221
|
-
}
|
|
222
|
-
function fontVar(token) {
|
|
223
|
-
return `var(--dc-font-${token}, ${FONT_TOKENS[token]}px)`;
|
|
224
|
-
}
|
|
225
|
-
function spaceVar(token) {
|
|
226
|
-
return `var(--dc-space-${token}, ${SPACE_TOKENS[token]}px)`;
|
|
227
|
-
}
|
|
228
|
-
function tokenPx(token, scale = 1) {
|
|
229
|
-
const [kind, name] = token.split("-");
|
|
230
|
-
const base = kind === "font" ? FONT_TOKENS[name] : SPACE_TOKENS[Number(name)];
|
|
231
|
-
return Math.round(base * scale * 100) / 100;
|
|
232
|
-
}
|
|
233
|
-
function tokenStyle(scale) {
|
|
234
|
-
const vars = { "--dc-scale": String(scale) };
|
|
235
|
-
for (const [name, px] of Object.entries(FONT_TOKENS)) vars[`--dc-font-${name}`] = `calc(${px}px * var(--dc-scale))`;
|
|
236
|
-
for (const [name, px] of Object.entries(SPACE_TOKENS)) vars[`--dc-space-${name}`] = `calc(${px}px * var(--dc-scale))`;
|
|
237
|
-
return vars;
|
|
238
|
-
}
|
|
239
|
-
function WidgetTokenStyles() {
|
|
240
|
-
return /* @__PURE__ */ jsx("style", { "data-dc-tokens": "", children: severityTokenCss({ hostWins: true }) });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/freshness-readout.tsx
|
|
244
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
144
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
245
145
|
var tickers = /* @__PURE__ */ new Map();
|
|
246
146
|
function subscribeTick(everyMs, listener) {
|
|
247
147
|
let ticker = tickers.get(everyMs);
|
|
@@ -286,7 +186,7 @@ function useFreshness(at, staleAfterSeconds) {
|
|
|
286
186
|
return { age, stale: isStale(age, staleAfterSeconds) };
|
|
287
187
|
}
|
|
288
188
|
function StaleBadge({ label }) {
|
|
289
|
-
return /* @__PURE__ */
|
|
189
|
+
return /* @__PURE__ */ jsx(
|
|
290
190
|
"span",
|
|
291
191
|
{
|
|
292
192
|
"data-stale-badge": "",
|
|
@@ -309,7 +209,7 @@ function StaleBadge({ label }) {
|
|
|
309
209
|
function Freshness({ at, staleAfterSeconds, staleLabel, style }) {
|
|
310
210
|
const reading = useFreshness(at, staleAfterSeconds);
|
|
311
211
|
if (!reading) return null;
|
|
312
|
-
return /* @__PURE__ */
|
|
212
|
+
return /* @__PURE__ */ jsx(FreshnessReadout, { reading, staleLabel, style });
|
|
313
213
|
}
|
|
314
214
|
function FreshnessReadout({
|
|
315
215
|
reading,
|
|
@@ -332,8 +232,8 @@ function FreshnessReadout({
|
|
|
332
232
|
...style
|
|
333
233
|
},
|
|
334
234
|
children: [
|
|
335
|
-
/* @__PURE__ */
|
|
336
|
-
reading.stale ? /* @__PURE__ */
|
|
235
|
+
/* @__PURE__ */ jsx("time", { children: formatAge(reading.age) }),
|
|
236
|
+
reading.stale ? /* @__PURE__ */ jsx(StaleBadge, { label: staleLabel }) : null
|
|
337
237
|
]
|
|
338
238
|
}
|
|
339
239
|
);
|
|
@@ -772,12 +672,13 @@ function useStickyChars(chars, holdMs = STICKY_HOLD_MS) {
|
|
|
772
672
|
}
|
|
773
673
|
|
|
774
674
|
// src/frame.tsx
|
|
775
|
-
import { jsx as
|
|
675
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
776
676
|
var FRESHNESS_MIN_WIDTH = 150;
|
|
777
677
|
var FRESHNESS_MIN_HEIGHT = 110;
|
|
778
678
|
var FRAME_SUBTITLE_MIN_HEIGHT = 120;
|
|
779
679
|
var FRAME_TITLE_MIN_HEIGHT = 76;
|
|
780
680
|
var BODY_SIZE_STEP = 4;
|
|
681
|
+
var EXPORT_BUTTON_SIZE = 24;
|
|
781
682
|
var DEFAULT_FRAME = resolveFrame(void 0, void 0);
|
|
782
683
|
var RADIUS = {
|
|
783
684
|
none: "0px",
|
|
@@ -793,7 +694,7 @@ function parseSampleTime(time) {
|
|
|
793
694
|
const at = Date.parse(time);
|
|
794
695
|
return Number.isNaN(at) ? void 0 : at;
|
|
795
696
|
}
|
|
796
|
-
function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }) {
|
|
697
|
+
function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime, exportRows }) {
|
|
797
698
|
const subject = useWidgetSubject();
|
|
798
699
|
const rawSub = subtitle ?? subject;
|
|
799
700
|
const dupSub = rawSub && sameLabel(rawSub, title) ? void 0 : rawSub;
|
|
@@ -801,6 +702,8 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
801
702
|
const at = freshness === void 0 ? void 0 : sampleTime === void 0 ? freshness.at : parseSampleTime(sampleTime);
|
|
802
703
|
const reading = useFreshness(at, freshness?.staleAfterSeconds);
|
|
803
704
|
const [rootRef, size] = useElementSize();
|
|
705
|
+
const [image, setImage] = useState3();
|
|
706
|
+
const registerImage = useCallback((source) => setImage(source ? { source } : void 0), []);
|
|
804
707
|
const [columnRef, columnSize] = useElementSize(BODY_SIZE_STEP);
|
|
805
708
|
const scale = useWidgetDensityScale();
|
|
806
709
|
const frame = useWidgetFrameStyle() ?? DEFAULT_FRAME;
|
|
@@ -812,6 +715,7 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
812
715
|
const sub = showSub ? dupSub : void 0;
|
|
813
716
|
const shownTitle = showTitle ? title : void 0;
|
|
814
717
|
const widgetScale = useMemo3(() => makeWidgetScale(columnSize, scale), [columnSize, scale]);
|
|
718
|
+
const exportable = Boolean(shownTitle || sub) && (exportRows !== void 0 || image !== void 0);
|
|
815
719
|
const compact = size.width > 0 && (size.width < FRESHNESS_MIN_WIDTH || size.height < FRESHNESS_MIN_HEIGHT);
|
|
816
720
|
const stale = reading?.stale === true;
|
|
817
721
|
return /* @__PURE__ */ jsxs2(
|
|
@@ -839,11 +743,14 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
839
743
|
"div",
|
|
840
744
|
{
|
|
841
745
|
style: {
|
|
746
|
+
position: "relative",
|
|
842
747
|
padding: `${spaceVar(2)} ${spaceVar(3)}`,
|
|
748
|
+
// Room for the export button, which sits at the bar's right edge.
|
|
749
|
+
...exportable ? { paddingRight: `calc(${spaceVar(3)} + ${EXPORT_BUTTON_SIZE}px)` } : null,
|
|
843
750
|
borderBottom: rule
|
|
844
751
|
},
|
|
845
752
|
children: [
|
|
846
|
-
shownTitle ? /* @__PURE__ */
|
|
753
|
+
shownTitle ? /* @__PURE__ */ jsx2(
|
|
847
754
|
"div",
|
|
848
755
|
{
|
|
849
756
|
title: shownTitle,
|
|
@@ -858,7 +765,7 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
858
765
|
children: shownTitle
|
|
859
766
|
}
|
|
860
767
|
) : null,
|
|
861
|
-
sub ? /* @__PURE__ */
|
|
768
|
+
sub ? /* @__PURE__ */ jsx2(
|
|
862
769
|
"div",
|
|
863
770
|
{
|
|
864
771
|
title: sub,
|
|
@@ -874,11 +781,12 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
874
781
|
},
|
|
875
782
|
children: sub
|
|
876
783
|
}
|
|
877
|
-
) : null
|
|
784
|
+
) : null,
|
|
785
|
+
exportable ? /* @__PURE__ */ jsx2(ExportSlot, { exportRows, image: image?.source, title, frameElement: () => rootRef.current }) : null
|
|
878
786
|
]
|
|
879
787
|
}
|
|
880
788
|
) : null,
|
|
881
|
-
/* @__PURE__ */
|
|
789
|
+
/* @__PURE__ */ jsx2(
|
|
882
790
|
"div",
|
|
883
791
|
{
|
|
884
792
|
"data-widget-body": "",
|
|
@@ -891,7 +799,7 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
891
799
|
...bodyStyle,
|
|
892
800
|
...stale ? { opacity: 0.45, filter: "grayscale(1)" } : null
|
|
893
801
|
},
|
|
894
|
-
children: /* @__PURE__ */
|
|
802
|
+
children: /* @__PURE__ */ jsx2(
|
|
895
803
|
"div",
|
|
896
804
|
{
|
|
897
805
|
ref: columnRef,
|
|
@@ -904,27 +812,54 @@ function WidgetFrame({ title, subtitle, children, bodyStyle, flush, sampleTime }
|
|
|
904
812
|
overflow: "hidden",
|
|
905
813
|
padding: flush ? 0 : spaceTokenVar(frame.padding)
|
|
906
814
|
},
|
|
907
|
-
children: /* @__PURE__ */
|
|
815
|
+
children: /* @__PURE__ */ jsx2(WidgetBodySizeProvider, { size: columnSize, children: /* @__PURE__ */ jsx2(WidgetImageRegistrarProvider, { register: registerImage, children: typeof children === "function" ? children(widgetScale) : children }) })
|
|
908
816
|
}
|
|
909
817
|
)
|
|
910
818
|
}
|
|
911
819
|
),
|
|
912
|
-
reading && !compact ? /* @__PURE__ */
|
|
820
|
+
reading && !compact ? /* @__PURE__ */ jsx2(
|
|
913
821
|
"div",
|
|
914
822
|
{
|
|
915
823
|
"data-widget-freshness": "",
|
|
916
824
|
style: { padding: `${spaceVar(1)} ${spaceVar(3)}`, borderTop: rule, flex: "0 0 auto" },
|
|
917
|
-
children: /* @__PURE__ */
|
|
825
|
+
children: /* @__PURE__ */ jsx2(FreshnessReadout, { reading })
|
|
918
826
|
}
|
|
919
827
|
) : null,
|
|
920
|
-
reading && compact && stale ? /* @__PURE__ */
|
|
828
|
+
reading && compact && stale ? /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: spaceVar(1), right: spaceVar(1) }, children: /* @__PURE__ */ jsx2(StaleBadge, {}) }) : null
|
|
921
829
|
]
|
|
922
830
|
}
|
|
923
831
|
);
|
|
924
832
|
}
|
|
833
|
+
function ExportSlot(props) {
|
|
834
|
+
const host = useRef3(null);
|
|
835
|
+
const latest = useRef3(props);
|
|
836
|
+
latest.current = props;
|
|
837
|
+
useEffect4(() => {
|
|
838
|
+
let live = true;
|
|
839
|
+
let unmount;
|
|
840
|
+
import("./chunks/export-menu-727YDRIA.js").then(
|
|
841
|
+
(m) => {
|
|
842
|
+
if (live && host.current) unmount = m.mountExportButton(host.current, EXPORT_BUTTON_SIZE, () => latest.current);
|
|
843
|
+
},
|
|
844
|
+
() => void 0
|
|
845
|
+
);
|
|
846
|
+
return () => {
|
|
847
|
+
live = false;
|
|
848
|
+
unmount?.();
|
|
849
|
+
};
|
|
850
|
+
}, []);
|
|
851
|
+
return /* @__PURE__ */ jsx2(
|
|
852
|
+
"div",
|
|
853
|
+
{
|
|
854
|
+
ref: host,
|
|
855
|
+
"data-widget-export": "",
|
|
856
|
+
style: { position: "absolute", top: 0, right: 0, bottom: 0, display: "flex", alignItems: "center", paddingRight: 4 }
|
|
857
|
+
}
|
|
858
|
+
);
|
|
859
|
+
}
|
|
925
860
|
|
|
926
861
|
// src/connection-badge.tsx
|
|
927
|
-
import { jsx as
|
|
862
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
928
863
|
var DOT = {
|
|
929
864
|
live: "primary",
|
|
930
865
|
reconnecting: "muted-foreground",
|
|
@@ -948,7 +883,7 @@ function HubConnectionBadge({ state, labels }) {
|
|
|
948
883
|
whiteSpace: "nowrap"
|
|
949
884
|
},
|
|
950
885
|
children: [
|
|
951
|
-
/* @__PURE__ */
|
|
886
|
+
/* @__PURE__ */ jsx3(
|
|
952
887
|
"span",
|
|
953
888
|
{
|
|
954
889
|
"aria-hidden": true,
|
|
@@ -968,8 +903,8 @@ function HubConnectionBadge({ state, labels }) {
|
|
|
968
903
|
}
|
|
969
904
|
|
|
970
905
|
// src/flash.tsx
|
|
971
|
-
import { useEffect as
|
|
972
|
-
import { jsx as
|
|
906
|
+
import { useEffect as useEffect5, useRef as useRef4, useState as useState4 } from "react";
|
|
907
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
973
908
|
var UP = {
|
|
974
909
|
fg: "var(--flash-up, hsl(142 72% 40%))",
|
|
975
910
|
bg: "var(--flash-up-bg, hsl(142 72% 45% / 0.16))"
|
|
@@ -981,10 +916,10 @@ var DOWN = {
|
|
|
981
916
|
var HOLD_MS = 400;
|
|
982
917
|
var FADE_MS = 600;
|
|
983
918
|
function useFlashOnChange(value, enabled, identity) {
|
|
984
|
-
const prev =
|
|
985
|
-
const prevIdentity =
|
|
986
|
-
const [direction, setDirection] =
|
|
987
|
-
|
|
919
|
+
const prev = useRef4(value);
|
|
920
|
+
const prevIdentity = useRef4(identity);
|
|
921
|
+
const [direction, setDirection] = useState4(null);
|
|
922
|
+
useEffect5(() => {
|
|
988
923
|
const before = prev.current;
|
|
989
924
|
const sameEntity = prevIdentity.current === identity;
|
|
990
925
|
prev.current = value;
|
|
@@ -1018,7 +953,7 @@ function FlashValue({
|
|
|
1018
953
|
style
|
|
1019
954
|
}) {
|
|
1020
955
|
const direction = useFlashOnChange(value, enabled, identity);
|
|
1021
|
-
return /* @__PURE__ */
|
|
956
|
+
return /* @__PURE__ */ jsx4("span", { style: { color: baseColor, ...style, ...flashTextStyle(direction) }, children: formatValue(value, precision) });
|
|
1022
957
|
}
|
|
1023
958
|
|
|
1024
959
|
// src/index.ts
|
|
@@ -1047,6 +982,7 @@ export {
|
|
|
1047
982
|
StaleBadge,
|
|
1048
983
|
WidgetCandidatesProvider,
|
|
1049
984
|
WidgetCatalogError2 as WidgetCatalogError,
|
|
985
|
+
WidgetDeclaredMetricsProvider,
|
|
1050
986
|
WidgetDensityProvider,
|
|
1051
987
|
WidgetFrame,
|
|
1052
988
|
WidgetFrameStyleProvider,
|
|
@@ -1113,6 +1049,7 @@ export {
|
|
|
1113
1049
|
useSlotCandidates,
|
|
1114
1050
|
useStickyChars,
|
|
1115
1051
|
useWidgetCandidates,
|
|
1052
|
+
useWidgetDeclaredMetrics,
|
|
1116
1053
|
useWidgetFrameStyle,
|
|
1117
1054
|
useWidgetFreshness,
|
|
1118
1055
|
useWidgetScale,
|