@modelform/react-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/chunk-L4SQVIJV.js +10630 -0
- package/dist/chunk-PIHXMZ4G.mjs +10630 -0
- package/dist/core/configSchema.d.ts +29 -0
- package/dist/core/dashboardSettings.d.ts +34 -0
- package/dist/core/datasource.d.ts +61 -0
- package/dist/core/documents.d.ts +35 -0
- package/dist/core/editing.d.ts +129 -0
- package/dist/core/fieldconfig.d.ts +12 -0
- package/dist/core/format.d.ts +29 -0
- package/dist/core/frame.d.ts +51 -0
- package/dist/core/gazetteer.d.ts +25 -0
- package/dist/core/grafana.d.ts +85 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/index.js +380 -0
- package/dist/core/index.mjs +380 -0
- package/dist/core/inputs.d.ts +99 -0
- package/dist/core/jsonEdit.d.ts +30 -0
- package/dist/core/layout.d.ts +49 -0
- package/dist/core/layoutEdit.d.ts +87 -0
- package/dist/core/links.d.ts +56 -0
- package/dist/core/local.d.ts +95 -0
- package/dist/core/manifest.d.ts +201 -0
- package/dist/core/mappings.d.ts +46 -0
- package/dist/core/navigation.d.ts +19 -0
- package/dist/core/panelOptions.d.ts +109 -0
- package/dist/core/reduce.d.ts +6 -0
- package/dist/core/resolveVariables.d.ts +38 -0
- package/dist/core/sample.d.ts +13 -0
- package/dist/core/schema.d.ts +202 -0
- package/dist/core/time.d.ts +66 -0
- package/dist/core/transform.d.ts +12 -0
- package/dist/core/variables.d.ts +76 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +4156 -0
- package/dist/index.mjs +4156 -0
- package/dist/ui/Chip.d.ts +5 -0
- package/dist/ui/DashboardView.d.ts +22 -0
- package/dist/ui/RenderBoundary.d.ts +25 -0
- package/dist/ui/TimeRangeSheet.d.ts +24 -0
- package/dist/ui/Toolbar.d.ts +6 -0
- package/dist/ui/chart.d.ts +69 -0
- package/dist/ui/context.d.ts +68 -0
- package/dist/ui/geomap.d.ts +157 -0
- package/dist/ui/inputs/InputForm.d.ts +36 -0
- package/dist/ui/inputs/InputPanels.d.ts +4 -0
- package/dist/ui/inputs/formContext.d.ts +14 -0
- package/dist/ui/links.d.ts +28 -0
- package/dist/ui/panels/GaugePanels.d.ts +5 -0
- package/dist/ui/panels/GeomapPanel.d.ts +6 -0
- package/dist/ui/panels/OtherPanels.d.ts +18 -0
- package/dist/ui/panels/StatPanel.d.ts +14 -0
- package/dist/ui/panels/TimeSeriesPanel.d.ts +8 -0
- package/dist/ui/panels/XYChartPanel.d.ts +6 -0
- package/dist/ui/panels/common.d.ts +78 -0
- package/dist/ui/panels/registry.d.ts +5 -0
- package/dist/ui/table.d.ts +62 -0
- package/dist/ui/theme.d.ts +21 -0
- package/dist/ui/xychart.d.ts +27 -0
- package/package.json +89 -3
- package/schema/app.schema.json +184 -0
- package/schema/dashboard.schema.json +940 -0
- package/tools/dashboards.js +90 -0
- package/tools/metro.js +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Todd Winstanley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# modelform
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Render Grafana-compatible dashboard JSON as native React Native panels, and build input forms in the
|
|
4
|
+
same format. One JSON model describes both what an app records and how it charts it.
|
|
5
|
+
|
|
6
|
+
- **Dashboards:** `timeseries`, `barchart`, `stat`, `gauge`, `bargauge`, `piechart`, `table`, `text`, `xychart`,
|
|
7
|
+
`trend`, `geomap` and rows, with field config, overrides, value mappings, thresholds, transformations,
|
|
8
|
+
template variables and repeats. Layouts reflow into a single column on phones.
|
|
9
|
+
- **Forms:** a form is a dashboard whose panels are `input-*` types (number, slider, select, toggle, rating, text,
|
|
10
|
+
counter, duration). Entries go to an `EntryStore` you provide, and dashboards chart them through the local
|
|
11
|
+
datasource.
|
|
12
|
+
- **Datasources:** a local one over recorded entries, and a Grafana one that runs panel queries through a Grafana
|
|
13
|
+
instance's HTTP API. You can also implement your own.
|
|
14
|
+
- **Configs:** a manifest format for whole apps (tabs, forms and dashboards), with JSON Schemas, validation that
|
|
15
|
+
reports issues instead of throwing, and a loader with caching and last-good fallback.
|
|
16
|
+
|
|
17
|
+
modelform is not affiliated with or endorsed by Grafana Labs. It reads the dashboard JSON model that Grafana
|
|
18
|
+
exports, and ignores keys it doesn't understand.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install @modelform/react-native react-native-svg react-native-safe-area-context
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`react` and `react-native` are peer dependencies too. It works in Expo apps, including Expo Go.
|
|
27
|
+
|
|
28
|
+
## Render a dashboard
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { DashboardProvider, DashboardToolbar, DashboardView, LocalDataSource, MemoryEntryStore } from '@modelform/react-native';
|
|
32
|
+
import dashboard from './dashboards/weight.json';
|
|
33
|
+
|
|
34
|
+
const store = new MemoryEntryStore();
|
|
35
|
+
const local = new LocalDataSource(store);
|
|
36
|
+
|
|
37
|
+
export function Weight() {
|
|
38
|
+
return (
|
|
39
|
+
<DashboardProvider dashboard={dashboard} resolve={() => local}>
|
|
40
|
+
<DashboardView header={<DashboardToolbar />} />
|
|
41
|
+
</DashboardProvider>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`resolve` maps each panel's `datasource` to a `DataSource`. Panels read recorded entries with
|
|
47
|
+
`"datasource": { "type": "modelform-local" }` and targets such as:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "refId": "A", "metric": "weight" }
|
|
51
|
+
{ "refId": "A", "metric": "water", "aggregate": "sum", "bucket": "1d" }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To chart a Grafana instance instead, use `new GrafanaDataSource(new GrafanaClient({ url, token }))` with a
|
|
55
|
+
service-account token. Grafana runs the queries, so any of its datasources works.
|
|
56
|
+
|
|
57
|
+
## Record with a form
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { InputForm } from '@modelform/react-native';
|
|
61
|
+
import form from './forms/daily.json';
|
|
62
|
+
|
|
63
|
+
<InputForm dashboard={form} store={store} onSaved={(count) => console.log(`saved ${count}`)} />;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"title": "Daily",
|
|
69
|
+
"panels": [
|
|
70
|
+
{
|
|
71
|
+
"type": "input-number",
|
|
72
|
+
"title": "Weight",
|
|
73
|
+
"gridPos": { "x": 0, "y": 0, "w": 12, "h": 3 },
|
|
74
|
+
"options": { "metric": "weight", "unit": "kg", "step": 0.1, "default": "last" }
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For anything beyond a demo, implement `EntryStore` over your own storage, such as SQLite.
|
|
81
|
+
|
|
82
|
+
## Bundled dashboards
|
|
83
|
+
|
|
84
|
+
`modelform dashboards [dir] [--watch]` writes an `index.ts` that imports every `.json` file in a folder, so
|
|
85
|
+
the app can bundle them by name. From `metro.config.js`, `require('@modelform/react-native/dashboards').watchDashboards(dir)`
|
|
86
|
+
keeps that file current while Metro runs.
|
|
87
|
+
|
|
88
|
+
## Validation and schemas
|
|
89
|
+
|
|
90
|
+
`@modelform/react-native/core` holds everything that doesn't render: the types, validation, layout, transformations, the
|
|
91
|
+
datasources and the config loader. It runs in Node too, for example to check configs on a server.
|
|
92
|
+
|
|
93
|
+
`@modelform/react-native/schema/app.schema.json` (app manifests) and `@modelform/react-native/schema/dashboard.schema.json` (dashboards
|
|
94
|
+
and forms) give editors completion and inline checks.
|
|
95
|
+
|
|
96
|
+
## Releases
|
|
97
|
+
|
|
98
|
+
From 0.1.1 on, versions are built and staged on npm by this repo's GitHub Actions release workflow, through trusted publishing, so each
|
|
99
|
+
one carries npm provenance linking it to the commit it was built from. A maintainer approves each staged version,
|
|
100
|
+
with 2FA, before it goes live. Changes are listed in [CHANGELOG.md](CHANGELOG.md).
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|