@modelform/react-native 0.2.0 → 0.3.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.
@@ -46,6 +46,8 @@ import {
46
46
  checkFiles,
47
47
  cleanDashboard,
48
48
  cleanPanelOptions,
49
+ collapseRow,
50
+ compactGrid,
49
51
  dashboardSchema,
50
52
  dashboardSchemaIssues,
51
53
  dashboardSourceIds,
@@ -73,6 +75,7 @@ import {
73
75
  framesToOptions,
74
76
  fromWire,
75
77
  getPath,
78
+ gridOffsetPx,
76
79
  gridUnitsToPx,
77
80
  httpFetchJson,
78
81
  initialVariableValues,
@@ -124,6 +127,7 @@ import {
124
127
  parseLocalDateTime,
125
128
  parseRange,
126
129
  parseTime,
130
+ placePanel,
127
131
  pointerToPath,
128
132
  prepareDashboard,
129
133
  queryPanel,
@@ -158,6 +162,8 @@ import {
158
162
  setOption,
159
163
  setOptionValue,
160
164
  setOverrides,
165
+ settleLayout,
166
+ snapToGrid,
161
167
  splitPath,
162
168
  startOf,
163
169
  stringifyCompact,
@@ -189,7 +195,7 @@ import {
189
195
  variableWithType,
190
196
  visibleVariables,
191
197
  zoomRange
192
- } from "../chunk-MRHC6AEU.mjs";
198
+ } from "../chunk-PU7RRUV4.mjs";
193
199
  export {
194
200
  ALL,
195
201
  BUNDLE_ACCEPT,
@@ -238,6 +244,8 @@ export {
238
244
  checkFiles,
239
245
  cleanDashboard,
240
246
  cleanPanelOptions,
247
+ collapseRow,
248
+ compactGrid,
241
249
  dashboardSchema,
242
250
  dashboardSchemaIssues,
243
251
  dashboardSourceIds,
@@ -265,6 +273,7 @@ export {
265
273
  framesToOptions,
266
274
  fromWire,
267
275
  getPath,
276
+ gridOffsetPx,
268
277
  gridUnitsToPx,
269
278
  httpFetchJson,
270
279
  initialVariableValues,
@@ -316,6 +325,7 @@ export {
316
325
  parseLocalDateTime,
317
326
  parseRange,
318
327
  parseTime,
328
+ placePanel,
319
329
  pointerToPath,
320
330
  prepareDashboard,
321
331
  queryPanel,
@@ -350,6 +360,8 @@ export {
350
360
  setOption,
351
361
  setOptionValue,
352
362
  setOverrides,
363
+ settleLayout,
364
+ snapToGrid,
353
365
  splitPath,
354
366
  startOf,
355
367
  stringifyCompact,
@@ -26,15 +26,48 @@ export interface LayoutRow {
26
26
  /** Height in grid units. */
27
27
  h: number;
28
28
  }
29
+ /** A panel placed on Grafana's grid, relative to the top of its section. */
30
+ export interface GridCell extends LayoutCell {
31
+ /** Column of the left edge, 0 to 23. */
32
+ x: number;
33
+ /** In grid units from the top of the section. */
34
+ y: number;
35
+ /** Columns wide; the same as `span`. */
36
+ w: number;
37
+ /** Height in grid units. */
38
+ h: number;
39
+ }
29
40
  export interface LayoutSection {
30
41
  key: string;
31
42
  /** The Grafana "row" panel heading this section, if any. */
32
43
  row?: Panel;
33
44
  collapsed: boolean;
45
+ /** Panels packed into lines in reading order: how phones show the section. */
34
46
  rows: LayoutRow[];
47
+ /** Panels where Grafana puts them, floated up: how wide screens show the section. */
48
+ grid: {
49
+ cells: GridCell[];
50
+ h: number;
51
+ };
35
52
  }
36
53
  /** Grafana's pixel height for h grid units. */
37
54
  export declare const gridUnitsToPx: (h: number) => number;
55
+ /** How far down y grid units starts, in pixels: each unit is a cell plus the gap under it. */
56
+ export declare const gridOffsetPx: (y: number) => number;
57
+ /** A rectangle on Grafana's grid, in columns and height units. */
58
+ export interface GridBox {
59
+ x: number;
60
+ y: number;
61
+ w: number;
62
+ h: number;
63
+ }
64
+ /**
65
+ * Grafana's vertical compaction. Boxes are taken top to bottom, then left to right; each floats
66
+ * up as far as it can, and one that overlaps a box already placed drops below it. Boxes listed
67
+ * in `fixed` are placed first, where they are, so the rest make way for them. Columns are
68
+ * snapped to whole units and kept on the grid. Returns new boxes, in the same order.
69
+ */
70
+ export declare function compactGrid(boxes: GridBox[], fixed?: ReadonlySet<number>): GridBox[];
38
71
  export declare const isRow: (p: Panel) => boolean;
39
72
  /** Current variable values and options; without them repeated rows and panels render once, unrepeated. */
40
73
  export interface RepeatContext {
@@ -1,11 +1,12 @@
1
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.
2
+ * The layout editor's model. Wide screens show panels where Grafana does: at their gridPos,
3
+ * floated up (see compactGrid in layout.ts). So editing the grid is placing and sizing panels,
4
+ * and after every change gridPos is rewritten to the floated-up layout, so the file (and
5
+ * Grafana) say what the app shows. Phones show panels in reading order, packed into lines;
6
+ * moving a panel there moves it in that order, which is still a place on the grid.
6
7
  *
7
8
  * 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
+ * from removing some), so the JSON text can be patched in place.
9
10
  */
10
11
  import { type JsonEdit } from './jsonEdit';
11
12
  import { type LayoutMode } from './layout';
@@ -13,8 +14,11 @@ import type { Panel } from './schema';
13
14
  /** Top-level panel indices (rows included) in the order the app shows them; ties keep file order. */
14
15
  export declare function readingOrder(panels: Panel[]): number[];
15
16
  /**
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.
17
+ * Rewrites gridPos x/y so that sorting by position gives `order`, packing each line by width.
18
+ * Sizes are kept. Returns new panels; untouched ones are the same objects.
19
+ *
20
+ * @deprecated Wide screens now show panels where their gridPos puts them, so packing into
21
+ * lines throws placement away. Use `settleLayout` to tidy a layout, `placePanel` to move one.
18
22
  */
19
23
  export declare function repack(panels: Panel[], order: number[]): Panel[];
20
24
  export interface CanvasItem {
@@ -39,11 +43,17 @@ export interface Canvas {
39
43
  }
40
44
  export declare const CANVAS_GAP = 8;
41
45
  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. */
46
+ /**
47
+ * One panel shown as it's being changed: a size while it's resized, in the units of the current
48
+ * mode, or (on the grid) a place while it's dragged. The other panels make way as they will.
49
+ */
43
50
  export interface SizeOverride {
44
51
  index: number;
45
- span: number;
46
- h: number;
52
+ span?: number;
53
+ h?: number;
54
+ /** Grid only: column and line of the top left. */
55
+ x?: number;
56
+ y?: number;
47
57
  }
48
58
  /** Sizes in the current mode: grid uses gridPos; phone uses `mobile`, falling back like the app does. */
49
59
  export declare function panelSize(panel: Panel, mode: LayoutMode): {
@@ -58,30 +68,63 @@ export declare function layoutCanvas(panels: Panel[], order: number[], mode: Lay
58
68
  * the pointer is over (left/right for panels, top/bottom for rows).
59
69
  */
60
70
  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. */
71
+ /**
72
+ * Moves `index` to just before `before` in reading order (or to the end), for phones, where
73
+ * order is all there is: it takes `before`'s place on the grid, which moves down to make way.
74
+ * The grid stays the source of truth, so panels beside the moved one can float up past
75
+ * `before` too; the moved panel always lands right before it.
76
+ */
62
77
  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. */
78
+ /** Resizes in the units of `mode`: gridPos w/h on the grid (panels in the way move down), mobile span/h on phones. */
64
79
  export declare function resizePanel(panels: Panel[], index: number, mode: LayoutMode, span: number, h: number): Panel[];
65
80
  /** Shows or hides a panel on phones. */
66
81
  export declare function setHiddenOnPhones(panels: Panel[], index: number, hidden: boolean): Panel[];
67
82
  /** One more than the largest panel id anywhere, collapsed rows included. */
68
83
  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. */
84
+ /**
85
+ * Adds a panel with a fresh id: beside `after` if it fits on the same line, else under it, or
86
+ * at the bottom without one. Panels in the way move down. Returns the panels and the new one's index.
87
+ */
70
88
  export declare function insertPanel(panels: Panel[], panel: Panel, after: number | null): {
71
89
  panels: Panel[];
72
90
  index: number;
73
91
  };
74
- /** A copy of a panel right after it. */
92
+ /** A copy of a panel beside or under it. */
75
93
  export declare function duplicatePanel(panels: Panel[], index: number): {
76
94
  panels: Panel[];
77
95
  index: number;
78
96
  };
79
- /** Removes a panel. A collapsed row takes the panels inside it along. */
97
+ /** Removes a panel; the panels below float up. A collapsed row takes the panels inside it along. */
80
98
  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. */
99
+ /**
100
+ * Expands a collapsed row: its panels move out to the top level, under it, as they were laid
101
+ * out inside it, and everything below moves down to make room. They're added at the end of
102
+ * the panels array so the rest of the file stays as it is.
103
+ */
82
104
  export declare function expandRow(panels: Panel[], index: number): Panel[];
105
+ /**
106
+ * Collapses a row: the panels under it, down to the next row, move inside it, and the panels
107
+ * below float up. Returns the panels and the indices that left the top level, for panelEdits.
108
+ */
109
+ export declare function collapseRow(panels: Panel[], index: number): {
110
+ panels: Panel[];
111
+ removed: number[];
112
+ };
113
+ /**
114
+ * Floats every panel up the way the app shows them, so the file says what the app shows. With
115
+ * `fixed`, that panel keeps its place (just moved or resized) and any it now covers move down
116
+ * first. Panels already in place are left as the same objects.
117
+ */
118
+ export declare function settleLayout(panels: Panel[], fixed?: number): Panel[];
119
+ /** Puts a panel with its top left at column x, line y; panels in the way move down, then everything floats up. */
120
+ export declare function placePanel(panels: Panel[], index: number, x: number, y: number): Panel[];
121
+ /** The grid cell a panel `w` columns wide would take with its top left at pixel (x, y) on a canvas `width` wide. */
122
+ export declare function snapToGrid(width: number, x: number, y: number, w: number): {
123
+ x: number;
124
+ y: number;
125
+ };
83
126
  /**
84
127
  * JSON edits that turn `before` into `after` (panel arrays from the ops above), with
85
128
  * `panels` patched element by element so the file keeps its formatting.
86
129
  */
87
- export declare function panelEdits(before: Panel[], after: Panel[], removed?: number): JsonEdit[];
130
+ export declare function panelEdits(before: Panel[], after: Panel[], removed?: number | number[]): JsonEdit[];