report-studio 1.2.2 → 1.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.
- package/README.md +254 -3
- package/dist/designer-Dj330bWd.js +4690 -0
- package/dist/designer.js +1 -1
- package/dist/index.js +2 -2
- package/dist/react-designer.js +1 -1
- package/dist/react.js +1 -1
- package/dist/viewer-BewnkhfP.js +4028 -0
- package/package.json +2 -2
- package/src/designer/blank.js +0 -1
- package/src/designer/canvas.js +172 -54
- package/src/designer/designer.js +313 -12
- package/src/designer/dialog.js +609 -5
- package/src/designer/fields.js +128 -11
- package/src/designer/geometry.js +77 -4
- package/src/designer/grouping.js +556 -0
- package/src/designer/icons.js +9 -0
- package/src/designer/menu.js +50 -6
- package/src/designer/panel.js +478 -38
- package/src/designer/rulers.js +14 -6
- package/src/designer/sample-data.js +112 -31
- package/src/designer/select.js +3 -2
- package/src/designer/structure.js +126 -12
- package/src/designer/styles.css +661 -27
- package/src/designer/tokens.js +38 -11
- package/src/engine/calculate.js +487 -0
- package/src/engine/csv.js +17 -9
- package/src/engine/format.js +483 -0
- package/src/engine/group.js +350 -70
- package/src/engine/highlight.js +224 -0
- package/src/engine/index.js +8 -1
- package/src/engine/measure.js +53 -26
- package/src/engine/paginate.js +189 -92
- package/src/engine/resolve.js +117 -10
- package/src/engine/rows.js +71 -8
- package/src/engine/search.js +12 -4
- package/src/engine/tables.js +309 -11
- package/src/engine/validate.js +265 -8
- package/src/engine/xlsx-style.js +50 -4
- package/src/engine/xlsx.js +91 -21
- package/src/index.js +18 -0
- package/src/render/items.js +61 -10
- package/src/render/report.css +0 -5
- package/types/index.d.ts +96 -8
- package/types/layout.d.ts +156 -2
- package/dist/designer-DQlfKnTr.js +0 -3416
- package/dist/viewer-BSPNCNRU.js +0 -2912
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "report-studio",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"build": "vite build",
|
|
76
76
|
"test": "vitest run",
|
|
77
77
|
"test:watch": "vitest",
|
|
78
|
-
"prepublishOnly": "npm run
|
|
78
|
+
"prepublishOnly": "npm run build && npm run test"
|
|
79
79
|
},
|
|
80
80
|
"bugs": {
|
|
81
81
|
"url": "https://report-studio-docs.vercel.app/report.html"
|
package/src/designer/blank.js
CHANGED
package/src/designer/canvas.js
CHANGED
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
* | pageHeader | anchored zones, from pageRegions()
|
|
17
17
|
* | reportHeader |
|
|
18
18
|
* | - - - - - - - - - - - |
|
|
19
|
-
* | groupHeader | the repeating unit, stacked inside
|
|
20
19
|
* | detail | whatever the detail region has left
|
|
21
|
-
* |
|
|
20
|
+
* | +- table -------+ |
|
|
21
|
+
* | | headings | |
|
|
22
|
+
* | | groupHeader | | a grouped table's own group bands, drawn
|
|
23
|
+
* | | rows | | inside it, where each group prints them
|
|
24
|
+
* | | groupFooter | |
|
|
25
|
+
* | +---------------+ |
|
|
22
26
|
* | - - - - - - - - - - - |
|
|
23
27
|
* | reportFooter |
|
|
24
28
|
* | pageFooter | pinned to the bottom edge
|
|
@@ -28,9 +32,10 @@
|
|
|
28
32
|
import { pageRegions, bandZoneHeight } from '../engine/regions.js';
|
|
29
33
|
import { items, esc } from '../render/items.js';
|
|
30
34
|
import {
|
|
31
|
-
SAMPLE_ROWS, designHeight, itemBox, resizableAxes, handlesFor
|
|
35
|
+
SAMPLE_ROWS, designHeight, itemBox, resizableAxes, handlesFor, levelStrips
|
|
32
36
|
} from './geometry.js';
|
|
33
37
|
import { ticksFor, guidesOf } from './rulers.js';
|
|
38
|
+
import { groupBandKey, bandLabel } from './grouping.js';
|
|
34
39
|
|
|
35
40
|
|
|
36
41
|
/** zones that own a strip of the page, drawn top to bottom */
|
|
@@ -59,9 +64,40 @@ function designItem(item) {
|
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
if (item.type === 'table') {
|
|
67
|
+
const strips = levelStrips(item);
|
|
68
|
+
|
|
69
|
+
if (!strips.length) {
|
|
70
|
+
return {
|
|
71
|
+
...item,
|
|
72
|
+
row: sampleRows(item.columns),
|
|
73
|
+
measuredHeight: designHeight(item)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A grouped table is drawn as one of its groups, through the same
|
|
79
|
+
* markup a printed group is - headings, group headers, rows, group
|
|
80
|
+
* footers; every level's, where a group that starts and ends every
|
|
81
|
+
* level draws them. The group bands are left empty here: each is drawn
|
|
82
|
+
* over its row as a zone of its own, so what is on it can be selected
|
|
83
|
+
* and dragged like anything on any other band.
|
|
84
|
+
*/
|
|
85
|
+
const room = (strip) => ({
|
|
86
|
+
height: strip.h, level: strip.level, items: [],
|
|
87
|
+
/** shaded as it will print, so the design shows where groups start */
|
|
88
|
+
background: strip.band?.background ?? null
|
|
89
|
+
});
|
|
90
|
+
const of = (kind) => strips.filter(s => s.kind === kind).map(room);
|
|
91
|
+
|
|
62
92
|
return {
|
|
63
93
|
...item,
|
|
64
|
-
|
|
94
|
+
groups: [{
|
|
95
|
+
showHeader: true,
|
|
96
|
+
showFooter: true,
|
|
97
|
+
headerBands: of('groupHeader'),
|
|
98
|
+
footerBands: of('groupFooter'),
|
|
99
|
+
rows: sampleRows(item.columns)
|
|
100
|
+
}],
|
|
65
101
|
measuredHeight: designHeight(item)
|
|
66
102
|
};
|
|
67
103
|
}
|
|
@@ -73,17 +109,31 @@ function designItem(item) {
|
|
|
73
109
|
/**
|
|
74
110
|
* Where every band sits on the design page, in printable-area coordinates.
|
|
75
111
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
112
|
+
* A table's group header and footer are drawn inside the table, once per group,
|
|
113
|
+
* so that is where they are designed: each is a zone of its own laid over the
|
|
114
|
+
* table, as wide as it is, between the column headings and the rows and below
|
|
115
|
+
* the rows. They move and resize with their table, and an item on one is as
|
|
116
|
+
* wide as it can print.
|
|
117
|
+
*
|
|
118
|
+
* A report's own groupHeader and groupFooter - which only a layout in the
|
|
119
|
+
* older form still has, once nothing is grouped by them - belong to no table,
|
|
120
|
+
* and are stacked at the top and bottom of the detail region as they always
|
|
121
|
+
* were, so they can be found and removed.
|
|
122
|
+
*
|
|
123
|
+
* A zone's `type` is the key the rest of the designer addresses its band by:
|
|
124
|
+
* the band type, or for a table's group band `groupHeader:<table id>` - which
|
|
125
|
+
* zone also carries as `kind`, `table` and the `label` the gutter shows.
|
|
126
|
+
* Every zone has a `left` and `width` as well as a `top` and `height`; a
|
|
127
|
+
* band zone runs the printable width, a table's group zone runs its table's.
|
|
80
128
|
*
|
|
81
129
|
* @param {object} layout
|
|
82
|
-
* @returns {object[]} `{ type, top, height, band }`, in draw order
|
|
130
|
+
* @returns {object[]} `{ type, top, left, height, width, band }`, in draw order -
|
|
131
|
+
* a table's group zones last, so they lie over the band their table is on
|
|
83
132
|
*/
|
|
84
133
|
export function designZones(layout) {
|
|
85
134
|
const { page } = layout;
|
|
86
135
|
const contentHeight = page.height - page.margin.top - page.margin.bottom;
|
|
136
|
+
const width = page.width - page.margin.left - page.margin.right;
|
|
87
137
|
|
|
88
138
|
const byType = Object.fromEntries(
|
|
89
139
|
(layout.bands || []).map(b => [b.type, b]));
|
|
@@ -96,49 +146,74 @@ export function designZones(layout) {
|
|
|
96
146
|
});
|
|
97
147
|
|
|
98
148
|
const zones = [];
|
|
149
|
+
const wide = (type, top, height, band) => ({ type, top, left: 0, height, width, band });
|
|
99
150
|
|
|
100
151
|
for (const type of PAGE_ZONES) {
|
|
101
152
|
const region = regions[type];
|
|
102
153
|
if (region && byType[type]) {
|
|
103
|
-
zones.push(
|
|
154
|
+
zones.push(wide(type, region.top, region.height, byType[type]));
|
|
104
155
|
}
|
|
105
156
|
}
|
|
106
157
|
|
|
107
158
|
const detail = regions.detail;
|
|
108
|
-
const groupHeader = byType.groupHeader;
|
|
109
|
-
const groupFooter = byType.groupFooter;
|
|
110
159
|
|
|
111
|
-
|
|
112
|
-
const
|
|
160
|
+
/** the report's own group bands, from a layout in the older form */
|
|
161
|
+
const height = (kind) => byType[kind] ? bandZoneHeight(byType[kind], contentHeight) : 0;
|
|
162
|
+
const headHeight = height('groupHeader');
|
|
163
|
+
const footHeight = height('groupFooter');
|
|
113
164
|
|
|
114
|
-
if (groupHeader) {
|
|
115
|
-
zones.push(
|
|
116
|
-
type: 'groupHeader', top: detail.top,
|
|
117
|
-
height: headHeight, band: groupHeader
|
|
118
|
-
});
|
|
165
|
+
if (byType.groupHeader) {
|
|
166
|
+
zones.push(wide('groupHeader', detail.top, headHeight, byType.groupHeader));
|
|
119
167
|
}
|
|
120
168
|
|
|
121
169
|
if (byType.detail) {
|
|
122
|
-
zones.push(
|
|
123
|
-
|
|
124
|
-
top: detail.top + headHeight,
|
|
125
|
-
height: Math.max(detail.height - headHeight - footHeight, 0),
|
|
126
|
-
band: byType.detail
|
|
127
|
-
});
|
|
170
|
+
zones.push(wide('detail', detail.top + headHeight,
|
|
171
|
+
Math.max(detail.height - headHeight - footHeight, 0), byType.detail));
|
|
128
172
|
}
|
|
129
173
|
|
|
130
|
-
if (groupFooter) {
|
|
131
|
-
zones.push(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
174
|
+
if (byType.groupFooter) {
|
|
175
|
+
zones.push(wide('groupFooter', detail.top + detail.height - footHeight,
|
|
176
|
+
footHeight, byType.groupFooter));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** then each grouped table's, over the zone of whichever band holds it */
|
|
180
|
+
for (const host of [...zones]) {
|
|
181
|
+
for (const item of (host.band.items || [])) {
|
|
182
|
+
if (item?.type === 'table') zones.push(...tableZones(item, host));
|
|
183
|
+
}
|
|
136
184
|
}
|
|
137
185
|
|
|
138
186
|
return zones;
|
|
139
187
|
}
|
|
140
188
|
|
|
141
189
|
|
|
190
|
+
/**
|
|
191
|
+
* A grouped table's group zones, placed inside the table on its band's zone.
|
|
192
|
+
*
|
|
193
|
+
* @param {object} table
|
|
194
|
+
* @param {object} host the zone of the band the table is on
|
|
195
|
+
* @returns {object[]}
|
|
196
|
+
*/
|
|
197
|
+
function tableZones(table, host) {
|
|
198
|
+
return levelStrips(table).map(({ kind, level, band, y, h }) => {
|
|
199
|
+
const key = groupBandKey(kind, table.id, level);
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
type: key,
|
|
203
|
+
kind,
|
|
204
|
+
level,
|
|
205
|
+
table: table.id,
|
|
206
|
+
label: bandLabel(key),
|
|
207
|
+
top: host.top + (table.y ?? 0) + y,
|
|
208
|
+
left: host.left + (table.x ?? 0),
|
|
209
|
+
height: h,
|
|
210
|
+
width: table.w ?? 0,
|
|
211
|
+
band
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
142
217
|
/**
|
|
143
218
|
* An absolutely positioned child anchors to its ancestor's *padding* box, and
|
|
144
219
|
* the page draws its margins as padding - so the margins are added back here,
|
|
@@ -157,7 +232,7 @@ function zone(z, margin) {
|
|
|
157
232
|
|
|
158
233
|
return `
|
|
159
234
|
<div class="band dz-zone" data-band-type="${esc(z.type)}"
|
|
160
|
-
style="
|
|
235
|
+
style="${zoneStyle(z, margin)}">
|
|
161
236
|
${items(drawn)}
|
|
162
237
|
</div>`;
|
|
163
238
|
}
|
|
@@ -249,10 +324,20 @@ export function guideLines(layout) {
|
|
|
249
324
|
}
|
|
250
325
|
|
|
251
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Where a zone is drawn on the page. Exported for the live drag, which moves a
|
|
329
|
+
* table's group zones with their table without rebuilding the sheet.
|
|
330
|
+
*/
|
|
331
|
+
export function zoneStyle(z, margin) {
|
|
332
|
+
return `position:absolute;top:${z.top + margin.top}px;left:${z.left + margin.left}px;` +
|
|
333
|
+
`width:${z.width}px;height:${z.height}px`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
252
337
|
/** the band name, in the gutter beside the page rather than over the design */
|
|
253
338
|
function tag(z, margin) {
|
|
254
339
|
return `<span class="dz-tag" data-band-tag="${esc(z.type)}"
|
|
255
|
-
style="top:${z.top + margin.top}px">${esc(z.type)}</span>`;
|
|
340
|
+
style="top:${z.top + margin.top}px">${esc(z.label ?? z.type)}</span>`;
|
|
256
341
|
}
|
|
257
342
|
|
|
258
343
|
|
|
@@ -281,7 +366,7 @@ export function selectionBox(layout, selection) {
|
|
|
281
366
|
item,
|
|
282
367
|
box: {
|
|
283
368
|
...box,
|
|
284
|
-
x: box.x + margin.left,
|
|
369
|
+
x: box.x + zone.left + margin.left,
|
|
285
370
|
y: box.y + zone.top + margin.top
|
|
286
371
|
}
|
|
287
372
|
};
|
|
@@ -400,18 +485,18 @@ export function bandBox(layout, bandType) {
|
|
|
400
485
|
const margin = layout.page.margin;
|
|
401
486
|
|
|
402
487
|
return {
|
|
403
|
-
left: margin.left,
|
|
488
|
+
left: zone.left + margin.left,
|
|
404
489
|
top: zone.top + margin.top,
|
|
405
|
-
w:
|
|
490
|
+
w: zone.width,
|
|
406
491
|
h: zone.height,
|
|
407
492
|
|
|
408
493
|
/**
|
|
409
494
|
* Where the band starts inside the printable area, which is what the
|
|
410
495
|
* rulers measure and therefore what a guide's position means. `originX`
|
|
411
|
-
* is zero
|
|
412
|
-
*
|
|
496
|
+
* is zero for every band that runs the page's width, and a table's
|
|
497
|
+
* group band starts where its table does.
|
|
413
498
|
*/
|
|
414
|
-
originX:
|
|
499
|
+
originX: zone.left,
|
|
415
500
|
originY: zone.top
|
|
416
501
|
};
|
|
417
502
|
}
|
|
@@ -472,40 +557,71 @@ export function drawGuides(band, lines = [], gaps = []) {
|
|
|
472
557
|
* @returns {number|null} null when the report has no such band
|
|
473
558
|
*/
|
|
474
559
|
export function absoluteTop(layout, bandType, y) {
|
|
560
|
+
return absolutePoint(layout, bandType, 0, y)?.y ?? null;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* The printable-area position of a point inside a band - both axes, because a
|
|
566
|
+
* table's group band does not start at the page's left edge.
|
|
567
|
+
*
|
|
568
|
+
* @param {object} layout
|
|
569
|
+
* @param {string} bandType
|
|
570
|
+
* @param {number} x band-relative
|
|
571
|
+
* @param {number} y band-relative
|
|
572
|
+
* @returns {{x: number, y: number}|null} null when the report has no such band
|
|
573
|
+
*/
|
|
574
|
+
export function absolutePoint(layout, bandType, x, y) {
|
|
475
575
|
const zone = designZones(layout).find(z => z.type === bandType);
|
|
476
|
-
return zone ? zone.top + y : null;
|
|
576
|
+
return zone ? { x: zone.left + x, y: zone.top + y } : null;
|
|
477
577
|
}
|
|
478
578
|
|
|
479
579
|
|
|
480
580
|
/**
|
|
481
|
-
* Which band a printable
|
|
581
|
+
* Which band a point in the printable area falls in.
|
|
482
582
|
*
|
|
483
|
-
* The zones tile the page - whatever a missing band would have taken
|
|
484
|
-
* absorbed by the detail (see regions.js) - so any point on the sheet is in
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
583
|
+
* The page-wide zones tile the page - whatever a missing band would have taken
|
|
584
|
+
* is absorbed by the detail (see regions.js) - so any point on the sheet is in
|
|
585
|
+
* one of them. A table's group zone lies over one of those, and a point inside
|
|
586
|
+
* it is on the group band: it is the one drawn on top. A point off the top or
|
|
587
|
+
* bottom is clamped to the nearest page-wide zone rather than returned as
|
|
588
|
+
* nothing, because dragging an item slightly past the edge is a gesture towards
|
|
589
|
+
* that band, not a gesture at nothing.
|
|
488
590
|
*
|
|
489
591
|
* @param {object} layout
|
|
490
592
|
* @param {number} top
|
|
593
|
+
* @param {number|null} [left] without one, only the page-wide zones count
|
|
594
|
+
* @param {object} [options]
|
|
595
|
+
* @param {boolean} [options.groupZones] false to look past tables' group zones
|
|
491
596
|
* @returns {string|null} a band type, or null for a report with no bands
|
|
492
597
|
*/
|
|
493
|
-
export function bandAtOffset(layout, top) {
|
|
598
|
+
export function bandAtOffset(layout, top, left = null, { groupZones = true } = {}) {
|
|
494
599
|
const zones = designZones(layout);
|
|
495
600
|
if (!zones.length) return null;
|
|
496
601
|
|
|
497
|
-
const
|
|
602
|
+
const across = zones.filter(z => !z.table);
|
|
498
603
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
604
|
+
const inside = (z) =>
|
|
605
|
+
top >= z.top && top < z.top + z.height &&
|
|
606
|
+
(z.table ? left != null && left >= z.left && left < z.left + z.width : true);
|
|
607
|
+
|
|
608
|
+
const hit = (groupZones ? zones : across).filter(inside);
|
|
609
|
+
if (hit.length) return hit.at(-1).type;
|
|
610
|
+
|
|
611
|
+
if (!across.length) return null;
|
|
502
612
|
|
|
613
|
+
const ordered = [...across].sort((a, b) => a.top - b.top);
|
|
503
614
|
return top < ordered[0].top ? ordered[0].type : ordered.at(-1).type;
|
|
504
615
|
}
|
|
505
616
|
|
|
506
617
|
|
|
507
618
|
/**
|
|
508
|
-
* Where an item would land if it were dropped where it currently sits
|
|
619
|
+
* Where an item would land if it were dropped where it currently sits - the
|
|
620
|
+
* band under its top-left corner.
|
|
621
|
+
*
|
|
622
|
+
* A table is never over a group band, even its own: a group band cannot hold
|
|
623
|
+
* one, and a table whose headings are switched off starts on its own group
|
|
624
|
+
* header.
|
|
509
625
|
*
|
|
510
626
|
* @param {object} layout
|
|
511
627
|
* @param {string} bandType the band it is in now
|
|
@@ -513,6 +629,8 @@ export function bandAtOffset(layout, top) {
|
|
|
513
629
|
* @returns {string|null} the band type under it
|
|
514
630
|
*/
|
|
515
631
|
export function bandUnder(layout, bandType, item) {
|
|
516
|
-
const
|
|
517
|
-
|
|
632
|
+
const at = absolutePoint(layout, bandType, item?.x ?? 0, item?.y ?? 0);
|
|
633
|
+
if (!at) return null;
|
|
634
|
+
|
|
635
|
+
return bandAtOffset(layout, at.y, at.x, { groupZones: item?.type !== 'table' });
|
|
518
636
|
}
|