@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,380 @@
1
+ import {
2
+ ALL,
3
+ BUNDLE_ACCEPT,
4
+ BUNDLE_TYPE,
5
+ CANVAS_GAP,
6
+ CANVAS_ROW_HEADER,
7
+ ConfigLoader,
8
+ DASHBOARD_DS,
9
+ DEFAULT_GAZETTEER,
10
+ EDITABLE_VARIABLE_TYPES,
11
+ GRID_COLUMNS,
12
+ GrafanaClient,
13
+ GrafanaDataSource,
14
+ GrafanaError,
15
+ HttpConfigFiles,
16
+ INPUT_OPTION_KEYS,
17
+ INPUT_TYPES,
18
+ LOCAL_DATASOURCE_TYPE,
19
+ LocalDataSource,
20
+ MANIFEST_VERSION,
21
+ MAPPING_TYPES,
22
+ MemoryEntryStore,
23
+ NAMED_COLORS,
24
+ OPTION_CATEGORIES,
25
+ OVERRIDE_MATCHERS,
26
+ PANEL_TYPES,
27
+ REDUCER_LABELS,
28
+ REFRESH_CHOICES,
29
+ RELATIVE_RANGES,
30
+ SERIES_PALETTE,
31
+ SPECIAL_MATCHES,
32
+ SaveConflictError,
33
+ TIME_PRESETS,
34
+ UNIT_CHOICES,
35
+ addTime,
36
+ appSchema,
37
+ applyDashboardLink,
38
+ applyJsonEdits,
39
+ applyTransformations,
40
+ assembleBundle,
41
+ assembleFromResponse,
42
+ buildFrames,
43
+ bundleFromFiles,
44
+ bundleRoot,
45
+ calculateInterval,
46
+ checkFiles,
47
+ cleanDashboard,
48
+ cleanPanelOptions,
49
+ dashboardSchema,
50
+ dashboardSchemaIssues,
51
+ dashboardSourceIds,
52
+ defaultFetchJson,
53
+ describeRange,
54
+ diffJson,
55
+ documentIdFor,
56
+ documentUses,
57
+ dropTarget,
58
+ duplicatePanel,
59
+ entriesSavedWith,
60
+ entryToInputValue,
61
+ expandRow,
62
+ fetchBundle,
63
+ fetchJsonWithToken,
64
+ fieldDisplayName,
65
+ fieldMatches,
66
+ formatClock,
67
+ formatDisplay,
68
+ formatDuration,
69
+ formatJsonText,
70
+ formatLocalDateTime,
71
+ formatValue,
72
+ frameLength,
73
+ framesToOptions,
74
+ fromWire,
75
+ getPath,
76
+ gridUnitsToPx,
77
+ initialVariableValues,
78
+ inputPanels,
79
+ inputProblem,
80
+ insertPanel,
81
+ interpolate,
82
+ interpolateDeep,
83
+ isBundleResponse,
84
+ isEditableVariableType,
85
+ isInputPanel,
86
+ isInputType,
87
+ isLocalDatasource,
88
+ isReducer,
89
+ isRow,
90
+ isSqlDatasource,
91
+ layoutCanvas,
92
+ layoutDashboard,
93
+ lineColumn,
94
+ loadGazetteer,
95
+ locate,
96
+ manifestSchemaIssues,
97
+ mappedResult,
98
+ mappingProblem,
99
+ mappingRow,
100
+ mappingRows,
101
+ metricChanges,
102
+ movePanel,
103
+ newDocument,
104
+ newPanel,
105
+ newVariable,
106
+ nextPanelId,
107
+ normalizeRef,
108
+ numberFields,
109
+ optionValue,
110
+ overrideProperties,
111
+ panelEdits,
112
+ panelHasQueries,
113
+ panelKey,
114
+ panelOptions,
115
+ panelOverrides,
116
+ panelSize,
117
+ panelSpan,
118
+ parseClockDigits,
119
+ parseDashboardLink,
120
+ parseDuration,
121
+ parseGazetteer,
122
+ parseJsonText,
123
+ parseLocalDateTime,
124
+ parseRange,
125
+ parseTime,
126
+ pointerToPath,
127
+ prepareDashboard,
128
+ queryPanel,
129
+ queryParam,
130
+ readConfigFiles,
131
+ readingOrder,
132
+ reduce,
133
+ refineOptions,
134
+ refreshedVariables,
135
+ removeDocumentFromManifest,
136
+ removePanel,
137
+ renameDocumentInManifest,
138
+ renameVariableInPanels,
139
+ repack,
140
+ repeatOptions,
141
+ resizePanel,
142
+ resolveColor,
143
+ resolveFieldConfig,
144
+ resolveLinks,
145
+ resolveTimezone,
146
+ resolveUrl,
147
+ resolveVariables,
148
+ rowsToMappings,
149
+ sampleEntries,
150
+ screenDocuments,
151
+ screenOfType,
152
+ selectValue,
153
+ seriesColor,
154
+ setHiddenOnPhones,
155
+ setJsonValue,
156
+ setOption,
157
+ setOptionValue,
158
+ setOverrides,
159
+ splitPath,
160
+ startOf,
161
+ stringifyCompact,
162
+ tabIdFor,
163
+ textSuggestions,
164
+ thresholdStep,
165
+ timeExprError,
166
+ timeField,
167
+ toEntries,
168
+ toMillis,
169
+ toSeries,
170
+ toXYSeries,
171
+ uniqueNames,
172
+ validateBundle,
173
+ validateDashboard,
174
+ validateManifest,
175
+ valueColor,
176
+ valueText,
177
+ variableDependents,
178
+ variableInfo,
179
+ variableNameError,
180
+ variableOptions,
181
+ variableOrder,
182
+ variableReferences,
183
+ variableUses,
184
+ variableWithCurrent,
185
+ variableWithFlags,
186
+ variableWithQuery,
187
+ variableWithType,
188
+ visibleVariables,
189
+ zoomRange
190
+ } from "../chunk-PIHXMZ4G.mjs";
191
+ export {
192
+ ALL,
193
+ BUNDLE_ACCEPT,
194
+ BUNDLE_TYPE,
195
+ CANVAS_GAP,
196
+ CANVAS_ROW_HEADER,
197
+ ConfigLoader,
198
+ DASHBOARD_DS,
199
+ DEFAULT_GAZETTEER,
200
+ EDITABLE_VARIABLE_TYPES,
201
+ GRID_COLUMNS,
202
+ GrafanaClient,
203
+ GrafanaDataSource,
204
+ GrafanaError,
205
+ HttpConfigFiles,
206
+ INPUT_OPTION_KEYS,
207
+ INPUT_TYPES,
208
+ LOCAL_DATASOURCE_TYPE,
209
+ LocalDataSource,
210
+ MANIFEST_VERSION,
211
+ MAPPING_TYPES,
212
+ MemoryEntryStore,
213
+ NAMED_COLORS,
214
+ OPTION_CATEGORIES,
215
+ OVERRIDE_MATCHERS,
216
+ PANEL_TYPES,
217
+ REDUCER_LABELS,
218
+ REFRESH_CHOICES,
219
+ RELATIVE_RANGES,
220
+ SERIES_PALETTE,
221
+ SPECIAL_MATCHES,
222
+ SaveConflictError,
223
+ TIME_PRESETS,
224
+ UNIT_CHOICES,
225
+ addTime,
226
+ appSchema,
227
+ applyDashboardLink,
228
+ applyJsonEdits,
229
+ applyTransformations,
230
+ assembleBundle,
231
+ assembleFromResponse,
232
+ buildFrames,
233
+ bundleFromFiles,
234
+ bundleRoot,
235
+ calculateInterval,
236
+ checkFiles,
237
+ cleanDashboard,
238
+ cleanPanelOptions,
239
+ dashboardSchema,
240
+ dashboardSchemaIssues,
241
+ dashboardSourceIds,
242
+ defaultFetchJson,
243
+ describeRange,
244
+ diffJson,
245
+ documentIdFor,
246
+ documentUses,
247
+ dropTarget,
248
+ duplicatePanel,
249
+ entriesSavedWith,
250
+ entryToInputValue,
251
+ expandRow,
252
+ fetchBundle,
253
+ fetchJsonWithToken,
254
+ fieldDisplayName,
255
+ fieldMatches,
256
+ formatClock,
257
+ formatDisplay,
258
+ formatDuration,
259
+ formatJsonText,
260
+ formatLocalDateTime,
261
+ formatValue,
262
+ frameLength,
263
+ framesToOptions,
264
+ fromWire,
265
+ getPath,
266
+ gridUnitsToPx,
267
+ initialVariableValues,
268
+ inputPanels,
269
+ inputProblem,
270
+ insertPanel,
271
+ interpolate,
272
+ interpolateDeep,
273
+ isBundleResponse,
274
+ isEditableVariableType,
275
+ isInputPanel,
276
+ isInputType,
277
+ isLocalDatasource,
278
+ isReducer,
279
+ isRow,
280
+ isSqlDatasource,
281
+ layoutCanvas,
282
+ layoutDashboard,
283
+ lineColumn,
284
+ loadGazetteer,
285
+ locate,
286
+ manifestSchemaIssues,
287
+ mappedResult,
288
+ mappingProblem,
289
+ mappingRow,
290
+ mappingRows,
291
+ metricChanges,
292
+ movePanel,
293
+ newDocument,
294
+ newPanel,
295
+ newVariable,
296
+ nextPanelId,
297
+ normalizeRef,
298
+ numberFields,
299
+ optionValue,
300
+ overrideProperties,
301
+ panelEdits,
302
+ panelHasQueries,
303
+ panelKey,
304
+ panelOptions,
305
+ panelOverrides,
306
+ panelSize,
307
+ panelSpan,
308
+ parseClockDigits,
309
+ parseDashboardLink,
310
+ parseDuration,
311
+ parseGazetteer,
312
+ parseJsonText,
313
+ parseLocalDateTime,
314
+ parseRange,
315
+ parseTime,
316
+ pointerToPath,
317
+ prepareDashboard,
318
+ queryPanel,
319
+ queryParam,
320
+ readConfigFiles,
321
+ readingOrder,
322
+ reduce,
323
+ refineOptions,
324
+ refreshedVariables,
325
+ removeDocumentFromManifest,
326
+ removePanel,
327
+ renameDocumentInManifest,
328
+ renameVariableInPanels,
329
+ repack,
330
+ repeatOptions,
331
+ resizePanel,
332
+ resolveColor,
333
+ resolveFieldConfig,
334
+ resolveLinks,
335
+ resolveTimezone,
336
+ resolveUrl,
337
+ resolveVariables,
338
+ rowsToMappings,
339
+ sampleEntries,
340
+ screenDocuments,
341
+ screenOfType,
342
+ selectValue,
343
+ seriesColor,
344
+ setHiddenOnPhones,
345
+ setJsonValue,
346
+ setOption,
347
+ setOptionValue,
348
+ setOverrides,
349
+ splitPath,
350
+ startOf,
351
+ stringifyCompact,
352
+ tabIdFor,
353
+ textSuggestions,
354
+ thresholdStep,
355
+ timeExprError,
356
+ timeField,
357
+ toEntries,
358
+ toMillis,
359
+ toSeries,
360
+ toXYSeries,
361
+ uniqueNames,
362
+ validateBundle,
363
+ validateDashboard,
364
+ validateManifest,
365
+ valueColor,
366
+ valueText,
367
+ variableDependents,
368
+ variableInfo,
369
+ variableNameError,
370
+ variableOptions,
371
+ variableOrder,
372
+ variableReferences,
373
+ variableUses,
374
+ variableWithCurrent,
375
+ variableWithFlags,
376
+ variableWithQuery,
377
+ variableWithType,
378
+ visibleVariables,
379
+ zoomRange
380
+ };
@@ -0,0 +1,99 @@
1
+ import type { Dashboard, Panel } from './schema';
2
+ /**
3
+ * Input forms reuse the dashboard format: a form is a dashboard whose panels have
4
+ * `input-*` types. Layout, rows and gridPos work exactly like visualization panels,
5
+ * so one layout engine (and one hot-reloadable JSON file) drives both tabs.
6
+ *
7
+ * { "type": "input-number", "title": "Weight", "gridPos": {"x":0,"y":0,"w":12,"h":3},
8
+ * "options": { "metric": "weight", "unit": "kg", "step": 0.1, "default": "last" } }
9
+ */
10
+ export type InputType = 'input-number' | 'input-slider' | 'input-select' | 'input-toggle' | 'input-rating' | 'input-text' | 'input-counter' | 'input-duration';
11
+ export interface InputChoice {
12
+ label: string;
13
+ value: number | string;
14
+ }
15
+ export interface InputOptions {
16
+ /** The metric this input records to. Visualization queries select data by this name. */
17
+ metric: string;
18
+ unit?: string;
19
+ min?: number;
20
+ max?: number;
21
+ step?: number;
22
+ placeholder?: string;
23
+ /**
24
+ * input-slider only: text spaced evenly along the track, first at min and last at max,
25
+ * e.g. ["Understeer", "Neutral", "Oversteer"]. Replaces the numeric min/max labels.
26
+ */
27
+ labels?: string[];
28
+ /** Initial value: a literal, or "last" to start from the most recent entry. */
29
+ default?: number | string | boolean | 'last';
30
+ /**
31
+ * "changed" (the default) records the value only when it was edited before Save;
32
+ * "always" records it on every Save, so a default like "last" is kept with each save.
33
+ */
34
+ record?: 'changed' | 'always';
35
+ /** Save waits until this has a value. */
36
+ required?: boolean;
37
+ /** input-select only. */
38
+ choices?: InputChoice[];
39
+ /**
40
+ * input-select only: take the choices from the app at runtime instead of `choices`,
41
+ * for lists that live in app data (e.g. wheel sets). Names a key of InputForm's `choices` prop.
42
+ */
43
+ choicesFrom?: string;
44
+ /** input-select only: allow selecting several. Each selection is recorded as its own entry. */
45
+ multi?: boolean;
46
+ /** input-counter only: the amount each tap records (default 1). */
47
+ increment?: number;
48
+ /** input-text only: a single-line field that suggests values recorded earlier, matching what's typed. */
49
+ suggest?: boolean;
50
+ /**
51
+ * input-text with `suggest` only: another input's metric whose current value narrows the
52
+ * suggestions to values saved alongside it (e.g. configurations of the chosen track).
53
+ * Falls back to every earlier value when none were.
54
+ */
55
+ suggestWith?: string;
56
+ }
57
+ /** The options each input type reads, for editors to offer. */
58
+ export declare const INPUT_OPTION_KEYS: Record<InputType, (keyof InputOptions)[]>;
59
+ export declare const INPUT_TYPES: InputType[];
60
+ export declare const isInputType: (type: string) => type is InputType;
61
+ export type InputPanel = Panel & {
62
+ type: InputType;
63
+ options: InputOptions;
64
+ };
65
+ export declare const isInputPanel: (p: Panel) => p is InputPanel;
66
+ export declare function inputPanels(dashboard: Dashboard): InputPanel[];
67
+ /**
68
+ * input-duration: lap-timer style MM:SS.hh. Digits fill from the right as they're typed,
69
+ * so "13245" reads 01:32.45, which is recorded as 92.45 seconds.
70
+ */
71
+ export declare function parseClockDigits(digits: string): number | null;
72
+ /** Seconds → MM:SS.hh (minutes widen past 99). */
73
+ export declare function formatClock(seconds: number): string;
74
+ /** A form value as held by the UI before saving. */
75
+ export type InputValue = number | string | boolean | (number | string)[] | null;
76
+ /** One recorded data point. `value` holds numbers (and booleans as 0/1); `text` holds free text and string choices. */
77
+ export interface Entry {
78
+ id: string;
79
+ metric: string;
80
+ ts: number;
81
+ value: number | null;
82
+ text: string | null;
83
+ }
84
+ export type NewEntry = Omit<Entry, 'id'>;
85
+ export declare function toEntries(panel: InputPanel, value: InputValue, ts: number): NewEntry[];
86
+ /** Why a value can't be saved as it is: empty when required, or outside a number input's min and max. */
87
+ export declare function inputProblem(panel: InputPanel, value: InputValue): string | undefined;
88
+ export declare function entryToInputValue(panel: InputPanel, entry: Entry | undefined): InputValue;
89
+ /**
90
+ * Earlier text values worth offering for `query`, most recently used first, one per
91
+ * spelling (ignoring case). Matches words starting with the query; an empty query
92
+ * matches everything. Leaves out `query` itself once it's typed in full.
93
+ */
94
+ export declare function textSuggestions(entries: Entry[], query: string, limit?: number): string[];
95
+ /**
96
+ * Entries of `metric` saved together with (at the same time as) a `withMetric` entry
97
+ * whose text is `withText`, ignoring case.
98
+ */
99
+ export declare function entriesSavedWith(entries: Entry[], metric: string, withMetric: string, withText: string): Entry[];
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Small edits to JSON text that keep its formatting: change a value, add or remove a key or
3
+ * array element, everything else untouched. New values are written in the style config files
4
+ * use, with short objects like gridPos on one line.
5
+ */
6
+ import { type JSONPath } from 'jsonc-parser';
7
+ export type { JSONPath };
8
+ export interface JsonEdit {
9
+ path: JSONPath;
10
+ /** Set (or add) this value. Ignored when `remove` is set. */
11
+ value?: unknown;
12
+ /** Remove the key or array element at `path`. */
13
+ remove?: boolean;
14
+ /** `path` ends in an array index: insert there instead of replacing. */
15
+ insert?: boolean;
16
+ }
17
+ /**
18
+ * JSON with short objects and arrays on one line (`{ "x": 0, "y": 0 }`) and longer ones
19
+ * broken up, `indent` spaces in.
20
+ */
21
+ export declare function stringifyCompact(value: unknown, indent?: number): string;
22
+ /** Applies edits in order. Text that doesn't parse is returned unchanged. */
23
+ export declare function applyJsonEdits(text: string, edits: JsonEdit[]): string;
24
+ /**
25
+ * The smallest edits that turn `before` into `after`: changed leaves are set and keys added or
26
+ * removed. In arrays, elements that match at either end are kept, and between them elements
27
+ * are edited in place, then removed or inserted, so adding or removing one leaves the rest as
28
+ * they were written.
29
+ */
30
+ export declare function diffJson(before: unknown, after: unknown, path?: JSONPath): JsonEdit[];
@@ -0,0 +1,49 @@
1
+ import type { Dashboard, Panel } from './schema';
2
+ import { type VariableInfo, type VariableValues, type VarOption } from './variables';
3
+ /**
4
+ * Converts Grafana's 24-column absolute grid into rows that reflow on a phone.
5
+ *
6
+ * Grafana positions panels absolutely (gridPos x/y/w/h). A phone can't show that
7
+ * faithfully, so panels are taken in reading order (y, then x) and packed into
8
+ * rows. In "phone" mode small panels (w <= 6, e.g. stat tiles) go two-up and
9
+ * everything else is full width; `panel.mobile` overrides either. In "grid"
10
+ * mode (tablets) the original widths are kept.
11
+ *
12
+ * Repeated rows and panels are expanded here, one copy per selected value of
13
+ * their `repeat` variable, each carrying that value in `scopedVars`.
14
+ */
15
+ export declare const GRID_COLUMNS = 24;
16
+ export type LayoutMode = 'phone' | 'grid';
17
+ export interface LayoutCell {
18
+ /** Unique across the layout, including copies of a repeated panel. */
19
+ key: string;
20
+ panel: Panel;
21
+ /** Columns out of 24. */
22
+ span: number;
23
+ }
24
+ export interface LayoutRow {
25
+ cells: LayoutCell[];
26
+ /** Height in grid units. */
27
+ h: number;
28
+ }
29
+ export interface LayoutSection {
30
+ key: string;
31
+ /** The Grafana "row" panel heading this section, if any. */
32
+ row?: Panel;
33
+ collapsed: boolean;
34
+ rows: LayoutRow[];
35
+ }
36
+ /** Grafana's pixel height for h grid units. */
37
+ export declare const gridUnitsToPx: (h: number) => number;
38
+ export declare const isRow: (p: Panel) => boolean;
39
+ /** Current variable values and options; without them repeated rows and panels render once, unrepeated. */
40
+ export interface RepeatContext {
41
+ values: VariableValues;
42
+ info: Record<string, VariableInfo>;
43
+ }
44
+ export declare function layoutDashboard(dashboard: Dashboard, mode?: LayoutMode, repeat?: RepeatContext): LayoutSection[];
45
+ /** One option per selected value of `name`; every option when All is selected. */
46
+ export declare function repeatOptions(name: string, ctx: RepeatContext): VarOption[];
47
+ /** Stable key for a panel or row copy: its id plus the values it was repeated for. */
48
+ export declare function panelKey(panel: Panel): string;
49
+ export declare function panelSpan(panel: Panel, mode: LayoutMode): number;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The layout editor's model. modelform lays panels out in reading order, packed into lines by
3
+ * width (see layout.ts), so editing a layout is editing an order plus sizes: moving a panel
4
+ * changes where it falls in the order, and every gridPos x/y is then rewritten from that
5
+ * order so the file (and Grafana) agree with what the app shows.
6
+ *
7
+ * Panels are identified by their index in `dashboard.panels`, which edits keep stable (apart
8
+ * from removing one), so the JSON text can be patched in place.
9
+ */
10
+ import { type JsonEdit } from './jsonEdit';
11
+ import { type LayoutMode } from './layout';
12
+ import type { Panel } from './schema';
13
+ /** Top-level panel indices (rows included) in the order the app shows them; ties keep file order. */
14
+ export declare function readingOrder(panels: Panel[]): number[];
15
+ /**
16
+ * Rewrites gridPos x/y so that sorting by position gives `order`, packing each line by width
17
+ * the way the app does. Sizes are kept. Returns new panels; untouched ones are the same objects.
18
+ */
19
+ export declare function repack(panels: Panel[], order: number[]): Panel[];
20
+ export interface CanvasItem {
21
+ /** Index in dashboard.panels. */
22
+ index: number;
23
+ row: boolean;
24
+ /** Pixels from the canvas's top left. */
25
+ x: number;
26
+ y: number;
27
+ width: number;
28
+ height: number;
29
+ /** Columns out of 24 as laid out in this mode. */
30
+ span: number;
31
+ /** Height in grid units as laid out in this mode. */
32
+ h: number;
33
+ }
34
+ export interface Canvas {
35
+ items: CanvasItem[];
36
+ height: number;
37
+ /** Phone mode: panels hidden on phones, in order. They aren't in `items`. */
38
+ hidden: number[];
39
+ }
40
+ export declare const CANVAS_GAP = 8;
41
+ export declare const CANVAS_ROW_HEADER = 32;
42
+ /** A size to show for one panel while it's being resized, in the units of the current mode. */
43
+ export interface SizeOverride {
44
+ index: number;
45
+ span: number;
46
+ h: number;
47
+ }
48
+ /** Sizes in the current mode: grid uses gridPos; phone uses `mobile`, falling back like the app does. */
49
+ export declare function panelSize(panel: Panel, mode: LayoutMode): {
50
+ span: number;
51
+ h: number;
52
+ };
53
+ /** Pixel rectangles for every panel and row, laid out as the app would at `width`. */
54
+ export declare function layoutCanvas(panels: Panel[], order: number[], mode: LayoutMode, width: number, override?: SizeOverride): Canvas;
55
+ /**
56
+ * Where a dragged panel would land with the pointer at (x, y): before the panel or row
57
+ * returned, or at the end (null). Uses the nearest item, before or after it by which half
58
+ * the pointer is over (left/right for panels, top/bottom for rows).
59
+ */
60
+ export declare function dropTarget(canvas: Canvas, x: number, y: number, dragging: number): number | null;
61
+ /** Moves `index` to just before `before` (or to the end) and repacks. */
62
+ export declare function movePanel(panels: Panel[], index: number, before: number | null): Panel[];
63
+ /** Resizes in the units of `mode`: gridPos w/h on the grid, mobile span/h on phones. */
64
+ export declare function resizePanel(panels: Panel[], index: number, mode: LayoutMode, span: number, h: number): Panel[];
65
+ /** Shows or hides a panel on phones. */
66
+ export declare function setHiddenOnPhones(panels: Panel[], index: number, hidden: boolean): Panel[];
67
+ /** One more than the largest panel id anywhere, collapsed rows included. */
68
+ export declare function nextPanelId(panels: Panel[]): number;
69
+ /** Adds a panel after `after` (or at the end), with a fresh id. Returns the panels and the new one's index. */
70
+ export declare function insertPanel(panels: Panel[], panel: Panel, after: number | null): {
71
+ panels: Panel[];
72
+ index: number;
73
+ };
74
+ /** A copy of a panel right after it. */
75
+ export declare function duplicatePanel(panels: Panel[], index: number): {
76
+ panels: Panel[];
77
+ index: number;
78
+ };
79
+ /** Removes a panel. A collapsed row takes the panels inside it along. */
80
+ export declare function removePanel(panels: Panel[], index: number): Panel[];
81
+ /** Expands a collapsed row: its panels move out to the top level, right after it. */
82
+ export declare function expandRow(panels: Panel[], index: number): Panel[];
83
+ /**
84
+ * JSON edits that turn `before` into `after` (panel arrays from the ops above), with
85
+ * `panels` patched element by element so the file keeps its formatting.
86
+ */
87
+ export declare function panelEdits(before: Panel[], after: Panel[], removed?: number): JsonEdit[];
@@ -0,0 +1,56 @@
1
+ import type { DataFrame, Field } from './frame';
2
+ import type { Dashboard, DataLink } from './schema';
3
+ import type { TimeRange } from './time';
4
+ import { type ScopedVars, type VariableInfo, type VariableValues } from './variables';
5
+ /** A link with its URL filled in, ready to open. */
6
+ export interface ResolvedLink {
7
+ title: string;
8
+ href: string;
9
+ targetBlank: boolean;
10
+ }
11
+ /** What a data link was opened from: a chart point, table cell or reduced stat value. */
12
+ export interface LinkData {
13
+ frame?: DataFrame;
14
+ /** Row of `frame` the point or cell is in; unset for reduced values. */
15
+ row?: number;
16
+ field?: Field;
17
+ /** The field's display name. */
18
+ fieldName?: string;
19
+ value?: unknown;
20
+ /** The value as displayed, for `${__value.text}`. */
21
+ text?: string;
22
+ /** Epoch ms of the point, for `${__value.time}`. */
23
+ time?: number;
24
+ /** The reducer that produced a stat value, for `${__value.calc}`. */
25
+ calc?: string;
26
+ /** For `${__series.name}`; defaults to the frame name. */
27
+ seriesName?: string;
28
+ }
29
+ export interface LinkContext {
30
+ dashboard?: Dashboard;
31
+ values: VariableValues;
32
+ info?: Record<string, VariableInfo>;
33
+ scoped?: ScopedVars;
34
+ range?: TimeRange;
35
+ timezone?: string;
36
+ data?: LinkData;
37
+ }
38
+ /** Fill in each link's URL and title. Links whose URL ends up empty are dropped. */
39
+ export declare function resolveLinks(links: DataLink[] | undefined, ctx: LinkContext): ResolvedLink[];
40
+ /** What a link to a Grafana dashboard asks for: the dashboard, and optionally a time range and variable values. */
41
+ export interface DashboardLinkTarget {
42
+ uid: string;
43
+ from?: string;
44
+ to?: string;
45
+ vars: Record<string, string[]>;
46
+ }
47
+ /**
48
+ * Recognise a link to a Grafana dashboard: `/d/<uid>[/<slug>]` with optional `from`, `to` and
49
+ * `var-<name>` query parameters. Relative links count; absolute ones only on `grafanaUrl`'s host.
50
+ */
51
+ export declare function parseDashboardLink(href: string, grafanaUrl?: string): DashboardLinkTarget | null;
52
+ /**
53
+ * The dashboard as a link asks to show it: its time range and the variables' current values
54
+ * replaced by the link's. Epoch-ms times are kept as such; modelform parses them.
55
+ */
56
+ export declare function applyDashboardLink(dashboard: Dashboard, target: Pick<DashboardLinkTarget, 'from' | 'to' | 'vars'>): Dashboard;