report-studio 1.2.3 → 1.3.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.
Files changed (53) hide show
  1. package/README.md +254 -3
  2. package/dist/designer-_sWqzOj8.js +5052 -0
  3. package/dist/designer.js +1 -1
  4. package/dist/index.js +2 -2
  5. package/dist/react-designer.js +1 -1
  6. package/dist/react.js +1 -1
  7. package/dist/viewer-4I7C1Rnd.js +4083 -0
  8. package/package.json +2 -2
  9. package/src/designer/blank.js +0 -1
  10. package/src/designer/canvas.js +172 -54
  11. package/src/designer/choice.js +368 -0
  12. package/src/designer/designer.js +342 -12
  13. package/src/designer/dialog.js +634 -6
  14. package/src/designer/fields.js +345 -36
  15. package/src/designer/geometry.js +77 -4
  16. package/src/designer/grouping.js +556 -0
  17. package/src/designer/icons.js +22 -0
  18. package/src/designer/menu.js +50 -6
  19. package/src/designer/panel.js +872 -69
  20. package/src/designer/rulers.js +14 -6
  21. package/src/designer/sample-data.js +112 -31
  22. package/src/designer/select.js +24 -3
  23. package/src/designer/structure.js +126 -12
  24. package/src/designer/styles.css +2017 -732
  25. package/src/designer/tokens.js +38 -11
  26. package/src/engine/calculate.js +487 -0
  27. package/src/engine/csv.js +17 -9
  28. package/src/engine/format.js +483 -0
  29. package/src/engine/group.js +350 -70
  30. package/src/engine/highlight.js +224 -0
  31. package/src/engine/index.js +8 -1
  32. package/src/engine/measure.js +53 -26
  33. package/src/engine/paginate.js +189 -92
  34. package/src/engine/resolve.js +117 -10
  35. package/src/engine/rows.js +71 -8
  36. package/src/engine/search.js +12 -4
  37. package/src/engine/tables.js +309 -11
  38. package/src/engine/validate.js +304 -8
  39. package/src/engine/xlsx-style.js +50 -4
  40. package/src/engine/xlsx.js +91 -21
  41. package/src/index.js +18 -0
  42. package/src/preview/chrome.css +302 -84
  43. package/src/preview/chrome.js +70 -58
  44. package/src/preview/viewer.js +137 -85
  45. package/src/render/items.js +61 -10
  46. package/src/render/report.css +0 -5
  47. package/src/shared/dropdown.css +78 -45
  48. package/src/shared/dropdown.js +105 -5
  49. package/src/shared/modal.css +78 -13
  50. package/types/index.d.ts +104 -9
  51. package/types/layout.d.ts +164 -2
  52. package/dist/designer-DQlfKnTr.js +0 -3416
  53. package/dist/viewer-BSPNCNRU.js +0 -2912
package/types/layout.d.ts CHANGED
@@ -26,6 +26,67 @@ export type RuleStyle = LineStyle | 'none';
26
26
 
27
27
  export type ImageFit = 'contain' | 'cover' | 'fill';
28
28
 
29
+ export type FormatType = 'text' | 'number' | 'currency' | 'percent' | 'date' | 'datetime';
30
+
31
+ /**
32
+ * How values print, and how a workbook shows them. Every key is optional; what
33
+ * a format leaves unsaid comes from the report's own `format`, then from the
34
+ * neutral defaults: international digit groups, no symbol, ISO dates.
35
+ */
36
+ export interface FormatDefaults {
37
+ /** places after the point, 0 to 6; default 2 */
38
+ decimals?: number;
39
+ /** 1,234,567 | 12,34,567 | 1234567; default 'international' */
40
+ grouping?: 'international' | 'indian' | 'none';
41
+ /** -1,234 | (1,234) | 1,234-; default 'minus' */
42
+ negative?: 'minus' | 'brackets' | 'trailing';
43
+ /** 0.00 | - | nothing; default 'zero' */
44
+ zero?: 'zero' | 'dash' | 'blank';
45
+ /** what a currency format prints with it, such as '₹'; default none */
46
+ symbol?: string;
47
+ /** default 'before' */
48
+ symbolPosition?: 'before' | 'after';
49
+ /**
50
+ * a date's layout from yyyy yy MMMM MMM MM M dd d HH H hh h mm ss a;
51
+ * default 'yyyy-MM-dd'
52
+ */
53
+ pattern?: string;
54
+ }
55
+
56
+ /** what a highlight rule tests for */
57
+ export type HighlightOp =
58
+ | '=' | '!=' | '<' | '<=' | '>' | '>=' | 'between'
59
+ | 'contains' | 'startsWith' | 'empty' | 'notEmpty';
60
+
61
+ /**
62
+ * One conditional formatting rule. Rules are checked in order and the first
63
+ * that holds is used. Numbers compare as numbers, dates by their day, and
64
+ * text without regard to case; a word never orders against a number.
65
+ */
66
+ export interface HighlightRule {
67
+ when: {
68
+ /** a field of the row, or of the data for a text item; the value itself when absent */
69
+ field?: string;
70
+ op: HighlightOp;
71
+ value?: string | number;
72
+ /** the upper end, for 'between'; both ends are included */
73
+ to?: string | number;
74
+ };
75
+ /** only what is named changes */
76
+ style: {
77
+ color?: string;
78
+ background?: string;
79
+ fontWeight?: string;
80
+ fontStyle?: string;
81
+ };
82
+ }
83
+
84
+ /** a text item's or a column's format */
85
+ export interface ValueFormat extends FormatDefaults {
86
+ /** 'text', or none, prints a value as it comes */
87
+ type: FormatType;
88
+ }
89
+
29
90
  export interface Margin {
30
91
  top: number;
31
92
  right: number;
@@ -37,7 +98,15 @@ export interface Margin {
37
98
  export interface PageSetup {
38
99
  width: number;
39
100
  height: number;
101
+ /** the margins that print; a side switched off is 0 here */
40
102
  margin: Margin;
103
+ /**
104
+ * The margins switched off in the designer, each with the value it comes
105
+ * back as when switched on again. Absent when every margin is on.
106
+ */
107
+ marginOff?: Partial<Margin>;
108
+ /** the designer's lock: a value typed into one side is written to all four */
109
+ marginLinked?: boolean;
41
110
  [key: string]: unknown;
42
111
  }
43
112
 
@@ -68,6 +137,10 @@ export interface TextItem extends ItemBase {
68
137
  /** literal text and `{placeholders}`, such as `Total: {sum(amount)}` */
69
138
  value: string;
70
139
  style?: TextStyle;
140
+ /** how the values its placeholders stand for print */
141
+ format?: ValueFormat | null;
142
+ /** styles the item by the one value it prints, or by a field of the data */
143
+ highlight?: HighlightRule[] | null;
71
144
  }
72
145
 
73
146
  export interface TableColumn {
@@ -76,6 +149,16 @@ export interface TableColumn {
76
149
  label?: string;
77
150
  width?: number;
78
151
  align?: Align;
152
+ /**
153
+ * Makes this a calculated column: worked out for each row and stored under
154
+ * `field`, e.g. `{qty} * {price}`, `round({amount} * 0.18, 2)` or
155
+ * `percentage({amount}, group)`.
156
+ */
157
+ expression?: string | null;
158
+ /** how this column's values print; the workbook keeps them as numbers and dates */
159
+ format?: ValueFormat | null;
160
+ /** styles each cell by its value, or by another field of its row */
161
+ highlight?: HighlightRule[] | null;
79
162
  [key: string]: unknown;
80
163
  }
81
164
 
@@ -95,10 +178,24 @@ export interface TableItem extends ItemBase {
95
178
  showHeader?: boolean;
96
179
  /** the dataset this table reads rows from; the layout's when absent */
97
180
  dataset?: string | null;
98
- /** group this table's rows by a field. One table per report may */
181
+ /**
182
+ * How this table's rows are grouped: the field, and the bands each group
183
+ * is drawn with. Outermost level first; each further level groups within
184
+ * the groups of the one before - by region, then by city. Each level
185
+ * groups by a different field. Any number of tables in a report may be
186
+ * grouped.
187
+ */
188
+ grouping?: GroupLevel[] | null;
189
+ /**
190
+ * The older way to group: by this field, drawn with the report's own
191
+ * groupHeader and groupFooter bands, so only one table may use it.
192
+ * Read for layouts that have it; prefer `grouping`.
193
+ */
99
194
  groupBy?: string | null;
100
195
  /** false keeps each cell to one line with an ellipsis */
101
196
  wrap?: boolean;
197
+ /** styles whole rows by a field of the row; a column's own rules go on top */
198
+ rowHighlight?: HighlightRule[] | null;
102
199
  style?: TableStyle;
103
200
  }
104
201
 
@@ -137,6 +234,38 @@ export interface ImageItem extends ItemBase {
137
234
 
138
235
  export type ReportItem = TextItem | TableItem | LineItem | BoxItem | ImageItem;
139
236
 
237
+ /**
238
+ * A band drawn once per group, inside the table it belongs to. Any item but a
239
+ * table. A group band's `{field}` reads the group's rows, and its
240
+ * `{sum(field)}` totals that group alone.
241
+ */
242
+ export interface GroupBand {
243
+ /** a colour the band is shaded with, across the table's width */
244
+ background?: string | null;
245
+ /** pixels; grows to fit what is in it */
246
+ height?: number;
247
+ items: Array<TextItem | LineItem | BoxItem | ImageItem>;
248
+ [key: string]: unknown;
249
+ }
250
+
251
+ /** one level of a table's grouping */
252
+ export interface GroupLevel {
253
+ /** the row field whose value decides which group a row is in */
254
+ by: string;
255
+ /** drawn above each group's rows; at least one of header and footer */
256
+ header?: GroupBand | null;
257
+ /** drawn under each group's last row */
258
+ footer?: GroupBand | null;
259
+ /**
260
+ * the order of this level's groups, by their value; numbers sort as
261
+ * numbers. Absent or null keeps the order the values are first seen in
262
+ */
263
+ sort?: 'asc' | 'desc' | null;
264
+ /** start each of this level's groups, after the table's first, on a new page */
265
+ newPage?: boolean;
266
+ [key: string]: unknown;
267
+ }
268
+
140
269
  export interface Band {
141
270
  type: BandType;
142
271
  /** pixels, or a percentage of the printable height such as `'10%'` */
@@ -152,8 +281,14 @@ export interface Layout {
152
281
  page: PageSetup;
153
282
  /** the dataset tables read from when they name none of their own */
154
283
  dataset?: string | null;
155
- /** group the first table's rows by this field */
284
+ /**
285
+ * The older way to group: the first table's rows by this field, drawn
286
+ * with the report's groupHeader and groupFooter bands. Prefer a table's
287
+ * own `grouping`.
288
+ */
156
289
  groupBy?: string | null;
290
+ /** what every item's and column's format falls back on */
291
+ format?: FormatDefaults | null;
157
292
  bands: Band[];
158
293
  [key: string]: unknown;
159
294
  }
@@ -164,6 +299,33 @@ export interface Layout {
164
299
  */
165
300
  export type ReportData = Record<string, unknown>;
166
301
 
302
+ /**
303
+ * One group's rows on one page - an entry of a built table's `groups`. For a
304
+ * table grouped at more than one level it is one of the innermost groups, with
305
+ * the bands of every outer group it starts or ends.
306
+ */
307
+ export interface GroupFragment {
308
+ /** the innermost level's group key */
309
+ key: string;
310
+ /** the group key at every level, outermost first */
311
+ path: string[];
312
+ rows: Array<Record<string, unknown>>;
313
+ rowHeights: number[];
314
+ /** whether the table's column labels head this fragment */
315
+ showHeader: boolean;
316
+ /** whether this fragment holds its group's last row */
317
+ showFooter: boolean;
318
+ /** group headers drawn over the rows, outermost first, each with its `level` */
319
+ headerBands: Array<GroupBand & { level: number }>;
320
+ /** group footers drawn under them, innermost first, each with its `level` */
321
+ footerBands: Array<GroupBand & { level: number }>;
322
+ /** the innermost level's header, when drawn here */
323
+ headerBand: (GroupBand & { level: number }) | null;
324
+ /** the innermost level's footer, when drawn here */
325
+ footerBand: (GroupBand & { level: number }) | null;
326
+ [key: string]: unknown;
327
+ }
328
+
167
329
  /** one page of a built report */
168
330
  export interface Page {
169
331
  /** 1-based */