@modelform/react-native 0.6.0 → 0.8.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/README.md +5 -0
- package/dist/{chunk-BW6HKFAB.mjs → chunk-AQO56KS2.mjs} +72 -21
- package/dist/{chunk-YUXA7I4J.js → chunk-QIBL3YUL.js} +73 -22
- package/dist/core/index.js +4 -2
- package/dist/core/index.mjs +3 -1
- package/dist/core/local.d.ts +20 -4
- package/dist/index.js +388 -265
- package/dist/index.mjs +189 -66
- package/dist/ui/inputs/InputGroup.d.ts +4 -0
- package/dist/ui/inputs/formContext.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
getPath,
|
|
85
85
|
gridOffsetPx,
|
|
86
86
|
gridUnitsToPx,
|
|
87
|
+
groupField,
|
|
87
88
|
groupFields,
|
|
88
89
|
groupProblems,
|
|
89
90
|
groupToEntries,
|
|
@@ -220,7 +221,7 @@ import {
|
|
|
220
221
|
variableWithType,
|
|
221
222
|
visibleVariables,
|
|
222
223
|
zoomRange
|
|
223
|
-
} from "./chunk-
|
|
224
|
+
} from "./chunk-AQO56KS2.mjs";
|
|
224
225
|
|
|
225
226
|
// src/ui/theme.tsx
|
|
226
227
|
import { createContext, useContext } from "react";
|
|
@@ -572,7 +573,7 @@ function usePanelLinks(panel) {
|
|
|
572
573
|
}
|
|
573
574
|
|
|
574
575
|
// src/ui/DashboardView.tsx
|
|
575
|
-
import { useCallback as useCallback3, useContext as useContext4, useMemo as useMemo9, useRef as
|
|
576
|
+
import { useCallback as useCallback3, useContext as useContext4, useMemo as useMemo9, useRef as useRef5, useState as useState11 } from "react";
|
|
576
577
|
import {
|
|
577
578
|
ActivityIndicator,
|
|
578
579
|
Pressable as Pressable12,
|
|
@@ -615,7 +616,7 @@ function useInputForm() {
|
|
|
615
616
|
}
|
|
616
617
|
|
|
617
618
|
// src/ui/inputs/InputGroup.tsx
|
|
618
|
-
import { useMemo as useMemo2 } from "react";
|
|
619
|
+
import { useMemo as useMemo2, useRef as useRef2, useState as useState6 } from "react";
|
|
619
620
|
import { Pressable as Pressable6, ScrollView as ScrollView4, StyleSheet as StyleSheet7, Text as Text7, View as View6 } from "react-native";
|
|
620
621
|
|
|
621
622
|
// src/ui/inputs/InputPanels.tsx
|
|
@@ -1787,21 +1788,117 @@ function titleText(v) {
|
|
|
1787
1788
|
if (Array.isArray(v)) return v.length ? v.join(", ") : void 0;
|
|
1788
1789
|
return typeof v === "boolean" ? void 0 : String(v);
|
|
1789
1790
|
}
|
|
1791
|
+
function summaryText(f, v) {
|
|
1792
|
+
if (v == null || v === "" || Array.isArray(v) && !v.length) return void 0;
|
|
1793
|
+
if (f.type === "input-toggle") return v ? f.title || "Yes" : void 0;
|
|
1794
|
+
if (f.type === "input-duration" && typeof v === "number") return formatClock(v);
|
|
1795
|
+
if (f.type === "input-select" && f.options.choices) {
|
|
1796
|
+
const label = (x) => f.options.choices.find((c) => c.value === x)?.label ?? String(x);
|
|
1797
|
+
return Array.isArray(v) ? v.map(label).join(", ") : label(v);
|
|
1798
|
+
}
|
|
1799
|
+
const text = Array.isArray(v) ? v.join(", ") : String(v);
|
|
1800
|
+
return f.options.unit ? `${text} ${f.options.unit}` : text;
|
|
1801
|
+
}
|
|
1802
|
+
var GAP = 8;
|
|
1803
|
+
function dropIndex(from, dy, keys, span) {
|
|
1804
|
+
let to = from;
|
|
1805
|
+
let left = dy;
|
|
1806
|
+
while (left > 0 && to < keys.length - 1 && left > span(keys[to + 1]) / 2) left -= span(keys[++to]);
|
|
1807
|
+
while (left < 0 && to > 0 && -left > span(keys[to - 1]) / 2) left += span(keys[--to]);
|
|
1808
|
+
return to;
|
|
1809
|
+
}
|
|
1790
1810
|
function InputGroupBody({ panel }) {
|
|
1791
1811
|
const theme = useDashTheme();
|
|
1792
1812
|
const form = useInputForm();
|
|
1793
1813
|
const group = form.group?.(panel);
|
|
1814
|
+
const [collapsed, setCollapsed] = useState6(/* @__PURE__ */ new Set());
|
|
1815
|
+
const [drag, setDrag] = useState6(null);
|
|
1816
|
+
const [heights, setHeights] = useState6({});
|
|
1817
|
+
const dragging = useRef2(null);
|
|
1818
|
+
const [wasEdited, setWasEdited] = useState6(group?.edited);
|
|
1819
|
+
if (group && group.edited !== wasEdited) {
|
|
1820
|
+
setWasEdited(group.edited);
|
|
1821
|
+
if (!group.edited) setCollapsed(/* @__PURE__ */ new Set());
|
|
1822
|
+
}
|
|
1794
1823
|
if (!group) return null;
|
|
1795
1824
|
const label = panel.options.itemTitle || "Item";
|
|
1796
|
-
|
|
1825
|
+
const collapseFilled = (except) => setCollapsed(new Set(group.items.filter((i) => i.key !== except && !isEmptyItem(panel, i.values)).map((i) => i.key)));
|
|
1826
|
+
const toggle = (key) => setCollapsed((c) => {
|
|
1827
|
+
const next = new Set(c);
|
|
1828
|
+
if (!next.delete(key)) next.add(key);
|
|
1829
|
+
return next;
|
|
1830
|
+
});
|
|
1831
|
+
const setDragging = (d) => {
|
|
1832
|
+
dragging.current = d;
|
|
1833
|
+
setDrag(d);
|
|
1834
|
+
};
|
|
1835
|
+
const span = (key) => (heights[key] ?? 0) + GAP;
|
|
1836
|
+
const keys = group.items.map((i) => i.key);
|
|
1837
|
+
const startDrag = (key, e) => setDragging({ key, from: keys.indexOf(key), startY: e.nativeEvent.pageY, dy: 0 });
|
|
1838
|
+
const moveDrag = (e) => {
|
|
1839
|
+
const d = dragging.current;
|
|
1840
|
+
if (d) setDragging({ ...d, dy: e.nativeEvent.pageY - d.startY });
|
|
1841
|
+
};
|
|
1842
|
+
const dropDrag = () => {
|
|
1843
|
+
const d = dragging.current;
|
|
1844
|
+
setDragging(null);
|
|
1845
|
+
if (!d) return;
|
|
1846
|
+
const to2 = dropIndex(d.from, d.dy, keys, span);
|
|
1847
|
+
for (let i = d.from; i !== to2; i += to2 > i ? 1 : -1) group.move(i, to2 > i ? 1 : -1);
|
|
1848
|
+
};
|
|
1849
|
+
const endDrag = () => setDragging(null);
|
|
1850
|
+
const to = drag ? dropIndex(drag.from, drag.dy, keys, span) : -1;
|
|
1851
|
+
const shift = (i, key) => {
|
|
1852
|
+
if (!drag) return void 0;
|
|
1853
|
+
if (key === drag.key) return drag.dy;
|
|
1854
|
+
const room = span(drag.key);
|
|
1855
|
+
if (drag.from < i && i <= to) return -room;
|
|
1856
|
+
if (to <= i && i < drag.from) return room;
|
|
1857
|
+
return 0;
|
|
1858
|
+
};
|
|
1859
|
+
return /* @__PURE__ */ jsxs7(ScrollView4, { style: styles7.fill, contentContainerStyle: styles7.list, nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", scrollEnabled: !drag, children: [
|
|
1797
1860
|
group.items.map((item, i) => {
|
|
1798
1861
|
const named = panel.options.titleFrom ? titleText(item.values[panel.options.titleFrom]) : void 0;
|
|
1799
|
-
|
|
1862
|
+
const title = named ?? `${label} ${i + 1}`;
|
|
1863
|
+
const troubled = groupFields(panel).some((f) => group.fieldProblem(i, f.options.metric));
|
|
1864
|
+
return /* @__PURE__ */ jsx9(
|
|
1865
|
+
ItemCard,
|
|
1866
|
+
{
|
|
1867
|
+
panel,
|
|
1868
|
+
group,
|
|
1869
|
+
form,
|
|
1870
|
+
index: i,
|
|
1871
|
+
title,
|
|
1872
|
+
last: i === group.items.length - 1,
|
|
1873
|
+
collapsed: collapsed.has(item.key) && !troubled,
|
|
1874
|
+
onToggle: () => toggle(item.key),
|
|
1875
|
+
onDuplicate: () => {
|
|
1876
|
+
collapseFilled();
|
|
1877
|
+
group.duplicate(i);
|
|
1878
|
+
},
|
|
1879
|
+
dragOffset: shift(i, item.key),
|
|
1880
|
+
lifted: drag?.key === item.key,
|
|
1881
|
+
onLayout: (h) => setHeights((all) => all[item.key] === h ? all : { ...all, [item.key]: h }),
|
|
1882
|
+
handle: {
|
|
1883
|
+
onStartShouldSetResponder: () => true,
|
|
1884
|
+
onMoveShouldSetResponder: () => true,
|
|
1885
|
+
onResponderTerminationRequest: () => false,
|
|
1886
|
+
onResponderGrant: (e) => startDrag(item.key, e),
|
|
1887
|
+
onResponderMove: moveDrag,
|
|
1888
|
+
onResponderRelease: dropDrag,
|
|
1889
|
+
onResponderTerminate: endDrag
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
item.key
|
|
1893
|
+
);
|
|
1800
1894
|
}),
|
|
1801
1895
|
group.canAdd && /* @__PURE__ */ jsx9(
|
|
1802
1896
|
Pressable6,
|
|
1803
1897
|
{
|
|
1804
|
-
onPress:
|
|
1898
|
+
onPress: () => {
|
|
1899
|
+
collapseFilled();
|
|
1900
|
+
group.add();
|
|
1901
|
+
},
|
|
1805
1902
|
accessibilityRole: "button",
|
|
1806
1903
|
style: ({ pressed }) => [styles7.add, { borderColor: theme.accent, opacity: pressed ? 0.7 : 1 }],
|
|
1807
1904
|
children: /* @__PURE__ */ jsxs7(Text7, { style: { color: theme.accent, fontWeight: "600" }, children: [
|
|
@@ -1812,7 +1909,7 @@ function InputGroupBody({ panel }) {
|
|
|
1812
1909
|
)
|
|
1813
1910
|
] });
|
|
1814
1911
|
}
|
|
1815
|
-
function ItemCard({ panel, group, form, index, title, last }) {
|
|
1912
|
+
function ItemCard({ panel, group, form, index, title, last, collapsed, onToggle, onDuplicate, dragOffset, lifted, onLayout, handle }) {
|
|
1816
1913
|
const theme = useDashTheme();
|
|
1817
1914
|
const fields = useMemo2(() => groupFields(panel), [panel]);
|
|
1818
1915
|
const item = group.items[index];
|
|
@@ -1838,32 +1935,56 @@ function ItemCard({ panel, group, form, index, title, last }) {
|
|
|
1838
1935
|
children: /* @__PURE__ */ jsx9(Text7, { style: { color: theme.textSecondary, fontSize: 15 }, children: text })
|
|
1839
1936
|
}
|
|
1840
1937
|
);
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1938
|
+
const summary = collapsed ? fields.filter((f) => f.options.metric !== panel.options.titleFrom).map((f) => summaryText(f, item.values[f.options.metric])).filter(Boolean).join(" \xB7 ") : "";
|
|
1939
|
+
return /* @__PURE__ */ jsxs7(
|
|
1940
|
+
View6,
|
|
1941
|
+
{
|
|
1942
|
+
onLayout: (e) => onLayout(e.nativeEvent.layout.height),
|
|
1943
|
+
style: [
|
|
1944
|
+
styles7.item,
|
|
1945
|
+
{ borderColor: lifted ? theme.accent : theme.border, backgroundColor: theme.surface },
|
|
1946
|
+
!!dragOffset && { transform: [{ translateY: dragOffset }] },
|
|
1947
|
+
lifted && { zIndex: 1, opacity: 0.95 }
|
|
1948
|
+
],
|
|
1949
|
+
children: [
|
|
1950
|
+
/* @__PURE__ */ jsxs7(View6, { style: styles7.itemHeader, children: [
|
|
1951
|
+
/* @__PURE__ */ jsx9(View6, { ...handle, style: styles7.handle, accessibilityLabel: `Drag ${title} to reorder`, children: /* @__PURE__ */ jsx9(Text7, { style: { color: theme.textMuted, fontSize: 16 }, children: "\u2261" }) }),
|
|
1952
|
+
/* @__PURE__ */ jsxs7(Pressable6, { onPress: onToggle, style: styles7.titleArea, accessibilityRole: "button", accessibilityLabel: `${collapsed ? "Expand" : "Collapse"} ${title}`, accessibilityState: { expanded: !collapsed }, children: [
|
|
1953
|
+
/* @__PURE__ */ jsxs7(Text7, { style: [styles7.itemTitle, { color: theme.text }], numberOfLines: 1, children: [
|
|
1954
|
+
collapsed ? "\u25B8 " : "\u25BE ",
|
|
1955
|
+
title
|
|
1956
|
+
] }),
|
|
1957
|
+
!!summary && /* @__PURE__ */ jsx9(Text7, { style: [styles7.summary, { color: theme.textSecondary }], numberOfLines: 1, children: summary })
|
|
1958
|
+
] }),
|
|
1959
|
+
button("\u2191", () => group.move(index, -1), `Move ${title} up`, index === 0),
|
|
1960
|
+
button("\u2193", () => group.move(index, 1), `Move ${title} down`, last),
|
|
1961
|
+
button("\u29C9", onDuplicate, `Duplicate ${title}`, !group.canAdd),
|
|
1962
|
+
button("\u2715", () => group.remove(index), `Remove ${title}`)
|
|
1855
1963
|
] }),
|
|
1856
|
-
/* @__PURE__ */ jsx9(
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1964
|
+
!collapsed && /* @__PURE__ */ jsx9(InputFormContext.Provider, { value: scoped, children: /* @__PURE__ */ jsx9(View6, { style: styles7.fields, children: fields.map((f) => {
|
|
1965
|
+
const problem = scoped.problem?.(f.options.metric);
|
|
1966
|
+
return /* @__PURE__ */ jsxs7(View6, { style: [styles7.field, { width: `${Math.min(24, Math.max(1, f.gridPos.w)) / 24 * 100}%` }], children: [
|
|
1967
|
+
/* @__PURE__ */ jsxs7(View6, { style: styles7.fieldHeader, children: [
|
|
1968
|
+
!!f.title && /* @__PURE__ */ jsx9(Text7, { style: [styles7.fieldTitle, { color: theme.textSecondary }], numberOfLines: 1, children: f.title }),
|
|
1969
|
+
!!problem && /* @__PURE__ */ jsx9(Text7, { style: [styles7.problem, { color: theme.danger }], numberOfLines: 1, accessibilityRole: "alert", children: problem })
|
|
1970
|
+
] }),
|
|
1971
|
+
/* @__PURE__ */ jsx9(View6, { style: styles7.fieldBody, children: /* @__PURE__ */ jsx9(InputPanelBody, { panel: f }) })
|
|
1972
|
+
] }, f.options.metric);
|
|
1973
|
+
}) }) })
|
|
1974
|
+
]
|
|
1975
|
+
}
|
|
1976
|
+
);
|
|
1860
1977
|
}
|
|
1861
1978
|
var styles7 = StyleSheet7.create({
|
|
1862
1979
|
fill: { flex: 1 },
|
|
1863
1980
|
list: { gap: 8, paddingBottom: 4 },
|
|
1864
1981
|
item: { borderWidth: 1, borderRadius: 8, padding: 8, gap: 6 },
|
|
1865
1982
|
itemHeader: { flexDirection: "row", alignItems: "center", gap: 4 },
|
|
1866
|
-
|
|
1983
|
+
titleArea: { flex: 1, flexDirection: "row", alignItems: "baseline", gap: 8, minHeight: 28, paddingVertical: 4 },
|
|
1984
|
+
itemTitle: { fontSize: 14, fontWeight: "600", flexShrink: 0, maxWidth: "60%" },
|
|
1985
|
+
summary: { flex: 1, fontSize: 13 },
|
|
1986
|
+
// Web: no text selection or page scroll from dragging the handle.
|
|
1987
|
+
handle: { width: 24, height: 28, alignItems: "center", justifyContent: "center", cursor: "grab", userSelect: "none", touchAction: "none" },
|
|
1867
1988
|
iconBtn: { width: 28, height: 28, alignItems: "center", justifyContent: "center" },
|
|
1868
1989
|
fields: { flexDirection: "row", flexWrap: "wrap", marginHorizontal: -4 },
|
|
1869
1990
|
field: { paddingHorizontal: 4, paddingVertical: 4, gap: 4 },
|
|
@@ -2046,7 +2167,7 @@ var styles9 = StyleSheet9.create({
|
|
|
2046
2167
|
});
|
|
2047
2168
|
|
|
2048
2169
|
// src/ui/panels/GeomapPanel.tsx
|
|
2049
|
-
import { useEffect as useEffect3, useMemo as useMemo5, useRef as
|
|
2170
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useRef as useRef3, useState as useState7 } from "react";
|
|
2050
2171
|
import { Image, PixelRatio, Pressable as Pressable9, StyleSheet as StyleSheet10, Text as Text10, View as View9 } from "react-native";
|
|
2051
2172
|
import Svg6, { Path as Path6, Text as SvgText2 } from "react-native-svg";
|
|
2052
2173
|
|
|
@@ -2475,8 +2596,8 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2475
2596
|
const { gazetteers, error } = useGazetteers(panel, frames);
|
|
2476
2597
|
const layers = useMemo5(() => geomapLayers(panel, frames, theme.scheme, retina, gazetteers), [panel, frames, theme.scheme, retina, gazetteers]);
|
|
2477
2598
|
const home = useMemo5(() => initialView(panel, layers, size.width, size.height), [panel, layers, size.width, size.height]);
|
|
2478
|
-
const [moved, setMoved] =
|
|
2479
|
-
const [picked, setPicked] =
|
|
2599
|
+
const [moved, setMoved] = useState7(null);
|
|
2600
|
+
const [picked, setPicked] = useState7(null);
|
|
2480
2601
|
const links = usePanelLinks(panel);
|
|
2481
2602
|
const view = moved ?? home;
|
|
2482
2603
|
const [minZoom, maxZoom] = zoomLimits(panel);
|
|
@@ -2517,7 +2638,7 @@ function GeomapPanel({ panel, frames }) {
|
|
|
2517
2638
|
}
|
|
2518
2639
|
return best;
|
|
2519
2640
|
};
|
|
2520
|
-
const gesture =
|
|
2641
|
+
const gesture = useRef3(null);
|
|
2521
2642
|
const responder = {
|
|
2522
2643
|
onStartShouldSetResponder: () => true,
|
|
2523
2644
|
// Keep the gesture while panning instead of handing it to the dashboard's scroll view.
|
|
@@ -2603,7 +2724,7 @@ var NONE = {};
|
|
|
2603
2724
|
function useGazetteers(panel, frames) {
|
|
2604
2725
|
const { resolve } = useDashboard();
|
|
2605
2726
|
const key = gazetteerPaths(panel, frames).join("\n");
|
|
2606
|
-
const [state, setState] =
|
|
2727
|
+
const [state, setState] = useState7({ key: "", gazetteers: NONE });
|
|
2607
2728
|
useEffect3(() => {
|
|
2608
2729
|
if (!key) return;
|
|
2609
2730
|
let live = true;
|
|
@@ -2740,7 +2861,7 @@ var styles10 = StyleSheet10.create({
|
|
|
2740
2861
|
});
|
|
2741
2862
|
|
|
2742
2863
|
// src/ui/panels/OtherPanels.tsx
|
|
2743
|
-
import { useMemo as useMemo6, useState as
|
|
2864
|
+
import { useMemo as useMemo6, useState as useState8 } from "react";
|
|
2744
2865
|
import { Pressable as Pressable10, ScrollView as ScrollView5, StyleSheet as StyleSheet11, Text as Text11, View as View10 } from "react-native";
|
|
2745
2866
|
import Svg7, { Path as Path7 } from "react-native-svg";
|
|
2746
2867
|
|
|
@@ -2929,7 +3050,7 @@ function TablePanel({ panel, frames }) {
|
|
|
2929
3050
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
2930
3051
|
const frame = frames[0];
|
|
2931
3052
|
const columns = useMemo6(() => frame ? tableColumns(panel, frame, frames.length > 1) : [], [panel, frame, frames.length]);
|
|
2932
|
-
const [tapped, setSort] =
|
|
3053
|
+
const [tapped, setSort] = useState8();
|
|
2933
3054
|
const sort = tapped === void 0 ? initialSort(panel, columns) : tapped;
|
|
2934
3055
|
const order = useMemo6(() => sortedRows(columns, frame ? frameLength(frame) : 0, sort), [columns, frame, sort]);
|
|
2935
3056
|
if (!frame || !frameLength(frame)) return /* @__PURE__ */ jsx13(NoData, {});
|
|
@@ -3110,7 +3231,7 @@ var styles11 = StyleSheet11.create({
|
|
|
3110
3231
|
});
|
|
3111
3232
|
|
|
3112
3233
|
// src/ui/panels/TimeSeriesPanel.tsx
|
|
3113
|
-
import { useId, useMemo as useMemo7, useRef as
|
|
3234
|
+
import { useId, useMemo as useMemo7, useRef as useRef4, useState as useState9 } from "react";
|
|
3114
3235
|
import { Pressable as Pressable11, StyleSheet as StyleSheet12, Text as Text12, View as View11 } from "react-native";
|
|
3115
3236
|
import Svg8, { Circle, ClipPath, Defs, G, Line, Path as Path8, Rect, Text as SvgText3 } from "react-native-svg";
|
|
3116
3237
|
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
@@ -3121,14 +3242,14 @@ function TimeSeriesPanel({ panel, frames }) {
|
|
|
3121
3242
|
const { range: range3, setRawRange, pinned, setPinned } = useDashboard();
|
|
3122
3243
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
3123
3244
|
const [size, onLayout] = useLayout();
|
|
3124
|
-
const [hoverX, setHoverX] =
|
|
3125
|
-
const [preview, setPreview] =
|
|
3126
|
-
const [xZoom, setXZoom] =
|
|
3127
|
-
const pinch =
|
|
3128
|
-
const originX =
|
|
3245
|
+
const [hoverX, setHoverX] = useState9(null);
|
|
3246
|
+
const [preview, setPreview] = useState9(null);
|
|
3247
|
+
const [xZoom, setXZoom] = useState9(null);
|
|
3248
|
+
const pinch = useRef4(null);
|
|
3249
|
+
const originX = useRef4(0);
|
|
3129
3250
|
const id = useId();
|
|
3130
3251
|
const clipId = `plot${id.replace(/[^a-zA-Z0-9]/g, "")}`;
|
|
3131
|
-
const [touching, setTouching] =
|
|
3252
|
+
const [touching, setTouching] = useState9(false);
|
|
3132
3253
|
const numericX = panel.type === "trend";
|
|
3133
3254
|
const { series, xConfig } = useMemo7(
|
|
3134
3255
|
() => numericX ? styledXYSeries(panel, frames, theme.scheme) : { series: styledSeries(panel, frames, theme.scheme), xConfig: {} },
|
|
@@ -3431,7 +3552,7 @@ var styles12 = StyleSheet12.create({
|
|
|
3431
3552
|
});
|
|
3432
3553
|
|
|
3433
3554
|
// src/ui/panels/XYChartPanel.tsx
|
|
3434
|
-
import { useId as useId2, useMemo as useMemo8, useState as
|
|
3555
|
+
import { useId as useId2, useMemo as useMemo8, useState as useState10 } from "react";
|
|
3435
3556
|
import { StyleSheet as StyleSheet13, View as View12 } from "react-native";
|
|
3436
3557
|
import Svg9, { Circle as Circle2, G as G2, Line as Line2, Path as Path9, Text as SvgText4 } from "react-native-svg";
|
|
3437
3558
|
|
|
@@ -3571,8 +3692,8 @@ var HIT_PX2 = 32;
|
|
|
3571
3692
|
function XYChartPanel({ panel, frames }) {
|
|
3572
3693
|
const theme = useDashTheme();
|
|
3573
3694
|
const [size, onLayout] = useLayout();
|
|
3574
|
-
const [touch, setTouch] =
|
|
3575
|
-
const [touching, setTouching] =
|
|
3695
|
+
const [touch, setTouch] = useState10(null);
|
|
3696
|
+
const [touching, setTouching] = useState10(false);
|
|
3576
3697
|
const id = useId2();
|
|
3577
3698
|
const { pinned, setPinned } = useDashboard();
|
|
3578
3699
|
const { resolve, openLinks } = usePanelLinks(panel);
|
|
@@ -3745,7 +3866,7 @@ function panelComponent(type) {
|
|
|
3745
3866
|
|
|
3746
3867
|
// src/ui/DashboardView.tsx
|
|
3747
3868
|
import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3748
|
-
var
|
|
3869
|
+
var GAP2 = 8;
|
|
3749
3870
|
var SIDE = 12;
|
|
3750
3871
|
var TITLE_H = 28;
|
|
3751
3872
|
var TABLET_WIDTH = 700;
|
|
@@ -3762,7 +3883,7 @@ function DashboardView({ mode = "auto", header, footer, refreshable }) {
|
|
|
3762
3883
|
() => layoutDashboard(dashboard, layoutMode, { values: variables, info: variableInfo2 }),
|
|
3763
3884
|
[dashboard, layoutMode, variables, variableInfo2]
|
|
3764
3885
|
);
|
|
3765
|
-
const [toggled, setToggled] =
|
|
3886
|
+
const [toggled, setToggled] = useState11({});
|
|
3766
3887
|
const { seen, viewportH, onScroll, onViewportLayout, onSectionLayout } = useSeenSections(window.height);
|
|
3767
3888
|
const maxPanelH = Math.max(MIN_PANEL_H, viewportH - SIDE * 2);
|
|
3768
3889
|
const contentW = width - SIDE * 2;
|
|
@@ -3798,7 +3919,7 @@ function DashboardView({ mode = "auto", header, footer, refreshable }) {
|
|
|
3798
3919
|
),
|
|
3799
3920
|
!collapsed && layoutMode === "grid" && /* @__PURE__ */ jsx16(GridSection, { grid: section.grid, width: contentW, maxPanelH, deferred: !seen.has(section.key) }),
|
|
3800
3921
|
!collapsed && layoutMode === "phone" && section.rows.map((row, ri) => /* @__PURE__ */ jsx16(View13, { style: styles14.row, children: row.cells.map((cell) => {
|
|
3801
|
-
const w = (contentW +
|
|
3922
|
+
const w = (contentW + GAP2) * (cell.span / GRID_COLUMNS) - GAP2;
|
|
3802
3923
|
return /* @__PURE__ */ jsx16(PanelCard, { panel: cell.panel, width: w, height: Math.min(gridUnitsToPx(row.h), maxPanelH), deferred: !seen.has(section.key) }, cell.key);
|
|
3803
3924
|
}) }, ri))
|
|
3804
3925
|
] }, section.key);
|
|
@@ -3810,16 +3931,16 @@ function DashboardView({ mode = "auto", header, footer, refreshable }) {
|
|
|
3810
3931
|
] });
|
|
3811
3932
|
}
|
|
3812
3933
|
function GridSection({ grid, width, maxPanelH, deferred }) {
|
|
3813
|
-
const colW = (width +
|
|
3934
|
+
const colW = (width + GAP2) / GRID_COLUMNS;
|
|
3814
3935
|
const tallest = Math.max(0, ...grid.cells.map((c) => gridUnitsToPx(c.h)));
|
|
3815
3936
|
const scale = tallest > maxPanelH ? maxPanelH / tallest : 1;
|
|
3816
|
-
return /* @__PURE__ */ jsx16(View13, { style: { height: gridUnitsToPx(grid.h) * scale }, children: grid.cells.map((cell) => /* @__PURE__ */ jsx16(View13, { style: [styles14.gridCell, { left: cell.x * colW, top: gridOffsetPx(cell.y) * scale }], children: /* @__PURE__ */ jsx16(PanelCard, { panel: cell.panel, width: cell.w * colW -
|
|
3937
|
+
return /* @__PURE__ */ jsx16(View13, { style: { height: gridUnitsToPx(grid.h) * scale }, children: grid.cells.map((cell) => /* @__PURE__ */ jsx16(View13, { style: [styles14.gridCell, { left: cell.x * colW, top: gridOffsetPx(cell.y) * scale }], children: /* @__PURE__ */ jsx16(PanelCard, { panel: cell.panel, width: cell.w * colW - GAP2, height: gridUnitsToPx(cell.h) * scale, deferred }) }, cell.key)) });
|
|
3817
3938
|
}
|
|
3818
3939
|
function useSeenSections(viewportHeight) {
|
|
3819
|
-
const [seen, setSeen] =
|
|
3820
|
-
const view =
|
|
3821
|
-
const [viewportH, setViewportH] =
|
|
3822
|
-
const positions =
|
|
3940
|
+
const [seen, setSeen] = useState11(/* @__PURE__ */ new Set());
|
|
3941
|
+
const view = useRef5({ y: 0, h: viewportHeight });
|
|
3942
|
+
const [viewportH, setViewportH] = useState11(viewportHeight);
|
|
3943
|
+
const positions = useRef5(/* @__PURE__ */ new Map());
|
|
3823
3944
|
const reveal = useCallback3(() => {
|
|
3824
3945
|
const { y, h } = view.current;
|
|
3825
3946
|
setSeen((prev) => {
|
|
@@ -3913,12 +4034,12 @@ function DataPanelBody({ panel, width, height }) {
|
|
|
3913
4034
|
}
|
|
3914
4035
|
var styles14 = StyleSheet14.create({
|
|
3915
4036
|
fill: { flex: 1 },
|
|
3916
|
-
content: { padding: SIDE, paddingBottom: 32, gap:
|
|
3917
|
-
section: { gap:
|
|
4037
|
+
content: { padding: SIDE, paddingBottom: 32, gap: GAP2 },
|
|
4038
|
+
section: { gap: GAP2 },
|
|
3918
4039
|
rowHeader: { flexDirection: "row", alignItems: "center", gap: 6, paddingVertical: 6 },
|
|
3919
4040
|
chevron: { fontSize: 14, width: 14 },
|
|
3920
4041
|
rowTitle: { fontSize: 15, fontWeight: "600" },
|
|
3921
|
-
row: { flexDirection: "row", gap:
|
|
4042
|
+
row: { flexDirection: "row", gap: GAP2 },
|
|
3922
4043
|
gridCell: { position: "absolute" },
|
|
3923
4044
|
card: { borderRadius: 10, borderWidth: StyleSheet14.hairlineWidth, paddingHorizontal: 12, paddingVertical: 8, overflow: "hidden" },
|
|
3924
4045
|
titleRow: { flexDirection: "row", alignItems: "flex-start", gap: 8, height: TITLE_H - 8, marginBottom: 8 },
|
|
@@ -3933,7 +4054,7 @@ var styles14 = StyleSheet14.create({
|
|
|
3933
4054
|
});
|
|
3934
4055
|
|
|
3935
4056
|
// src/ui/inputs/InputForm.tsx
|
|
3936
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo10, useState as
|
|
4057
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo10, useState as useState12 } from "react";
|
|
3937
4058
|
import { Pressable as Pressable13, StyleSheet as StyleSheet15, Text as Text14, View as View14 } from "react-native";
|
|
3938
4059
|
import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
3939
4060
|
var NO_CHOICES = {};
|
|
@@ -3972,13 +4093,13 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
3972
4093
|
const panels = useMemo10(() => plainInputPanels(dashboard), [dashboard]);
|
|
3973
4094
|
const groups = useMemo10(() => inputGroups(dashboard), [dashboard]);
|
|
3974
4095
|
const saved = useMemo10(() => editing ? savedValues(panels, editing) : NO_DEFAULTS, [panels, editing]);
|
|
3975
|
-
const [defaults, setDefaults] =
|
|
3976
|
-
const [edits, setEdits] =
|
|
3977
|
-
const [last, setLast] =
|
|
3978
|
-
const [groupEdits, setGroupEdits] =
|
|
3979
|
-
const [offsetMs, setOffsetMs] =
|
|
3980
|
-
const [status, setStatus] =
|
|
3981
|
-
const [checked, setChecked] =
|
|
4096
|
+
const [defaults, setDefaults] = useState12({});
|
|
4097
|
+
const [edits, setEdits] = useState12({});
|
|
4098
|
+
const [last, setLast] = useState12({});
|
|
4099
|
+
const [groupEdits, setGroupEdits] = useState12({});
|
|
4100
|
+
const [offsetMs, setOffsetMs] = useState12(0);
|
|
4101
|
+
const [status, setStatus] = useState12(null);
|
|
4102
|
+
const [checked, setChecked] = useState12(false);
|
|
3982
4103
|
useEffect4(() => {
|
|
3983
4104
|
let run = 0;
|
|
3984
4105
|
const load = async () => {
|
|
@@ -4023,7 +4144,7 @@ function InputForm({ dashboard, store, onSaved, choices = NO_CHOICES, header, ti
|
|
|
4023
4144
|
const p = panels.find((x) => x.options.metric === m);
|
|
4024
4145
|
return p && (checked || m in edits) ? inputProblem(p, value(m)) : void 0;
|
|
4025
4146
|
},
|
|
4026
|
-
group: (g) => groupState(g, itemsOf(g), last[groupKey(g)],
|
|
4147
|
+
group: (g) => groupState(g, itemsOf(g), last[groupKey(g)], groupKey(g) in groupEdits, checked, (update) => {
|
|
4027
4148
|
setStatus(null);
|
|
4028
4149
|
setGroupEdits((all) => ({ ...all, [groupKey(g)]: update(all[groupKey(g)] ?? base[groupKey(g)] ?? []) }));
|
|
4029
4150
|
})
|
|
@@ -4106,7 +4227,7 @@ function groupChanges(base, items) {
|
|
|
4106
4227
|
const moved = edited + added + removed === 0 && items.some((i, n) => base[n]?.key !== i.key) ? 1 : 0;
|
|
4107
4228
|
return edited + added + removed + moved;
|
|
4108
4229
|
}
|
|
4109
|
-
function groupState(group, items, last, showProblems, update) {
|
|
4230
|
+
function groupState(group, items, last, edited, showProblems, update) {
|
|
4110
4231
|
const fields = groupFields(group);
|
|
4111
4232
|
const { max } = group.options;
|
|
4112
4233
|
const fresh = (position) => ({ key: `n${nextItemKey++}`, values: freshItem(group, position, last), edited: [] });
|
|
@@ -4115,6 +4236,7 @@ function groupState(group, items, last, showProblems, update) {
|
|
|
4115
4236
|
return {
|
|
4116
4237
|
items: items.map((i) => ({ key: i.key, values: i.values, edited: i.edited })),
|
|
4117
4238
|
canAdd: typeof max !== "number" || items.length < max,
|
|
4239
|
+
edited,
|
|
4118
4240
|
problem: showProblems && typeof min === "number" && filled < min ? `At least ${min}` : void 0,
|
|
4119
4241
|
add: () => update((all) => typeof max === "number" && all.length >= max ? all : [...all, fresh(all.length)]),
|
|
4120
4242
|
duplicate: (index) => update(
|
|
@@ -4147,7 +4269,7 @@ async function replace(store, ids, entries) {
|
|
|
4147
4269
|
var HOUR = 36e5;
|
|
4148
4270
|
function TimestampPicker({ offsetMs, onChange }) {
|
|
4149
4271
|
const theme = useDashTheme();
|
|
4150
|
-
const [now, setNow] =
|
|
4272
|
+
const [now, setNow] = useState12(() => Date.now());
|
|
4151
4273
|
useEffect4(() => {
|
|
4152
4274
|
const id = setInterval(() => setNow(Date.now()), 3e4);
|
|
4153
4275
|
return () => clearInterval(id);
|
|
@@ -4277,6 +4399,7 @@ export {
|
|
|
4277
4399
|
getPath,
|
|
4278
4400
|
gridOffsetPx,
|
|
4279
4401
|
gridUnitsToPx,
|
|
4402
|
+
groupField,
|
|
4280
4403
|
groupFields,
|
|
4281
4404
|
groupKey,
|
|
4282
4405
|
groupProblems,
|
|
@@ -3,6 +3,10 @@ import { type InputGroupPanel } from '../../core/inputs';
|
|
|
3
3
|
* An input-group panel: a card per item with the group's fields, and buttons to add,
|
|
4
4
|
* duplicate, move and remove items. Each item's fields are the ordinary input components,
|
|
5
5
|
* reading and writing that item through a form context of their own.
|
|
6
|
+
*
|
|
7
|
+
* A card's title collapses it to a one-line summary; adding or duplicating an item
|
|
8
|
+
* collapses the other filled ones, and a card with a problem stays open. The handle (≡)
|
|
9
|
+
* drags a card past its neighbours to reorder.
|
|
6
10
|
*/
|
|
7
11
|
export declare function InputGroupBody({ panel }: {
|
|
8
12
|
panel: InputGroupPanel;
|
|
@@ -20,6 +20,8 @@ export interface FormGroup {
|
|
|
20
20
|
edited: string[];
|
|
21
21
|
}[];
|
|
22
22
|
canAdd: boolean;
|
|
23
|
+
/** Whether the group has changes since it was last saved or discarded. */
|
|
24
|
+
edited?: boolean;
|
|
23
25
|
/** Why the group as a whole can't be saved (too few items), once that's worth showing. */
|
|
24
26
|
problem?: string;
|
|
25
27
|
add(): void;
|
package/package.json
CHANGED