@modelform/react-native 0.0.0-stage → 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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/chunk-L4SQVIJV.js +10630 -0
  4. package/dist/chunk-PIHXMZ4G.mjs +10630 -0
  5. package/dist/core/configSchema.d.ts +29 -0
  6. package/dist/core/dashboardSettings.d.ts +34 -0
  7. package/dist/core/datasource.d.ts +61 -0
  8. package/dist/core/documents.d.ts +35 -0
  9. package/dist/core/editing.d.ts +129 -0
  10. package/dist/core/fieldconfig.d.ts +12 -0
  11. package/dist/core/format.d.ts +29 -0
  12. package/dist/core/frame.d.ts +51 -0
  13. package/dist/core/gazetteer.d.ts +25 -0
  14. package/dist/core/grafana.d.ts +85 -0
  15. package/dist/core/index.d.ts +27 -0
  16. package/dist/core/index.js +380 -0
  17. package/dist/core/index.mjs +380 -0
  18. package/dist/core/inputs.d.ts +99 -0
  19. package/dist/core/jsonEdit.d.ts +30 -0
  20. package/dist/core/layout.d.ts +49 -0
  21. package/dist/core/layoutEdit.d.ts +87 -0
  22. package/dist/core/links.d.ts +56 -0
  23. package/dist/core/local.d.ts +95 -0
  24. package/dist/core/manifest.d.ts +201 -0
  25. package/dist/core/mappings.d.ts +46 -0
  26. package/dist/core/navigation.d.ts +19 -0
  27. package/dist/core/panelOptions.d.ts +109 -0
  28. package/dist/core/reduce.d.ts +6 -0
  29. package/dist/core/resolveVariables.d.ts +38 -0
  30. package/dist/core/sample.d.ts +13 -0
  31. package/dist/core/schema.d.ts +202 -0
  32. package/dist/core/time.d.ts +66 -0
  33. package/dist/core/transform.d.ts +12 -0
  34. package/dist/core/variables.d.ts +76 -0
  35. package/dist/index.d.ts +11 -0
  36. package/dist/index.js +4156 -0
  37. package/dist/index.mjs +4156 -0
  38. package/dist/ui/Chip.d.ts +5 -0
  39. package/dist/ui/DashboardView.d.ts +22 -0
  40. package/dist/ui/RenderBoundary.d.ts +25 -0
  41. package/dist/ui/TimeRangeSheet.d.ts +24 -0
  42. package/dist/ui/Toolbar.d.ts +6 -0
  43. package/dist/ui/chart.d.ts +69 -0
  44. package/dist/ui/context.d.ts +68 -0
  45. package/dist/ui/geomap.d.ts +157 -0
  46. package/dist/ui/inputs/InputForm.d.ts +36 -0
  47. package/dist/ui/inputs/InputPanels.d.ts +4 -0
  48. package/dist/ui/inputs/formContext.d.ts +14 -0
  49. package/dist/ui/links.d.ts +28 -0
  50. package/dist/ui/panels/GaugePanels.d.ts +5 -0
  51. package/dist/ui/panels/GeomapPanel.d.ts +6 -0
  52. package/dist/ui/panels/OtherPanels.d.ts +18 -0
  53. package/dist/ui/panels/StatPanel.d.ts +14 -0
  54. package/dist/ui/panels/TimeSeriesPanel.d.ts +8 -0
  55. package/dist/ui/panels/XYChartPanel.d.ts +6 -0
  56. package/dist/ui/panels/common.d.ts +78 -0
  57. package/dist/ui/panels/registry.d.ts +5 -0
  58. package/dist/ui/table.d.ts +62 -0
  59. package/dist/ui/theme.d.ts +21 -0
  60. package/dist/ui/xychart.d.ts +27 -0
  61. package/package.json +89 -3
  62. package/schema/app.schema.json +184 -0
  63. package/schema/dashboard.schema.json +940 -0
  64. package/tools/dashboards.js +90 -0
  65. package/tools/metro.js +21 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * The subset of the Grafana dashboard JSON model that modelform understands.
3
+ * Unknown keys are tolerated and ignored, so dashboards exported from Grafana
4
+ * load as-is. See https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/view-dashboard-json-model/
5
+ *
6
+ * modelform adds two extensions, both of which Grafana ignores:
7
+ * - `panel.mobile` to tune phone layout per panel
8
+ * - `input-*` panel types for data entry forms (see inputs.ts)
9
+ */
10
+ export interface Dashboard {
11
+ uid?: string;
12
+ title: string;
13
+ description?: string;
14
+ tags?: string[];
15
+ panels: Panel[];
16
+ templating?: {
17
+ list: TemplateVariable[];
18
+ };
19
+ time?: {
20
+ from: string;
21
+ to: string;
22
+ };
23
+ /** "browser" (the default), "utc", or an IANA zone such as "Europe/London". */
24
+ timezone?: string;
25
+ refresh?: string | false;
26
+ /** Present on dashboards exported "for sharing externally". */
27
+ __inputs?: {
28
+ name: string;
29
+ type: string;
30
+ pluginId?: string;
31
+ }[];
32
+ }
33
+ export interface GridPos {
34
+ x: number;
35
+ y: number;
36
+ w: number;
37
+ h: number;
38
+ }
39
+ export interface DataSourceRef {
40
+ type?: string;
41
+ uid?: string;
42
+ }
43
+ /** A panel query. Everything besides refId/datasource is datasource-specific and passed through untouched. */
44
+ export interface Target {
45
+ refId: string;
46
+ datasource?: DataSourceRef | string | null;
47
+ hide?: boolean;
48
+ /** The local datasource's metric (see LocalTarget). Typed here so a config can't give it something else. */
49
+ metric?: string;
50
+ /** Display name for the series. */
51
+ alias?: string;
52
+ [key: string]: unknown;
53
+ }
54
+ export interface ThresholdStep {
55
+ value: number | null;
56
+ color: string;
57
+ }
58
+ export interface FieldConfig {
59
+ unit?: string;
60
+ min?: number;
61
+ max?: number;
62
+ decimals?: number;
63
+ displayName?: string;
64
+ color?: {
65
+ mode?: string;
66
+ fixedColor?: string;
67
+ };
68
+ thresholds?: {
69
+ mode?: 'absolute' | 'percentage';
70
+ steps: ThresholdStep[];
71
+ };
72
+ mappings?: ValueMapping[];
73
+ /** Data links: opened from a point, cell or value of this field. */
74
+ links?: DataLink[];
75
+ custom?: {
76
+ drawStyle?: 'line' | 'bars' | 'points';
77
+ lineWidth?: number;
78
+ fillOpacity?: number;
79
+ showPoints?: 'auto' | 'always' | 'never';
80
+ [key: string]: unknown;
81
+ };
82
+ [key: string]: unknown;
83
+ }
84
+ /** A Grafana data link or panel link. `url` may use variables and, for data links, `${__value.raw}`-style macros. */
85
+ export interface DataLink {
86
+ title: string;
87
+ url: string;
88
+ targetBlank?: boolean;
89
+ }
90
+ /** Grafana value mappings: display text (and optionally a color) in place of a value. */
91
+ export type ValueMapping = {
92
+ type: 'value';
93
+ options: Record<string, MappingResult>;
94
+ } | {
95
+ type: 'range';
96
+ options: {
97
+ from?: number | null;
98
+ to?: number | null;
99
+ result: MappingResult;
100
+ };
101
+ } | {
102
+ type: 'regex';
103
+ options: {
104
+ pattern: string;
105
+ result: MappingResult;
106
+ };
107
+ } | {
108
+ type: 'special';
109
+ options: {
110
+ match: 'null' | 'nan' | 'null+nan' | 'true' | 'false' | 'empty';
111
+ result: MappingResult;
112
+ };
113
+ } | {
114
+ type: string;
115
+ options?: unknown;
116
+ };
117
+ export interface MappingResult {
118
+ text?: string;
119
+ color?: string;
120
+ index?: number;
121
+ }
122
+ export interface FieldOverride {
123
+ matcher: {
124
+ id: string;
125
+ options?: unknown;
126
+ };
127
+ properties: {
128
+ id: string;
129
+ value?: unknown;
130
+ }[];
131
+ }
132
+ /** modelform extension: how a panel behaves on a narrow screen. */
133
+ export interface MobileOptions {
134
+ /** Columns out of 24 on a phone. Defaults: w <= 6 → 12 (two-up), otherwise 24. */
135
+ span?: number;
136
+ /** Height in grid units (Grafana units are 30px). Defaults to gridPos.h. */
137
+ h?: number;
138
+ hidden?: boolean;
139
+ }
140
+ export interface Panel {
141
+ id?: number;
142
+ type: string;
143
+ title?: string;
144
+ description?: string;
145
+ gridPos: GridPos;
146
+ datasource?: DataSourceRef | string | null;
147
+ targets?: Target[];
148
+ fieldConfig?: {
149
+ defaults?: FieldConfig;
150
+ overrides?: FieldOverride[];
151
+ };
152
+ options?: Record<string, any>;
153
+ /** Applied in order to the query results. See transform.ts for the ones modelform implements. */
154
+ transformations?: {
155
+ id: string;
156
+ options?: Record<string, any>;
157
+ disabled?: boolean;
158
+ }[];
159
+ /** Rows only. */
160
+ collapsed?: boolean;
161
+ /** Rows only: children of a collapsed row live here instead of at the top level. */
162
+ panels?: Panel[];
163
+ /** Repeat this row (or panel) once per selected value of the named variable. */
164
+ repeat?: string;
165
+ /** Panel repeats: side by side (`h`, wrapping at maxPerRow) or stacked (`v`). */
166
+ repeatDirection?: 'h' | 'v';
167
+ maxPerRow?: number;
168
+ /** Set on each copy of a repeated row or panel: the single value it was repeated for. */
169
+ scopedVars?: Record<string, {
170
+ text: string;
171
+ value: string;
172
+ }>;
173
+ mobile?: MobileOptions;
174
+ /** Panel links, from the panel header menu in Grafana. */
175
+ links?: DataLink[];
176
+ [key: string]: unknown;
177
+ }
178
+ export interface VariableOption {
179
+ text: string | string[];
180
+ value: string | string[];
181
+ selected?: boolean;
182
+ }
183
+ export interface TemplateVariable {
184
+ name: string;
185
+ type: 'query' | 'custom' | 'constant' | 'textbox' | 'interval' | 'datasource' | 'adhoc' | string;
186
+ label?: string;
187
+ hide?: number;
188
+ query?: unknown;
189
+ current?: Partial<VariableOption>;
190
+ options?: VariableOption[];
191
+ multi?: boolean;
192
+ includeAll?: boolean;
193
+ allValue?: string | null;
194
+ /** Query variables: where the options come from. */
195
+ datasource?: DataSourceRef | string | null;
196
+ /** Query variables: 0/missing = never, 1 = on dashboard load, 2 = on time range change. */
197
+ refresh?: number;
198
+ /** Query variables: `/pattern/flags` applied to each option's text. */
199
+ regex?: string;
200
+ /** Query variables: 0 = query order, 1/2 = alpha, 3/4 = numeric, 5/6 = alpha ignoring case, 7/8 = natural. Odd ascending. */
201
+ sort?: number;
202
+ }
@@ -0,0 +1,66 @@
1
+ /** Grafana-style relative time parsing: "now", "now-6h", "now-1d/d", "now/w", or absolute ISO/epoch-ms. */
2
+ export interface TimeRange {
3
+ from: number;
4
+ to: number;
5
+ raw: {
6
+ from: string;
7
+ to: string;
8
+ };
9
+ }
10
+ export type TimeUnit = 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y';
11
+ export declare function parseTime(expr: string, now?: number, roundUp?: boolean): number;
12
+ export declare function parseRange(raw: {
13
+ from: string;
14
+ to: string;
15
+ }, now?: number): TimeRange;
16
+ export declare function addTime(d: Date, n: number, unit: TimeUnit): Date;
17
+ /** Round down to the start of the unit (local time), or to its last millisecond when roundUp. */
18
+ export declare function startOf(d: Date, unit: TimeUnit, roundUp?: boolean): Date;
19
+ /** "5m" → 300000. Accepts Grafana interval strings including ms. */
20
+ export declare function parseDuration(s: string): number;
21
+ /** Pick a query interval the way Grafana does: range / maxDataPoints, snapped to a nice value. */
22
+ export declare function calculateInterval(range: TimeRange, maxDataPoints: number, minIntervalMs?: number): number;
23
+ export declare function formatDuration(ms: number): string;
24
+ export declare const TIME_PRESETS: {
25
+ label: string;
26
+ from: string;
27
+ to: string;
28
+ }[];
29
+ /** More relative ranges for the custom range picker, beyond the quick presets. */
30
+ export declare const RELATIVE_RANGES: {
31
+ label: string;
32
+ from: string;
33
+ to: string;
34
+ }[];
35
+ /**
36
+ * "2026-03-01", "2026-03-01 14:00" or "2026-03-01T14:00:05" as local time. Date.parse would read a
37
+ * bare date as UTC midnight, which lands on the previous day west of Greenwich.
38
+ */
39
+ export declare function parseLocalDateTime(s: string): number | null;
40
+ /** Local "YYYY-MM-DD HH:mm:ss", the form the range picker shows and parseLocalDateTime reads back. */
41
+ export declare function formatLocalDateTime(ms: number): string;
42
+ /** An error message for a time expression the range picker can't use, or null if it parses. */
43
+ export declare function timeExprError(expr: string): string | null;
44
+ /** A short label for a range: the preset or relative range it matches, else "Mar 1 – Mar 5, 2026" style. */
45
+ export declare function describeRange(raw: {
46
+ from: string;
47
+ to: string;
48
+ }, now?: number): string;
49
+ /**
50
+ * The range a pinch on an x axis shows. `startFrac`/`frac` are where the fingers' midpoint sat across
51
+ * the plot (0–1) when the pinch began and now; the value under it stays under it, so moving both
52
+ * fingers pans as well. `scale` > 1 spreads the fingers to zoom in. The result stays within
53
+ * [minFrom, maxTo] where it fits.
54
+ */
55
+ export declare function zoomRange(start: {
56
+ from: number;
57
+ to: number;
58
+ }, scale: number, startFrac: number, frac: number, { minSpan, maxSpan, minFrom, maxTo, }?: {
59
+ minSpan?: number;
60
+ maxSpan?: number;
61
+ minFrom?: number;
62
+ maxTo?: number;
63
+ }): {
64
+ from: number;
65
+ to: number;
66
+ };
@@ -0,0 +1,12 @@
1
+ import { type DataFrame } from './frame';
2
+ /** A panel's `transformations` entry. */
3
+ export interface Transformation {
4
+ id: string;
5
+ options?: Record<string, any>;
6
+ disabled?: boolean;
7
+ }
8
+ /**
9
+ * Applies a panel's transformations in order. Ones modelform doesn't implement are skipped,
10
+ * so their panels render the untransformed data as they did before transformations were supported.
11
+ */
12
+ export declare function applyTransformations(frames: DataFrame[], transformations: Transformation[] | undefined): DataFrame[];
@@ -0,0 +1,76 @@
1
+ import type { DataFrame } from './frame';
2
+ import type { Dashboard, TemplateVariable } from './schema';
3
+ import type { TimeRange } from './time';
4
+ /**
5
+ * Dashboard template variables. The current selection saved in the JSON is the starting
6
+ * value. Options for custom/interval variables are read from the JSON; query variables are
7
+ * re-run against their datasource by resolveVariables (see resolveVariables.ts), and until
8
+ * then (or for datasources that can't run them) offer the options saved in the JSON.
9
+ */
10
+ export type VariableValues = Record<string, string | string[]>;
11
+ export interface VarOption {
12
+ text: string;
13
+ value: string;
14
+ }
15
+ /** What interpolation needs to know about a variable beyond its value. */
16
+ export interface VariableInfo {
17
+ multi?: boolean;
18
+ includeAll?: boolean;
19
+ allValue?: string | null;
20
+ /** Never includes the synthetic All option. */
21
+ options: VarOption[];
22
+ }
23
+ export declare const ALL = "$__all";
24
+ /** Per-variable single values, as Grafana gives each copy of a repeated row or panel. */
25
+ export type ScopedVars = Record<string, VarOption>;
26
+ export declare function initialVariableValues(dashboard: Dashboard): VariableValues;
27
+ export declare function variableOptions(v: TemplateVariable): VarOption[];
28
+ /** Per-variable info for interpolation, preferring `resolved` options over the ones saved in the JSON. */
29
+ export declare function variableInfo(dashboard: Dashboard, resolved?: Record<string, VarOption[]>): Record<string, VariableInfo>;
30
+ export declare function visibleVariables(dashboard: Dashboard): TemplateVariable[];
31
+ /** Datasources whose queries take multi-value variables as a quoted list, `'a','b'`, by default. */
32
+ export declare const isSqlDatasource: (type: string | undefined) => boolean;
33
+ /** Turn a variable query's result into options, using Grafana's SQL convention of `__text`/`__value` columns. */
34
+ export declare function framesToOptions(frames: DataFrame[]): VarOption[];
35
+ /** Apply a query variable's `regex` and `sort`, and drop duplicate values, as Grafana does. */
36
+ export declare function refineOptions(v: TemplateVariable, options: VarOption[]): VarOption[];
37
+ /**
38
+ * Grafana's selection rules after a variable's options change: keep the current value if it's
39
+ * still an option (for multi-value, keep whichever still are), keep All, otherwise take the first
40
+ * option, which is All when the variable includes it.
41
+ */
42
+ export declare function selectValue(v: TemplateVariable, current: string | string[] | undefined, options: VarOption[]): string | string[];
43
+ /** Names of the other variables a variable's query refers to. */
44
+ export declare function variableReferences(v: TemplateVariable, names: Iterable<string>): string[];
45
+ interface InterpolateContext {
46
+ values: VariableValues;
47
+ /** Needed to expand All and for `:text`; without it All becomes `.*`. */
48
+ info?: Record<string, VariableInfo>;
49
+ /** Datasource type of the query being interpolated; picks the default multi-value format. */
50
+ datasourceType?: string;
51
+ /** Single values that override `values` inside a repeated row or panel. */
52
+ scoped?: ScopedVars;
53
+ range?: TimeRange;
54
+ intervalMs?: number;
55
+ /** The dashboard's `timezone` setting, for `$__timezone`. Missing or "browser" means the device's zone. */
56
+ timezone?: string;
57
+ /** Percent-encode substituted values, as Grafana does in links. `:raw` and `:queryparam` opt out. */
58
+ urlEncode?: boolean;
59
+ }
60
+ /**
61
+ * Replace $var, ${var}, ${var:format} and [[var]] in a string. Built-ins that Grafana resolves
62
+ * in the browser ($__interval, $__range, ...) are filled in too; anything unknown is left as-is.
63
+ */
64
+ export declare function interpolate(text: string, ctx: InterpolateContext): string;
65
+ /** Grafana's `:queryparam` format: `var-name=a&var-name=b`, which is also how dashboard URLs carry variables. */
66
+ export declare function queryParam(name: string, value: string | string[]): string;
67
+ /** Deep-interpolate every string inside a query target. */
68
+ export declare function interpolateDeep<T>(value: T, ctx: InterpolateContext): T;
69
+ /**
70
+ * What Grafana puts in `$__timezone`: "utc" for UTC, else an IANA zone name. "browser" (Grafana's default) and
71
+ * an empty setting mean the device's own zone.
72
+ */
73
+ export declare function resolveTimezone(setting: string | undefined): string;
74
+ /** The label to show for a variable's current value. */
75
+ export declare function valueText(value: string | string[] | undefined, info: VariableInfo | undefined): string;
76
+ export {};
@@ -0,0 +1,11 @@
1
+ export * from './core';
2
+ export { DashThemeProvider, useDashTheme, lightTheme, darkTheme, type DashTheme } from './ui/theme';
3
+ export { DashboardProvider, useDashboard, usePanelData, type DashboardProviderProps, type PanelData } from './ui/context';
4
+ export { DashboardView, PanelCard, type DashboardViewProps } from './ui/DashboardView';
5
+ export { RenderBoundary } from './ui/RenderBoundary';
6
+ export { DashboardToolbar, Chip } from './ui/Toolbar';
7
+ export { InputForm, type InputFormProps } from './ui/inputs/InputForm';
8
+ export { Calendar } from './ui/TimeRangeSheet';
9
+ export { InputFormContext, useInputForm, type InputFormState } from './ui/inputs/formContext';
10
+ export { registerPanel } from './ui/panels/registry';
11
+ export { Legend, NoData, type PanelProps } from './ui/panels/common';