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