report-studio 1.2.0 → 1.2.2
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 +38 -2
- package/dist/{designer-qy59eEux.js → designer-DQlfKnTr.js} +928 -928
- package/dist/designer.js +1 -1
- package/dist/index.js +2 -2
- package/dist/react-designer.js +1 -1
- package/dist/react.js +2 -1
- package/dist/viewer-BSPNCNRU.js +2912 -0
- package/package.json +1 -1
- package/src/designer/index.html +1 -1
- package/src/designer/styles.css +31 -8
- package/src/engine/csv.js +12 -197
- package/src/engine/index.js +1 -0
- package/src/engine/rows.js +456 -0
- package/src/engine/xlsx-drawing.js +313 -0
- package/src/engine/xlsx-style.js +457 -0
- package/src/engine/xlsx.js +1200 -0
- package/src/engine/zip.js +138 -0
- package/src/index.html +1 -1
- package/src/index.js +5 -1
- package/src/preview/chrome.css +75 -12
- package/src/preview/chrome.js +69 -55
- package/src/preview/index.html +1 -1
- package/src/preview/viewer.js +42 -1
- package/src/react/index.js +3 -3
- package/src/shared/brand.css +3 -1
- package/src/shared/theme.css +15 -3
- package/types/index.d.ts +53 -0
- package/dist/viewer-xa17tyMJ.js +0 -1721
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "report-studio",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Visual report designer and paginated report viewer for the browser. Zero runtime dependencies; plain JS, React components and a Vite plugin.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
package/src/designer/index.html
CHANGED
package/src/designer/styles.css
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
@import "../shared/dropdown.css";
|
|
16
16
|
@import "../preview/chrome.css";
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
.report-designer {
|
|
19
19
|
--dz-bar-height: 56px;
|
|
20
20
|
/* wide enough for "reportHeader", the longest band name */
|
|
21
21
|
--dz-gutter: 96px;
|
|
@@ -25,11 +25,30 @@
|
|
|
25
25
|
--dz-foot-offset: 20px;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The designer fills the element it was given - a column of the bar and the
|
|
30
|
+
* row below it - so a host can put its own header above it. A mount with no
|
|
31
|
+
* height of its own (the CLI's page, a host that never set one) gets the
|
|
32
|
+
* window's instead: height: 100% has nothing to resolve against there, so the
|
|
33
|
+
* cap is what stops the designer growing to the length of the page.
|
|
34
|
+
*/
|
|
28
35
|
.report-designer {
|
|
29
|
-
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
height: 100%;
|
|
39
|
+
max-height: 100vh;
|
|
30
40
|
background-color: var(--backdrop);
|
|
31
41
|
}
|
|
32
42
|
|
|
43
|
+
/**
|
|
44
|
+
* A class outranks the browser's own [hidden] rule, so display: flex above
|
|
45
|
+
* would keep a designer on screen that its host had hidden - under the report,
|
|
46
|
+
* in a tabbed page that hides whichever screen is not chosen.
|
|
47
|
+
*/
|
|
48
|
+
.report-designer[hidden] {
|
|
49
|
+
display: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
53
|
* The designer takes the focus so its shortcuts have somewhere to arrive, but
|
|
35
54
|
* it is not a control - a ring around the whole screen would be saying that it
|
|
@@ -41,10 +60,14 @@
|
|
|
41
60
|
|
|
42
61
|
/* ---------------- the bar ---------------- */
|
|
43
62
|
|
|
63
|
+
/**
|
|
64
|
+
* In the column, not fixed to the window: fixed, it sat over whatever the host
|
|
65
|
+
* had at the top of its page - its own header, and the tabs to leave by.
|
|
66
|
+
*/
|
|
44
67
|
.dz-bar {
|
|
45
|
-
position:
|
|
46
|
-
inset: 0 0 auto 0;
|
|
68
|
+
position: relative;
|
|
47
69
|
z-index: 10;
|
|
70
|
+
flex: none;
|
|
48
71
|
|
|
49
72
|
display: flex;
|
|
50
73
|
align-items: center;
|
|
@@ -98,12 +121,12 @@
|
|
|
98
121
|
|
|
99
122
|
/* ---------------- the canvas ---------------- */
|
|
100
123
|
|
|
101
|
-
/* the bar
|
|
124
|
+
/* whatever height the bar leaves; the canvas and the rail scroll inside it */
|
|
102
125
|
.dz-body {
|
|
126
|
+
flex: 1;
|
|
127
|
+
min-height: 0;
|
|
103
128
|
display: flex;
|
|
104
129
|
align-items: stretch;
|
|
105
|
-
margin-top: var(--dz-bar-height);
|
|
106
|
-
height: calc(100vh - var(--dz-bar-height));
|
|
107
130
|
}
|
|
108
131
|
|
|
109
132
|
/**
|
|
@@ -299,7 +322,7 @@
|
|
|
299
322
|
|
|
300
323
|
/* ---------------- rulers and guides ---------------- */
|
|
301
324
|
|
|
302
|
-
|
|
325
|
+
.report-designer {
|
|
303
326
|
--dz-ruler: 18px;
|
|
304
327
|
}
|
|
305
328
|
|
package/src/engine/csv.js
CHANGED
|
@@ -14,9 +14,14 @@
|
|
|
14
14
|
* Spec 5.1: "extract table rows from the page list, download as a file", and
|
|
15
15
|
* spec 2.2 lists CSV export as a page-list consumer. So both read the built
|
|
16
16
|
* pages - the same thing the renderer draws - and never the layout or the raw
|
|
17
|
-
* data.
|
|
17
|
+
* data. Reading them is rows.js, shared with the XLSX export; this file is only
|
|
18
|
+
* the encoding.
|
|
18
19
|
*/
|
|
19
20
|
|
|
21
|
+
import { reportRows, tableRows, columnLabel } from './rows.js';
|
|
22
|
+
|
|
23
|
+
export { reportTables } from './rows.js';
|
|
24
|
+
|
|
20
25
|
|
|
21
26
|
/** cells starting with these are executed as formulas by Excel and Sheets */
|
|
22
27
|
const FORMULA_LEAD = /^[=+\-@\t\r]/;
|
|
@@ -48,11 +53,11 @@ export function toCSV(pages, options = {}) {
|
|
|
48
53
|
table: only = null
|
|
49
54
|
} = options;
|
|
50
55
|
|
|
51
|
-
const table =
|
|
56
|
+
const table = tableRows(pages, only);
|
|
52
57
|
if (!table) return '';
|
|
53
58
|
|
|
54
59
|
const grouped = groupColumn && table.rows.some(r => r.group !== null);
|
|
55
|
-
const labels = table.columns.map(
|
|
60
|
+
const labels = table.columns.map(columnLabel);
|
|
56
61
|
|
|
57
62
|
const lines = [];
|
|
58
63
|
|
|
@@ -102,134 +107,15 @@ export function toReportCSV(pages, options = {}) {
|
|
|
102
107
|
neutraliseFormulas = true
|
|
103
108
|
} = options;
|
|
104
109
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
for (const page of (pages ?? [])) {
|
|
108
|
-
for (const band of readingOrder(page?.bands)) collectBand(band, out);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (out.length === 0) return '';
|
|
110
|
+
const rows = reportRows(pages);
|
|
111
|
+
if (rows.length === 0) return '';
|
|
112
112
|
|
|
113
|
-
return
|
|
114
|
-
.map(cells => encodeRow(cells, delimiter, neutraliseFormulas))
|
|
113
|
+
return rows
|
|
114
|
+
.map(({ cells }) => encodeRow(cells, delimiter, neutraliseFormulas))
|
|
115
115
|
.join(newline);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
/**
|
|
120
|
-
* A page's bands, top of the paper first.
|
|
121
|
-
*
|
|
122
|
-
* The array they arrive in is the order they were built, which is not the order
|
|
123
|
-
* they are read: a page footer is anchored to the bottom edge and is often
|
|
124
|
-
* second in the list. `top` is the position the renderer places them at, so it
|
|
125
|
-
* is the only thing that knows.
|
|
126
|
-
*/
|
|
127
|
-
function readingOrder(bands) {
|
|
128
|
-
return [...(bands ?? [])].sort((a, b) => (a?.top ?? 0) - (b?.top ?? 0));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Adds a band's lines to the output.
|
|
134
|
-
*
|
|
135
|
-
* Items are sorted down the band and then across it, and neighbours that share
|
|
136
|
-
* a line are written as one row - so a caption and the figure beside it arrive
|
|
137
|
-
* as two cells rather than as two rows, which is how the band was designed to
|
|
138
|
-
* be read.
|
|
139
|
-
*
|
|
140
|
-
* @param {object} band
|
|
141
|
-
* @param {Array[]} out gathered rows, appended to
|
|
142
|
-
*/
|
|
143
|
-
function collectBand(band, out) {
|
|
144
|
-
const drawn = (band?.items ?? [])
|
|
145
|
-
.filter(item => item?.type === 'text' || item?.type === 'table')
|
|
146
|
-
.sort((a, b) => (a.y ?? 0) - (b.y ?? 0) || (a.x ?? 0) - (b.x ?? 0));
|
|
147
|
-
|
|
148
|
-
/** the run of text items being gathered, and the item that anchors its line */
|
|
149
|
-
let line = null;
|
|
150
|
-
const flush = () => {
|
|
151
|
-
if (line) out.push(line.cells);
|
|
152
|
-
line = null;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
for (const item of drawn) {
|
|
156
|
-
if (item.type === 'table') {
|
|
157
|
-
flush();
|
|
158
|
-
collectTable(item, out);
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (line && sameLine(line.anchor, item)) {
|
|
163
|
-
line.cells.push(item.text);
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
flush();
|
|
168
|
-
line = { anchor: item, cells: [item.text] };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
flush();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Whether two items are on the same line of the band.
|
|
177
|
-
*
|
|
178
|
-
* By overlap rather than by an equal y: a heading and the date beside it are
|
|
179
|
-
* set in different sizes, so they are placed a few pixels apart and still read
|
|
180
|
-
* as one line. Half the shorter item is the threshold - enough that a genuine
|
|
181
|
-
* second line, which clears the first, is never folded into it.
|
|
182
|
-
*
|
|
183
|
-
* Measured against the item that opened the line rather than against the line
|
|
184
|
-
* as it grows, so one tall item cannot go on absorbing everything under it.
|
|
185
|
-
*/
|
|
186
|
-
function sameLine(anchor, item) {
|
|
187
|
-
const span = (i) => {
|
|
188
|
-
const top = i.y ?? 0;
|
|
189
|
-
return [top, top + (i.measuredHeight ?? i.h ?? 0)];
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const [aTop, aBottom] = span(anchor);
|
|
193
|
-
const [bTop, bBottom] = span(item);
|
|
194
|
-
const overlap = Math.min(aBottom, bBottom) - Math.max(aTop, bTop);
|
|
195
|
-
|
|
196
|
-
return overlap >= Math.min(aBottom - aTop, bBottom - bTop) / 2;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Adds a table's rows to the output, in the order items.js draws them.
|
|
202
|
-
*
|
|
203
|
-
* The grouped shape repeats the column labels for every group that starts one,
|
|
204
|
-
* and wraps each fragment's rows in the group's own header and footer bands -
|
|
205
|
-
* which are bands, so they are written by the same code as any other.
|
|
206
|
-
*
|
|
207
|
-
* @param {object} table
|
|
208
|
-
* @param {Array[]} out
|
|
209
|
-
*/
|
|
210
|
-
function collectTable(table, out) {
|
|
211
|
-
const labels = () => table.columns.map(c => c.label ?? c.field);
|
|
212
|
-
const cells = (row) => table.columns.map(c => row?.[c.field]);
|
|
213
|
-
|
|
214
|
-
if (!table.groups) {
|
|
215
|
-
if (table.showHeader) out.push(labels());
|
|
216
|
-
for (const row of (table.row ?? [])) out.push(cells(row));
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
for (const fragment of table.groups) {
|
|
221
|
-
if (fragment.showHeader && table.showHeader) out.push(labels());
|
|
222
|
-
if (fragment.headerBand) collectBand(fragment.headerBand, out);
|
|
223
|
-
|
|
224
|
-
for (const row of fragment.rows) out.push(cells(row));
|
|
225
|
-
|
|
226
|
-
if (fragment.showFooter && fragment.footerBand) {
|
|
227
|
-
collectBand(fragment.footerBand, out);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
119
|
/**
|
|
234
120
|
* A filename for the download, derived from the layout's name.
|
|
235
121
|
* @param {object} paginated the buildPages result
|
|
@@ -246,77 +132,6 @@ export function reportFilename(paginated, extension = 'csv') {
|
|
|
246
132
|
}
|
|
247
133
|
|
|
248
134
|
|
|
249
|
-
/**
|
|
250
|
-
* The tables a built report holds, in the order they first appear - what a
|
|
251
|
-
* host offers when it asks which one to export with toCSV.
|
|
252
|
-
*
|
|
253
|
-
* Read from the pages rather than the layout, like everything in this file:
|
|
254
|
-
* a table split over three pages is listed once, by its id.
|
|
255
|
-
*
|
|
256
|
-
* @param {object[]} pages the `pages` array from buildPages
|
|
257
|
-
* @returns {{id: string, columns: string[]}[]}
|
|
258
|
-
*/
|
|
259
|
-
export function reportTables(pages) {
|
|
260
|
-
const found = new Map();
|
|
261
|
-
|
|
262
|
-
for (const page of (pages ?? [])) {
|
|
263
|
-
for (const band of (page.bands ?? [])) {
|
|
264
|
-
for (const item of (band.items ?? [])) {
|
|
265
|
-
if (item.type !== 'table' || found.has(item.id)) continue;
|
|
266
|
-
|
|
267
|
-
found.set(item.id, {
|
|
268
|
-
id: item.id,
|
|
269
|
-
columns: (item.columns ?? []).map(c => c.label ?? c.field)
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return [...found.values()];
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Walks the page list for one table, gathering its rows across every page and
|
|
281
|
-
* every group fragment.
|
|
282
|
-
* @param {object[]} pages
|
|
283
|
-
* @param {string|null} [only] the table's id; the first table met when absent
|
|
284
|
-
* @returns {{columns: object[], rows: {group: string|null, row: object}[]}|null}
|
|
285
|
-
*/
|
|
286
|
-
function collect(pages, only = null) {
|
|
287
|
-
let columns = null;
|
|
288
|
-
let id = only;
|
|
289
|
-
const rows = [];
|
|
290
|
-
|
|
291
|
-
for (const page of (pages ?? [])) {
|
|
292
|
-
for (const band of (page.bands ?? [])) {
|
|
293
|
-
for (const item of (band.items ?? [])) {
|
|
294
|
-
if (item.type !== 'table') continue;
|
|
295
|
-
if (id !== null && item.id !== id) continue;
|
|
296
|
-
|
|
297
|
-
if (columns === null) {
|
|
298
|
-
id = item.id;
|
|
299
|
-
columns = item.columns ?? [];
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (item.row) {
|
|
303
|
-
for (const row of item.row) rows.push({ group: null, row });
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
for (const fragment of (item.groups ?? [])) {
|
|
308
|
-
for (const row of fragment.rows) {
|
|
309
|
-
rows.push({ group: fragment.key, row });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return columns === null ? null : { columns, rows };
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
135
|
function encodeRow(cells, delimiter, neutraliseFormulas) {
|
|
321
136
|
return cells.map(cell => encodeCell(cell, delimiter, neutraliseFormulas)).join(delimiter);
|
|
322
137
|
}
|
package/src/engine/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { validateLayout, ReportError } from './validate.js';
|
|
|
19
19
|
export { search, searchPages } from './search.js';
|
|
20
20
|
export { pageRegions, bandZoneHeight, resolveHeight, DEFAULT_BAND_HEIGHTS } from './regions.js';
|
|
21
21
|
export { toCSV, toReportCSV, reportFilename, reportTables } from './csv.js';
|
|
22
|
+
export { toXLSX, toXLSXAsync, reportImageSources, XLSX_MIME } from './xlsx.js';
|
|
22
23
|
export { tablesOf, datasetOf, groupingOf } from './tables.js';
|
|
23
24
|
export { measureText, wrapLines, textHeight, LINE_HEIGHT_RATIO } from './text-metrics.js';
|
|
24
25
|
|