@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.
- package/LICENSE +21 -0
- package/README.md +97 -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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Generates <app>/dashboards/index.ts from the *.json files beside it.
|
|
3
|
+
// Plain CommonJS so metro.config.js and the `modelform` bin can load it without a build step.
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const INDEX = 'index.ts';
|
|
8
|
+
|
|
9
|
+
const HEADER = `// Generated by modelform from the *.json files in this folder. Do not edit:
|
|
10
|
+
// add, rename or delete a .json file instead. \`expo start\` regenerates this file
|
|
11
|
+
// (see metro.config.js); run \`pnpm dashboards\` to regenerate it by hand.
|
|
12
|
+
//
|
|
13
|
+
// Export a dashboard from Grafana (Share → Export → JSON) and drop the file here.
|
|
14
|
+
// Exports made with "Export for sharing externally" reference datasources as \${DS_NAME};
|
|
15
|
+
// those resolve to the first datasource of the matching type in your Grafana.
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
/** Dashboard ids are file names without `.json`, sorted so output is stable. */
|
|
19
|
+
function listDashboards(dir) {
|
|
20
|
+
return fs
|
|
21
|
+
.readdirSync(dir)
|
|
22
|
+
.filter((f) => f.endsWith('.json'))
|
|
23
|
+
.sort()
|
|
24
|
+
.map((file) => ({ id: file.slice(0, -'.json'.length), file }));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function renderIndex(entries) {
|
|
28
|
+
const key = (id) => (/^[A-Za-z_$][\w$]*$/.test(id) ? id : `'${id.replace(/'/g, "\\'")}'`);
|
|
29
|
+
const ids = entries.length ? entries.map((e) => `'${e.id}'`).join(' | ') : 'never';
|
|
30
|
+
const rows = entries.map((e) => ` ${key(e.id)}: require('./${e.file}'),\n`).join('');
|
|
31
|
+
return `${HEADER}
|
|
32
|
+
import type { Dashboard } from '@modelform/react-native';
|
|
33
|
+
|
|
34
|
+
export type BundledId = ${ids};
|
|
35
|
+
|
|
36
|
+
// require() rather than import so JSON edits hot-reload while \`expo start\` runs.
|
|
37
|
+
export const bundled: Record<string, Dashboard> = {
|
|
38
|
+
${rows}};
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Writes dir/index.ts if its contents would change. Returns true when it wrote. */
|
|
43
|
+
function writeIndex(dir) {
|
|
44
|
+
const out = path.join(dir, INDEX);
|
|
45
|
+
const next = renderIndex(listDashboards(dir));
|
|
46
|
+
const prev = fs.existsSync(out) ? fs.readFileSync(out, 'utf8') : null;
|
|
47
|
+
if (prev === next) return false;
|
|
48
|
+
fs.writeFileSync(out, next);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates the index now, then again whenever a .json file is added, removed or renamed.
|
|
54
|
+
* The watcher is unref'd so one-shot commands like `expo export` still exit.
|
|
55
|
+
*/
|
|
56
|
+
function watchDashboards(dir, log = console.log) {
|
|
57
|
+
const run = () => {
|
|
58
|
+
try {
|
|
59
|
+
if (writeIndex(dir)) log(`modelform: regenerated ${path.relative(process.cwd(), path.join(dir, INDEX))}`);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
log(`modelform: could not generate ${INDEX} in ${dir}: ${e.message}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
run();
|
|
65
|
+
let timer;
|
|
66
|
+
const watcher = fs.watch(dir, (_event, name) => {
|
|
67
|
+
if (name && !String(name).endsWith('.json')) return;
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
timer = setTimeout(run, 50);
|
|
70
|
+
});
|
|
71
|
+
watcher.unref();
|
|
72
|
+
return watcher;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { listDashboards, renderIndex, writeIndex, watchDashboards };
|
|
76
|
+
|
|
77
|
+
if (require.main === module) {
|
|
78
|
+
const args = process.argv.slice(2);
|
|
79
|
+
if (args[0] !== 'dashboards') {
|
|
80
|
+
console.error('usage: modelform dashboards [dir] [--watch]');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
const watch = args.includes('--watch');
|
|
84
|
+
const dir = path.resolve(args.slice(1).find((a) => !a.startsWith('--')) ?? 'dashboards');
|
|
85
|
+
if (watch) {
|
|
86
|
+
watchDashboards(dir).ref();
|
|
87
|
+
} else {
|
|
88
|
+
console.log(writeIndex(dir) ? `wrote ${path.join(dir, INDEX)}` : `${path.join(dir, INDEX)} is up to date`);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/tools/metro.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Metro settings every app that bundles modelform needs.
|
|
2
|
+
// Plain CommonJS so metro.config.js can load it without a build step.
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
// jsonc-parser's `main` is a UMD build that calls `require` through a factory parameter,
|
|
6
|
+
// which Metro's dependency collector can't see: its ./impl/* modules are left out of the
|
|
7
|
+
// bundle and the app dies on load with `Requiring unknown module "./impl/format"`. Its ESM
|
|
8
|
+
// build uses plain imports, so point Metro there.
|
|
9
|
+
const JSONC_PARSER_ESM = path.join(path.dirname(require.resolve('jsonc-parser/package.json')), 'lib/esm/main.js');
|
|
10
|
+
|
|
11
|
+
/** Adjusts an Expo Metro config so modelform's dependencies bundle correctly. */
|
|
12
|
+
function withModelform(config) {
|
|
13
|
+
const resolveRequest = config.resolver.resolveRequest;
|
|
14
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
15
|
+
if (moduleName === 'jsonc-parser') return { type: 'sourceFile', filePath: JSONC_PARSER_ESM };
|
|
16
|
+
return (resolveRequest ?? context.resolveRequest)(context, moduleName, platform);
|
|
17
|
+
};
|
|
18
|
+
return config;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { withModelform };
|