report-studio 1.0.0 → 1.2.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/LICENSE +21 -21
- package/README.md +171 -22
- package/dist/designer-qy59eEux.js +3416 -0
- package/dist/designer.js +2 -3209
- package/dist/index.js +2 -2
- package/dist/react-designer.js +41 -0
- package/dist/react.js +60 -0
- package/dist/{viewer-D-c0lKzQ.js → viewer-xa17tyMJ.js} +682 -537
- package/package.json +105 -66
- package/src/cli/serve.js +135 -135
- package/src/designer/designer.js +2054 -1900
- package/src/designer/dialog.js +708 -708
- package/src/designer/fields.js +51 -2
- package/src/designer/icons.js +5 -0
- package/src/designer/index.html +28 -28
- package/src/designer/main.js +39 -39
- package/src/designer/menu.js +2 -2
- package/src/designer/panel.js +21 -1
- package/src/designer/sample-data.js +180 -9
- package/src/designer/structure.js +87 -6
- package/src/designer/styles.css +1654 -1616
- package/src/designer/tokens.js +9 -0
- package/src/engine/csv.js +350 -315
- package/src/engine/group.js +128 -65
- package/src/engine/index.js +35 -34
- package/src/engine/measure.js +13 -12
- package/src/engine/paginate.js +8 -4
- package/src/engine/resolve.js +37 -0
- package/src/engine/tables.js +87 -0
- package/src/engine/validate.js +97 -22
- package/src/index.html +79 -79
- package/src/index.js +51 -50
- package/src/preview/chrome.css +505 -505
- package/src/preview/chrome.js +147 -147
- package/src/preview/index.html +28 -28
- package/src/preview/viewer.js +763 -745
- package/src/react/designer.js +87 -0
- package/src/react/index.js +117 -0
- package/src/render/items.js +94 -1
- package/src/render/report.css +30 -0
- package/src/server/routes.js +331 -331
- package/src/shared/brand.css +29 -29
- package/src/shared/dropdown.css +136 -136
- package/src/shared/modal.css +125 -125
- package/src/shared/store.js +145 -145
- package/src/shared/theme.css +72 -72
- package/src/shared/window.js +138 -138
- package/types/designer.d.ts +85 -0
- package/types/index.d.ts +204 -0
- package/types/layout.d.ts +179 -0
- package/types/react-designer.d.ts +29 -0
- package/types/react.d.ts +30 -0
- package/types/vite.d.ts +18 -0
package/src/engine/validate.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
import { tablesOf, hasOwnGrouping } from './tables.js';
|
|
11
|
+
import { designHeight } from './measure.js';
|
|
12
|
+
|
|
13
|
+
|
|
10
14
|
const BAND_TYPES = [
|
|
11
15
|
'reportHeader',
|
|
12
16
|
'pageHeader',
|
|
@@ -17,7 +21,7 @@ const BAND_TYPES = [
|
|
|
17
21
|
'pageFooter'
|
|
18
22
|
];
|
|
19
23
|
|
|
20
|
-
const ITEM_TYPES = ['text', 'table', 'line', 'box'];
|
|
24
|
+
const ITEM_TYPES = ['text', 'table', 'line', 'box', 'image'];
|
|
21
25
|
|
|
22
26
|
/** spec 3.3: a line runs along one axis; which one is the item's to say */
|
|
23
27
|
const LINE_ORIENTATIONS = ['horizontal', 'vertical'];
|
|
@@ -28,6 +32,9 @@ const LINE_STYLES = ['solid', 'dashed', 'dotted', 'double'];
|
|
|
28
32
|
/** a table's grid may also be turned off, which a line cannot be */
|
|
29
33
|
const RULE_STYLES = [...LINE_STYLES, 'none'];
|
|
30
34
|
|
|
35
|
+
/** how a picture is fitted to its box: the three object-fit values that mean something here */
|
|
36
|
+
export const IMAGE_FITS = ['contain', 'cover', 'fill'];
|
|
37
|
+
|
|
31
38
|
|
|
32
39
|
/** Thrown for a layout the engine cannot work with. */
|
|
33
40
|
export class ReportError extends Error {
|
|
@@ -98,45 +105,79 @@ export function validateLayout(json) {
|
|
|
98
105
|
issues.push('layout.groupBy is set but there is no groupHeader or groupFooter band to show it');
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
|
|
108
|
+
validateTables(json, json.bands, issues);
|
|
102
109
|
|
|
103
110
|
return issues;
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
|
|
107
114
|
/**
|
|
108
|
-
*
|
|
115
|
+
* What the tables of a report may be, together.
|
|
109
116
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* designer drew sample rows in both, the validator passed it, and the fault
|
|
113
|
-
* only showed up in the printed report.
|
|
117
|
+
* Any number of them, each bound to its own dataset - but two things they may
|
|
118
|
+
* not do, because the engine has no honest way to print them:
|
|
114
119
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* one splittable item per band in paginate.js, and an answer for what a CSV
|
|
119
|
-
* export of two tables means. Until then this is the honest boundary, and it is
|
|
120
|
-
* one function to delete when that lands.
|
|
120
|
+
* Two grouped tables. groupHeader and groupFooter are the report's bands, so
|
|
121
|
+
* both tables would draw their groups with the same heading - and a subtotal
|
|
122
|
+
* in it would be summed over whichever table happened to be drawn.
|
|
121
123
|
*
|
|
124
|
+
* Two tables side by side. Each table splits across pages on its own, so the
|
|
125
|
+
* one on the left would run to page three before the one on the right began,
|
|
126
|
+
* and began on page three. Tables in one band are stacked: each starts below
|
|
127
|
+
* where the one above it was designed to end, and the engine moves it down
|
|
128
|
+
* by however far the rows above really ran.
|
|
129
|
+
*
|
|
130
|
+
* @param {object} json the layout
|
|
122
131
|
* @param {object[]} bands
|
|
123
132
|
* @param {string[]} issues
|
|
124
133
|
*/
|
|
125
|
-
function
|
|
126
|
-
const tables =
|
|
134
|
+
function validateTables(json, bands, issues) {
|
|
135
|
+
const tables = tablesOf(json);
|
|
127
136
|
|
|
128
|
-
for (const
|
|
129
|
-
if (
|
|
137
|
+
for (const table of tables) {
|
|
138
|
+
if (table.groupBy != null && typeof table.groupBy !== 'string') {
|
|
139
|
+
issues.push(`table "${table.id}".groupBy must be a field name or null`);
|
|
140
|
+
}
|
|
130
141
|
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
if (table.dataset != null && typeof table.dataset !== 'string') {
|
|
143
|
+
issues.push(`table "${table.id}".dataset must be a dataset name or null`);
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
|
|
136
|
-
|
|
147
|
+
const grouped = tables.filter(hasOwnGrouping);
|
|
148
|
+
|
|
149
|
+
if (grouped.length > 1) {
|
|
137
150
|
issues.push(
|
|
138
|
-
|
|
139
|
-
`a report
|
|
151
|
+
`${grouped.length} tables are grouped (${grouped.map(t => `"${t.id}"`).join(', ')}); ` +
|
|
152
|
+
`a report groups one, because groupHeader and groupFooter are shared`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (grouped.length > 0 && json.groupBy == null
|
|
156
|
+
&& !bands.some(b => b?.type === 'groupHeader' || b?.type === 'groupFooter')) {
|
|
157
|
+
issues.push(
|
|
158
|
+
`table "${grouped[0].id}" is grouped by "${grouped[0].groupBy}" but there is ` +
|
|
159
|
+
`no groupHeader or groupFooter band to show it`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const band of bands) {
|
|
163
|
+
if (!Array.isArray(band?.items)) continue;
|
|
164
|
+
|
|
165
|
+
const stack = band.items
|
|
166
|
+
.filter(item => item?.type === 'table')
|
|
167
|
+
.map(item => ({ item, top: Number(item.y) || 0, bottom: (Number(item.y) || 0) + designHeight(item) }))
|
|
168
|
+
.sort((a, b) => a.top - b.top);
|
|
169
|
+
|
|
170
|
+
for (let i = 1; i < stack.length; i++) {
|
|
171
|
+
const above = stack[i - 1];
|
|
172
|
+
const below = stack[i];
|
|
173
|
+
|
|
174
|
+
if (below.top < above.bottom) {
|
|
175
|
+
issues.push(
|
|
176
|
+
`tables "${above.item.id}" and "${below.item.id}" overlap in the ${band.type} band; ` +
|
|
177
|
+
`move "${below.item.id}" to y ${Math.ceil(above.bottom)} or lower - tables are ` +
|
|
178
|
+
`stacked, one under another, not placed side by side`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
140
181
|
}
|
|
141
182
|
}
|
|
142
183
|
|
|
@@ -203,6 +244,11 @@ function validateItem(item, where, issues) {
|
|
|
203
244
|
return;
|
|
204
245
|
}
|
|
205
246
|
|
|
247
|
+
if (item.type === 'image') {
|
|
248
|
+
validateImage(item, where, issues);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
206
252
|
/** table */
|
|
207
253
|
if (!(typeof item.rowHeight === 'number' && item.rowHeight > 0)) {
|
|
208
254
|
issues.push(`${where}.rowHeight must be a positive number`);
|
|
@@ -268,6 +314,35 @@ function validateBox(item, where, issues) {
|
|
|
268
314
|
}
|
|
269
315
|
|
|
270
316
|
|
|
317
|
+
/**
|
|
318
|
+
* An image is a fixed box with a picture in it: `src` is one stored in the
|
|
319
|
+
* layout, `field` is a path into the data whose value is the picture's URL.
|
|
320
|
+
*
|
|
321
|
+
* Neither is required. A freshly drawn image has no picture yet, and an empty
|
|
322
|
+
* frame is a layout the designer has to be able to save - it prints nothing,
|
|
323
|
+
* the way a text box with an empty value does. Whether a URL is one the page
|
|
324
|
+
* will actually load is the renderer's question, not this one: a layout can be
|
|
325
|
+
* valid and its data still point somewhere a report should not go.
|
|
326
|
+
*/
|
|
327
|
+
function validateImage(item, where, issues) {
|
|
328
|
+
if (item.src != null && typeof item.src !== 'string') {
|
|
329
|
+
issues.push(`${where}.src must be a string - a URL or a data: URI`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (item.field != null && typeof item.field !== 'string') {
|
|
333
|
+
issues.push(`${where}.field must be a data path such as "company.logo"`);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (item.fit != null && !IMAGE_FITS.includes(item.fit)) {
|
|
337
|
+
issues.push(`${where}.fit "${item.fit}" is not one of: ${IMAGE_FITS.join(', ')}`);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (item.alt != null && typeof item.alt !== 'string') {
|
|
341
|
+
issues.push(`${where}.alt must be a string`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
|
|
271
346
|
/**
|
|
272
347
|
* A line carries no content, so what there is to get wrong is its direction and
|
|
273
348
|
* its pen. Both are optional in the file - a bare `{type: "line"}` draws a
|
package/src/index.html
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>Report Studio</title>
|
|
8
|
-
<link rel="icon" type="image/png" href="./asset/images/icon.png">
|
|
9
|
-
<link rel="stylesheet" href="./shared/theme.css">
|
|
10
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
11
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
12
|
-
<link
|
|
13
|
-
href="https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700&family=Instrument+Sans:ital,wght@0,400..700&display=swap"
|
|
14
|
-
rel="stylesheet">
|
|
15
|
-
<style>
|
|
16
|
-
body {
|
|
17
|
-
min-height: 100vh;
|
|
18
|
-
display: grid;
|
|
19
|
-
place-content: center;
|
|
20
|
-
gap: 20px;
|
|
21
|
-
background: var(--backdrop);
|
|
22
|
-
font-family: "Instrument Sans", system-ui, sans-serif;
|
|
23
|
-
color: var(--ink);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/* the wordmark stands in for the heading; the text stays for readers */
|
|
27
|
-
h1 {
|
|
28
|
-
height: 26px;
|
|
29
|
-
width: calc(26px * var(--brand-logo-ratio));
|
|
30
|
-
|
|
31
|
-
background-image: var(--brand-logo);
|
|
32
|
-
background-repeat: no-repeat;
|
|
33
|
-
background-position: left center;
|
|
34
|
-
background-size: contain;
|
|
35
|
-
|
|
36
|
-
text-indent: -9999px;
|
|
37
|
-
overflow: hidden;
|
|
38
|
-
white-space: nowrap;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
p {
|
|
42
|
-
color: var(--ink-soft);
|
|
43
|
-
font-size: 13px;
|
|
44
|
-
max-width: 40ch;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
nav {
|
|
48
|
-
display: flex;
|
|
49
|
-
gap: 12px;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
a {
|
|
53
|
-
padding: 10px 18px;
|
|
54
|
-
background: var(--surface);
|
|
55
|
-
border: 1px solid var(--border);
|
|
56
|
-
border-radius: 6px;
|
|
57
|
-
color: var(--ink);
|
|
58
|
-
text-decoration: none;
|
|
59
|
-
font-size: 14px;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
a:hover {
|
|
63
|
-
border-color: var(--accent);
|
|
64
|
-
background: var(--accent-soft);
|
|
65
|
-
}
|
|
66
|
-
</style>
|
|
67
|
-
</head>
|
|
68
|
-
|
|
69
|
-
<body>
|
|
70
|
-
<h1>Report Studio</h1>
|
|
71
|
-
<p>The development playground. Both screens run straight from
|
|
72
|
-
<code>src/</code> with no build step.</p>
|
|
73
|
-
<nav>
|
|
74
|
-
<a href="./designer/">Designer</a>
|
|
75
|
-
<a href="./preview/">Preview</a>
|
|
76
|
-
</nav>
|
|
77
|
-
</body>
|
|
78
|
-
|
|
79
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Report Studio</title>
|
|
8
|
+
<link rel="icon" type="image/png" href="./asset/images/icon.png">
|
|
9
|
+
<link rel="stylesheet" href="./shared/theme.css">
|
|
10
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
11
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
12
|
+
<link
|
|
13
|
+
href="https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700&family=Instrument+Sans:ital,wght@0,400..700&display=swap"
|
|
14
|
+
rel="stylesheet">
|
|
15
|
+
<style>
|
|
16
|
+
body {
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
display: grid;
|
|
19
|
+
place-content: center;
|
|
20
|
+
gap: 20px;
|
|
21
|
+
background: var(--backdrop);
|
|
22
|
+
font-family: "Instrument Sans", system-ui, sans-serif;
|
|
23
|
+
color: var(--ink);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* the wordmark stands in for the heading; the text stays for readers */
|
|
27
|
+
h1 {
|
|
28
|
+
height: 26px;
|
|
29
|
+
width: calc(26px * var(--brand-logo-ratio));
|
|
30
|
+
|
|
31
|
+
background-image: var(--brand-logo);
|
|
32
|
+
background-repeat: no-repeat;
|
|
33
|
+
background-position: left center;
|
|
34
|
+
background-size: contain;
|
|
35
|
+
|
|
36
|
+
text-indent: -9999px;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
p {
|
|
42
|
+
color: var(--ink-soft);
|
|
43
|
+
font-size: 13px;
|
|
44
|
+
max-width: 40ch;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
nav {
|
|
48
|
+
display: flex;
|
|
49
|
+
gap: 12px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
a {
|
|
53
|
+
padding: 10px 18px;
|
|
54
|
+
background: var(--surface);
|
|
55
|
+
border: 1px solid var(--border);
|
|
56
|
+
border-radius: 6px;
|
|
57
|
+
color: var(--ink);
|
|
58
|
+
text-decoration: none;
|
|
59
|
+
font-size: 14px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
a:hover {
|
|
63
|
+
border-color: var(--accent);
|
|
64
|
+
background: var(--accent-soft);
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
67
|
+
</head>
|
|
68
|
+
|
|
69
|
+
<body>
|
|
70
|
+
<h1>Report Studio</h1>
|
|
71
|
+
<p>The development playground. Both screens run straight from
|
|
72
|
+
<code>src/</code> with no build step.</p>
|
|
73
|
+
<nav>
|
|
74
|
+
<a href="./designer/">Designer</a>
|
|
75
|
+
<a href="./preview/">Preview</a>
|
|
76
|
+
</nav>
|
|
77
|
+
</body>
|
|
78
|
+
|
|
79
|
+
</html>
|
package/src/index.js
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* report-studio - the package's main entry point.
|
|
3
|
-
*
|
|
4
|
-
* The engine and the viewer, and nothing that touches the document on import -
|
|
5
|
-
* so an application that only builds pages, or only renders them on a server,
|
|
6
|
-
* pays for nothing it does not use.
|
|
7
|
-
*
|
|
8
|
-
* The designer is a separate entry (`report-studio/designer`) because it is the
|
|
9
|
-
* larger half and most applications ship the reports rather than the tool that
|
|
10
|
-
* drew them. Each screen has a stylesheet of its own to link beside it:
|
|
11
|
-
* `report-studio/viewer.css` and `report-studio/designer.css`, or
|
|
12
|
-
* `report-studio/report.css` alone to draw a report with no chrome at all.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
buildPages,
|
|
17
|
-
resolve,
|
|
18
|
-
group,
|
|
19
|
-
measure,
|
|
20
|
-
paginate,
|
|
21
|
-
validateLayout,
|
|
22
|
-
ReportError,
|
|
23
|
-
search,
|
|
24
|
-
searchPages,
|
|
25
|
-
toCSV,
|
|
26
|
-
toReportCSV,
|
|
27
|
-
reportFilename,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
/**
|
|
2
|
+
* report-studio - the package's main entry point.
|
|
3
|
+
*
|
|
4
|
+
* The engine and the viewer, and nothing that touches the document on import -
|
|
5
|
+
* so an application that only builds pages, or only renders them on a server,
|
|
6
|
+
* pays for nothing it does not use.
|
|
7
|
+
*
|
|
8
|
+
* The designer is a separate entry (`report-studio/designer`) because it is the
|
|
9
|
+
* larger half and most applications ship the reports rather than the tool that
|
|
10
|
+
* drew them. Each screen has a stylesheet of its own to link beside it:
|
|
11
|
+
* `report-studio/viewer.css` and `report-studio/designer.css`, or
|
|
12
|
+
* `report-studio/report.css` alone to draw a report with no chrome at all.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
buildPages,
|
|
17
|
+
resolve,
|
|
18
|
+
group,
|
|
19
|
+
measure,
|
|
20
|
+
paginate,
|
|
21
|
+
validateLayout,
|
|
22
|
+
ReportError,
|
|
23
|
+
search,
|
|
24
|
+
searchPages,
|
|
25
|
+
toCSV,
|
|
26
|
+
toReportCSV,
|
|
27
|
+
reportFilename,
|
|
28
|
+
reportTables,
|
|
29
|
+
measureText,
|
|
30
|
+
wrapLines,
|
|
31
|
+
textHeight,
|
|
32
|
+
LINE_HEIGHT_RATIO
|
|
33
|
+
} from './engine/index.js';
|
|
34
|
+
|
|
35
|
+
export { render } from './render/render.js';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The viewer: paging, zoom, search, print and CSV over a page list.
|
|
39
|
+
*
|
|
40
|
+
* It takes one empty element and builds the rest, the same way createDesigner
|
|
41
|
+
* does. Link `report-studio/viewer.css` beside it - the report's own stylesheet
|
|
42
|
+
* is included there, so that one file is enough.
|
|
43
|
+
*/
|
|
44
|
+
export { createViewer, openViewerWindow } from './preview/viewer.js';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Opens a blank window with the host's stylesheets in it, ready to be mounted
|
|
48
|
+
* into - for a host that wants a screen of its own without using one of the
|
|
49
|
+
* two helpers above.
|
|
50
|
+
*/
|
|
51
|
+
export { openWindow } from './shared/window.js';
|