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.
- package/README.md +254 -3
- package/dist/designer-_sWqzOj8.js +5052 -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-4I7C1Rnd.js +4083 -0
- package/package.json +2 -2
- package/src/designer/blank.js +0 -1
- package/src/designer/canvas.js +172 -54
- package/src/designer/choice.js +368 -0
- package/src/designer/designer.js +342 -12
- package/src/designer/dialog.js +634 -6
- package/src/designer/fields.js +345 -36
- package/src/designer/geometry.js +77 -4
- package/src/designer/grouping.js +556 -0
- package/src/designer/icons.js +22 -0
- package/src/designer/menu.js +50 -6
- package/src/designer/panel.js +872 -69
- package/src/designer/rulers.js +14 -6
- package/src/designer/sample-data.js +112 -31
- package/src/designer/select.js +24 -3
- package/src/designer/structure.js +126 -12
- package/src/designer/styles.css +2017 -732
- 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 +304 -8
- package/src/engine/xlsx-style.js +50 -4
- package/src/engine/xlsx.js +91 -21
- package/src/index.js +18 -0
- package/src/preview/chrome.css +302 -84
- package/src/preview/chrome.js +70 -58
- package/src/preview/viewer.js +137 -85
- package/src/render/items.js +61 -10
- package/src/render/report.css +0 -5
- package/src/shared/dropdown.css +78 -45
- package/src/shared/dropdown.js +105 -5
- package/src/shared/modal.css +78 -13
- package/types/index.d.ts +104 -9
- package/types/layout.d.ts +164 -2
- package/dist/designer-DQlfKnTr.js +0 -3416
- package/dist/viewer-BSPNCNRU.js +0 -2912
package/src/engine/xlsx.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* never the layout or the data.
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
-
import { reportLayout, reportRows, tableRows, reportTables, columnLabel } from './rows.js';
|
|
37
|
+
import { reportLayout, reportRows, tableRows, reportTables, columnLabel, groupColumns } from './rows.js';
|
|
38
38
|
import {
|
|
39
39
|
argb, cellFormat, createStyles, columnChars, indentLevels, DEFAULT_COLUMN_PX, points
|
|
40
40
|
} from './xlsx-style.js';
|
|
@@ -44,6 +44,8 @@ import {
|
|
|
44
44
|
} from './xlsx-drawing.js';
|
|
45
45
|
import { imageSrc } from '../render/items.js';
|
|
46
46
|
import { zip } from './zip.js';
|
|
47
|
+
import { excelNumberFormat, excelValue } from './format.js';
|
|
48
|
+
import { cellHighlight } from './highlight.js';
|
|
47
49
|
|
|
48
50
|
|
|
49
51
|
/** Excel's hard limits; past them it refuses the whole file */
|
|
@@ -134,7 +136,7 @@ const PLACEHOLDER = /\{[^{}]+\}/;
|
|
|
134
136
|
* @param {string} [options.reportSheetName='Report']
|
|
135
137
|
* @param {boolean} [options.groupColumn=true] prepend the group key on a
|
|
136
138
|
* grouped table's sheet, as toCSV does
|
|
137
|
-
* @param {string} [options.groupLabel='Group']
|
|
139
|
+
* @param {string|string[]} [options.groupLabel='Group'] as toCSV's
|
|
138
140
|
* @param {Object<string, Uint8Array|ArrayBuffer>|Map} [options.images] the
|
|
139
141
|
* bytes of pictures that are not `data:` URIs, keyed by their src - which is
|
|
140
142
|
* what toXLSXAsync fetches. A picture with no bytes is left out
|
|
@@ -299,7 +301,9 @@ function reportSheet(pages, name, styled, images) {
|
|
|
299
301
|
if (isText) return placeText(row, grid, formats);
|
|
300
302
|
|
|
301
303
|
return [{
|
|
302
|
-
cells: row.cells.map((value, i) => ({
|
|
304
|
+
cells: row.cells.map((value, i) => ({
|
|
305
|
+
...typed(value, row.design?.[i]), format: formats(row.design?.[i])
|
|
306
|
+
})),
|
|
303
307
|
page: row.page, top: row.top, own: row.height
|
|
304
308
|
}];
|
|
305
309
|
});
|
|
@@ -324,13 +328,14 @@ function reportSheet(pages, name, styled, images) {
|
|
|
324
328
|
|
|
325
329
|
/**
|
|
326
330
|
* One table as a sheet: the labels, then every row across every page.
|
|
327
|
-
* Grouped tables get the group key as a first column
|
|
328
|
-
*
|
|
331
|
+
* Grouped tables get the group key as a first column - one per level, for a
|
|
332
|
+
* table grouped within its groups - so the groups survive a sort: the same
|
|
333
|
+
* choice toCSV makes.
|
|
329
334
|
*/
|
|
330
335
|
function tableSheet(table, styled, groupColumn, groupLabel) {
|
|
331
|
-
const
|
|
332
|
-
const columns =
|
|
333
|
-
const labels =
|
|
336
|
+
const groups = groupColumn ? groupColumns(table, groupLabel) : { labels: [], cells: () => [] };
|
|
337
|
+
const columns = [...groups.labels.map(() => ({ field: null, align: 'left' })), ...table.columns];
|
|
338
|
+
const labels = [...groups.labels, ...table.columns.map(columnLabel)];
|
|
334
339
|
|
|
335
340
|
/**
|
|
336
341
|
* One format object per column, so the writer resolves each once. A
|
|
@@ -354,17 +359,37 @@ function tableSheet(table, styled, groupColumn, groupLabel) {
|
|
|
354
359
|
const cellFormats = columns.map(column =>
|
|
355
360
|
styled ? cellFormat({ kind: 'cell', column, table: table.table }) : null);
|
|
356
361
|
|
|
362
|
+
/** a highlighted cell's format, made once per column and style */
|
|
363
|
+
const litFormats = new Map();
|
|
364
|
+
const formatFor = (i, highlight) => {
|
|
365
|
+
if (!styled || !highlight) return cellFormats[i];
|
|
366
|
+
|
|
367
|
+
const key = `${i}|${JSON.stringify(highlight)}`;
|
|
368
|
+
if (!litFormats.has(key)) {
|
|
369
|
+
litFormats.set(key, cellFormat({ kind: 'cell', column: columns[i], table: table.table, highlight }));
|
|
370
|
+
}
|
|
371
|
+
return litFormats.get(key);
|
|
372
|
+
};
|
|
373
|
+
const groupWidth = columns.length - table.columns.length;
|
|
374
|
+
|
|
357
375
|
const rows = [{
|
|
358
376
|
cells: labels.map((value, i) => ({ value, format: headFormats[i] })),
|
|
359
377
|
height: styled ? table.headerHeight : null
|
|
360
378
|
}];
|
|
361
379
|
|
|
362
|
-
for (const
|
|
380
|
+
for (const entry of table.rows) {
|
|
381
|
+
const { row, height } = entry;
|
|
363
382
|
const values = table.columns.map(c => row?.[c.field]);
|
|
364
|
-
const cells =
|
|
383
|
+
const cells = [...groups.cells(entry), ...values];
|
|
365
384
|
|
|
366
385
|
rows.push({
|
|
367
|
-
cells: cells.map((value, i) => ({
|
|
386
|
+
cells: cells.map((value, i) => ({
|
|
387
|
+
...typed(value, { kind: 'cell', column: columns[i] }),
|
|
388
|
+
/** the group columns are the report's, not the table's, and take no rules */
|
|
389
|
+
format: i < groupWidth
|
|
390
|
+
? cellFormats[i]
|
|
391
|
+
: formatFor(i, cellHighlight(table.table, columns[i], row))
|
|
392
|
+
})),
|
|
368
393
|
height: styled ? height : null
|
|
369
394
|
});
|
|
370
395
|
}
|
|
@@ -457,7 +482,10 @@ function placeText(row, grid, formats) {
|
|
|
457
482
|
row.cells.forEach((raw, i) => {
|
|
458
483
|
const design = row.design[i];
|
|
459
484
|
const align = formats(design)?.alignment?.horizontal ?? 'left';
|
|
460
|
-
|
|
485
|
+
/** a formatted total is a real number; an unformatted one is guessed at, as ever */
|
|
486
|
+
const typedValue = typed(raw, design);
|
|
487
|
+
const value = typedValue.numFmt ? typedValue.value : numericText(raw, design.template);
|
|
488
|
+
const numFmt = typedValue.numFmt;
|
|
461
489
|
|
|
462
490
|
const x = Math.max(0, Number(design.x) || 0);
|
|
463
491
|
const w = Math.max(1, Number(design.w) || 1);
|
|
@@ -471,14 +499,14 @@ function placeText(row, grid, formats) {
|
|
|
471
499
|
const across = formats.text(design, { centred: true });
|
|
472
500
|
|
|
473
501
|
line = lineFor(span);
|
|
474
|
-
line.cells[first] = { value, format: across };
|
|
502
|
+
line.cells[first] = { value, format: across, numFmt };
|
|
475
503
|
for (let c = first + 1; c <= last; c++) line.cells[c] = { value: null, format: across };
|
|
476
504
|
} else {
|
|
477
505
|
const c = align === 'right' ? last : first;
|
|
478
506
|
const inset = align === 'right' ? grid.right(c) - (x + w) : x - grid.left(c);
|
|
479
507
|
|
|
480
508
|
line = lineFor([c]);
|
|
481
|
-
line.cells[c] = { value, format: formats.text(design, { indent: indentLevels(inset) }) };
|
|
509
|
+
line.cells[c] = { value, format: formats.text(design, { indent: indentLevels(inset) }), numFmt };
|
|
482
510
|
}
|
|
483
511
|
|
|
484
512
|
line.top = Math.min(line.top, design.y);
|
|
@@ -489,6 +517,35 @@ function placeText(row, grid, formats) {
|
|
|
489
517
|
}
|
|
490
518
|
|
|
491
519
|
|
|
520
|
+
/**
|
|
521
|
+
* A value as the workbook should hold it, when the report gave it a format:
|
|
522
|
+
* the real number or date, and the code that shows it as the report printed
|
|
523
|
+
* it - so 1,00,000.00 on the page is 100000 in the cell, and still adds up.
|
|
524
|
+
*
|
|
525
|
+
* A table cell is typed by its column's format. A text item is typed only when
|
|
526
|
+
* it is one placeholder and nothing else - a grand total - which is when the
|
|
527
|
+
* engine keeps the value it printed as `raw`; "Total: ₹1,200" stays text.
|
|
528
|
+
*
|
|
529
|
+
* @param {*} value what the row or the page holds
|
|
530
|
+
* @param {object|undefined} design the cell's descriptor, from rows.js
|
|
531
|
+
* @returns {{value: *, numFmt?: string}}
|
|
532
|
+
*/
|
|
533
|
+
function typed(value, design) {
|
|
534
|
+
const source = design?.kind === 'cell' ? design.column?.format
|
|
535
|
+
: design?.kind === 'text' ? design.format
|
|
536
|
+
: null;
|
|
537
|
+
|
|
538
|
+
const code = excelNumberFormat(source);
|
|
539
|
+
if (!code) return { value };
|
|
540
|
+
|
|
541
|
+
const raw = design.kind === 'text' ? design.raw : value;
|
|
542
|
+
if (raw === undefined) return { value };
|
|
543
|
+
|
|
544
|
+
const number = excelValue(raw, source);
|
|
545
|
+
return number === null ? { value } : { value: number, numFmt: code };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
|
|
492
549
|
/**
|
|
493
550
|
* A text item's value, as a number when it is a total: the item's template
|
|
494
551
|
* holds a placeholder and what it printed is a plain number and nothing else.
|
|
@@ -807,8 +864,11 @@ function formatCache() {
|
|
|
807
864
|
const key = design.column ?? design;
|
|
808
865
|
if (!byColumn.has(key)) byColumn.set(key, {});
|
|
809
866
|
const entry = byColumn.get(key);
|
|
810
|
-
|
|
811
|
-
|
|
867
|
+
|
|
868
|
+
/** a highlighted cell is its column's format and its rule's style - one per pair */
|
|
869
|
+
const variant = design.highlight ? `${design.kind}|${JSON.stringify(design.highlight)}` : design.kind;
|
|
870
|
+
entry[variant] ??= cellFormat(design);
|
|
871
|
+
return entry[variant];
|
|
812
872
|
}
|
|
813
873
|
|
|
814
874
|
formats.text = (design, { centred = false, indent = 0 } = {}) => {
|
|
@@ -816,7 +876,7 @@ function formatCache() {
|
|
|
816
876
|
if (!byStyle.has(key)) byStyle.set(key, new Map());
|
|
817
877
|
const variants = byStyle.get(key);
|
|
818
878
|
|
|
819
|
-
const variant = `${centred}|${indent}`;
|
|
879
|
+
const variant = `${centred}|${indent}|${design.highlight ? JSON.stringify(design.highlight) : ''}`;
|
|
820
880
|
if (!variants.has(variant)) {
|
|
821
881
|
const base = cellFormat(design);
|
|
822
882
|
variants.set(variant, {
|
|
@@ -907,7 +967,7 @@ function worksheet({ name, rows, frozen, gridLines, widths, width, drawing }, st
|
|
|
907
967
|
rows.forEach((row, r) => {
|
|
908
968
|
let cells = '';
|
|
909
969
|
row.cells.forEach((c, i) => {
|
|
910
|
-
if (c) cells += cell(`${columnName(i)}${r + 1}`, c.value, c.format, xfFor);
|
|
970
|
+
if (c) cells += cell(`${columnName(i)}${r + 1}`, c.value, c.format, xfFor, c.numFmt);
|
|
911
971
|
});
|
|
912
972
|
|
|
913
973
|
const height = Number(row.height) > 0
|
|
@@ -943,12 +1003,17 @@ function usedRange(width, height) {
|
|
|
943
1003
|
}
|
|
944
1004
|
|
|
945
1005
|
|
|
946
|
-
/**
|
|
1006
|
+
/**
|
|
1007
|
+
* format object and number format to a cell format index, each pair resolved
|
|
1008
|
+
* once. The number format is a built-in id, or a custom code from format.js.
|
|
1009
|
+
*/
|
|
947
1010
|
function xfResolver(styles) {
|
|
948
1011
|
const cache = new WeakMap();
|
|
949
1012
|
const plain = new Map();
|
|
950
1013
|
|
|
951
|
-
return (format,
|
|
1014
|
+
return (format, code) => {
|
|
1015
|
+
const numFmt = typeof code === 'string' ? styles.numFmt(code) : code;
|
|
1016
|
+
|
|
952
1017
|
if (!format) {
|
|
953
1018
|
if (!plain.has(numFmt)) plain.set(numFmt, styles.xf(null, numFmt));
|
|
954
1019
|
return plain.get(numFmt);
|
|
@@ -971,8 +1036,10 @@ function xfResolver(styles) {
|
|
|
971
1036
|
* @param {*} value the raw value from the row
|
|
972
1037
|
* @param {object|null} format
|
|
973
1038
|
* @param {Function} xfFor
|
|
1039
|
+
* @param {string} [code] the number format a typed value is shown with, from
|
|
1040
|
+
* format.js - a number or a date serial the report formats
|
|
974
1041
|
*/
|
|
975
|
-
function cell(ref, value, format, xfFor) {
|
|
1042
|
+
function cell(ref, value, format, xfFor, code) {
|
|
976
1043
|
const empty = value === null || value === undefined || value === '';
|
|
977
1044
|
const isDate = value instanceof Date && !Number.isNaN(value.getTime());
|
|
978
1045
|
|
|
@@ -983,6 +1050,9 @@ function cell(ref, value, format, xfFor) {
|
|
|
983
1050
|
numFmt = Number.isInteger(serial) ? NUMFMT_DATE : NUMFMT_DATE_TIME;
|
|
984
1051
|
}
|
|
985
1052
|
|
|
1053
|
+
if (code && typeof value === 'number') numFmt = code;
|
|
1054
|
+
if (code && isDate) numFmt = code;
|
|
1055
|
+
|
|
986
1056
|
const xf = xfFor(format, numFmt);
|
|
987
1057
|
const s = xf ? ` s="${xf}"` : '';
|
|
988
1058
|
|
package/src/index.js
CHANGED
|
@@ -30,6 +30,24 @@ export {
|
|
|
30
30
|
toXLSXAsync,
|
|
31
31
|
reportImageSources,
|
|
32
32
|
XLSX_MIME,
|
|
33
|
+
tablesOf,
|
|
34
|
+
datasetOf,
|
|
35
|
+
groupingOf,
|
|
36
|
+
groupingsOf,
|
|
37
|
+
groupBandsOf,
|
|
38
|
+
levelsOf,
|
|
39
|
+
isGrouped,
|
|
40
|
+
normalizeGrouping,
|
|
41
|
+
fragmentBandsOf,
|
|
42
|
+
MAX_GROUP_LEVELS,
|
|
43
|
+
formatValue,
|
|
44
|
+
describeFormat,
|
|
45
|
+
excelNumberFormat,
|
|
46
|
+
DEFAULT_FORMAT,
|
|
47
|
+
INDIAN_DEFAULTS,
|
|
48
|
+
highlightFor,
|
|
49
|
+
cellHighlight,
|
|
50
|
+
describeHighlight,
|
|
33
51
|
measureText,
|
|
34
52
|
wrapLines,
|
|
35
53
|
textHeight,
|