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/designer/fields.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
* Nothing here invents a field the engine does not read.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { levelsOf } from '../engine/tables.js';
|
|
15
|
+
import { setGroupBy } from './grouping.js';
|
|
16
|
+
import { formatValue, DATE_PATTERNS, CURRENCY_SYMBOLS } from '../engine/format.js';
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* Spec 10 left the font list open, and closes it here: web-safe families only.
|
|
@@ -40,10 +44,15 @@ const STYLES = [
|
|
|
40
44
|
{ label: 'Italic', value: 'italic' }
|
|
41
45
|
];
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* A choice with an `icon` on every option can be drawn as a row of glyph
|
|
49
|
+
* buttons rather than a dropdown, as a design tool draws text alignment - the
|
|
50
|
+
* field asks for that with `segmented`. The label is still each button's name.
|
|
51
|
+
*/
|
|
43
52
|
const ALIGNMENTS = [
|
|
44
|
-
{ label: 'Left', value: 'left' },
|
|
45
|
-
{ label: 'Centre', value: 'center' },
|
|
46
|
-
{ label: 'Right', value: 'right' }
|
|
53
|
+
{ label: 'Left', value: 'left', icon: 'alignLeft' },
|
|
54
|
+
{ label: 'Centre', value: 'center', icon: 'alignCenter' },
|
|
55
|
+
{ label: 'Right', value: 'right', icon: 'alignRight' }
|
|
47
56
|
];
|
|
48
57
|
|
|
49
58
|
const IMAGE_FITS = [
|
|
@@ -53,8 +62,8 @@ const IMAGE_FITS = [
|
|
|
53
62
|
];
|
|
54
63
|
|
|
55
64
|
const ORIENTATIONS = [
|
|
56
|
-
{ label: 'Horizontal', value: 'horizontal' },
|
|
57
|
-
{ label: 'Vertical', value: 'vertical' }
|
|
65
|
+
{ label: 'Horizontal', value: 'horizontal', icon: 'horizontal' },
|
|
66
|
+
{ label: 'Vertical', value: 'vertical', icon: 'vertical' }
|
|
58
67
|
];
|
|
59
68
|
|
|
60
69
|
/**
|
|
@@ -76,6 +85,16 @@ const LINE_STYLES = [
|
|
|
76
85
|
const RULE_STYLES = [...LINE_STYLES, { label: 'None', value: 'none' }];
|
|
77
86
|
|
|
78
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Two hints for the rail's layout, which say nothing about the value:
|
|
90
|
+
*
|
|
91
|
+
* short a letter drawn inside the box in place of a label above it, as X,
|
|
92
|
+
* Y, W and H are in every design tool. The full label is still there
|
|
93
|
+
* for a screen reader and a tooltip
|
|
94
|
+
* half the control takes one of the rail's two columns rather than both.
|
|
95
|
+
* Numbers and colours always do; a choice or a text box asks, when
|
|
96
|
+
* what it holds is short enough to read at half the width
|
|
97
|
+
*/
|
|
79
98
|
const num = (key, label, extra = {}) =>
|
|
80
99
|
({ key, label, type: 'number', ...extra });
|
|
81
100
|
|
|
@@ -104,10 +123,16 @@ function maxRuleWidth(item) {
|
|
|
104
123
|
* readField and writeField need, since they walk a path on whatever they get.
|
|
105
124
|
*/
|
|
106
125
|
export const COLUMN_FIELDS = [
|
|
107
|
-
{ key: 'field', label: 'Field', type: 'text' },
|
|
108
|
-
{ key: 'label', label: 'Label', type: 'text' },
|
|
126
|
+
{ key: 'field', label: 'Field', type: 'text', half: true },
|
|
127
|
+
{ key: 'label', label: 'Label', type: 'text', half: true },
|
|
109
128
|
{ key: 'width', label: 'Width', type: 'number', min: 1 },
|
|
110
|
-
{ key: 'align', label: 'Align', type: 'choice', options: ALIGNMENTS }
|
|
129
|
+
{ key: 'align', label: 'Align', type: 'choice', options: ALIGNMENTS, half: true, segmented: true },
|
|
130
|
+
{
|
|
131
|
+
key: 'expression', label: 'Calculation', type: 'text',
|
|
132
|
+
hint: 'Blank shows the field as it is. A calculation - {qty} * {price}, ' +
|
|
133
|
+
'round({amount} * 0.18, 2), percentage({amount}) - is worked out for ' +
|
|
134
|
+
"each row and saved under this column's field"
|
|
135
|
+
}
|
|
111
136
|
];
|
|
112
137
|
|
|
113
138
|
|
|
@@ -127,10 +152,10 @@ export function fieldsFor(item) {
|
|
|
127
152
|
const box = {
|
|
128
153
|
title: 'Position and size',
|
|
129
154
|
fields: [
|
|
130
|
-
num('x', 'X'),
|
|
131
|
-
num('y', 'Y'),
|
|
132
|
-
num('w', 'Width', { min: 1 }),
|
|
133
|
-
...(item.type === 'table' ? [] : [num('h', 'Height', { min: 1 })])
|
|
155
|
+
num('x', 'X', { short: 'X' }),
|
|
156
|
+
num('y', 'Y', { short: 'Y' }),
|
|
157
|
+
num('w', 'Width', { min: 1, short: 'W' }),
|
|
158
|
+
...(item.type === 'table' ? [] : [num('h', 'Height', { min: 1, short: 'H' })])
|
|
134
159
|
]
|
|
135
160
|
};
|
|
136
161
|
|
|
@@ -142,7 +167,7 @@ export function fieldsFor(item) {
|
|
|
142
167
|
fields: [
|
|
143
168
|
{
|
|
144
169
|
key: 'style.borderStyle', label: 'Style', type: 'choice',
|
|
145
|
-
options: RULE_STYLES
|
|
170
|
+
options: RULE_STYLES, half: true
|
|
146
171
|
},
|
|
147
172
|
num('style.borderWidth', 'Width', { min: 1 }),
|
|
148
173
|
{ key: 'style.borderColor', label: 'Colour', type: 'color' },
|
|
@@ -195,12 +220,12 @@ export function fieldsFor(item) {
|
|
|
195
220
|
fields: [
|
|
196
221
|
{
|
|
197
222
|
key: 'orientation', label: 'Runs', type: 'choice',
|
|
198
|
-
options: ORIENTATIONS
|
|
223
|
+
options: ORIENTATIONS, half: true, segmented: true
|
|
199
224
|
},
|
|
200
225
|
num('style.thickness', 'Thickness', { min: 1 }),
|
|
201
226
|
{
|
|
202
227
|
key: 'style.lineStyle', label: 'Style', type: 'choice',
|
|
203
|
-
options: LINE_STYLES
|
|
228
|
+
options: LINE_STYLES, half: true
|
|
204
229
|
},
|
|
205
230
|
{ key: 'style.color', label: 'Colour', type: 'color' }
|
|
206
231
|
]
|
|
@@ -219,11 +244,7 @@ export function fieldsFor(item) {
|
|
|
219
244
|
hint: "The key in the data object whose rows this table " +
|
|
220
245
|
"draws. Blank reads the report's dataset"
|
|
221
246
|
},
|
|
222
|
-
|
|
223
|
-
key: 'groupBy', label: 'Group by', type: 'text', nullable: true,
|
|
224
|
-
hint: 'A field to group these rows by, or blank. One table ' +
|
|
225
|
-
'in a report can be grouped'
|
|
226
|
-
}
|
|
247
|
+
GROUP_BY
|
|
227
248
|
]
|
|
228
249
|
},
|
|
229
250
|
{
|
|
@@ -265,7 +286,7 @@ export function fieldsFor(item) {
|
|
|
265
286
|
},
|
|
266
287
|
{
|
|
267
288
|
key: 'style.borderStyle', label: 'Borders', type: 'choice',
|
|
268
|
-
options: RULE_STYLES
|
|
289
|
+
options: RULE_STYLES, half: true
|
|
269
290
|
},
|
|
270
291
|
num('style.borderWidth', 'Border width', {
|
|
271
292
|
min: 1,
|
|
@@ -297,9 +318,9 @@ export function fieldsFor(item) {
|
|
|
297
318
|
fields: [
|
|
298
319
|
{ key: 'style.fontFamily', label: 'Font', type: 'choice', options: FONT_STACKS },
|
|
299
320
|
num('style.fontSize', 'Size', { min: 1 }),
|
|
300
|
-
{ key: 'style.fontWeight', label: 'Weight', type: 'choice', options: WEIGHTS },
|
|
301
|
-
{ key: 'style.fontStyle', label: 'Style', type: 'choice', options: STYLES },
|
|
302
|
-
{ key: 'style.align', label: 'Align', type: 'choice', options: ALIGNMENTS },
|
|
321
|
+
{ key: 'style.fontWeight', label: 'Weight', type: 'choice', options: WEIGHTS, half: true },
|
|
322
|
+
{ key: 'style.fontStyle', label: 'Style', type: 'choice', options: STYLES, half: true },
|
|
323
|
+
{ key: 'style.align', label: 'Align', type: 'choice', options: ALIGNMENTS, half: true, segmented: true },
|
|
303
324
|
{ key: 'style.color', label: 'Colour', type: 'color' }
|
|
304
325
|
]
|
|
305
326
|
}
|
|
@@ -464,9 +485,11 @@ function pageFields(layout) {
|
|
|
464
485
|
label: 'Orientation',
|
|
465
486
|
type: 'choice',
|
|
466
487
|
rebuilds: true,
|
|
488
|
+
half: true,
|
|
489
|
+
segmented: true,
|
|
467
490
|
options: [
|
|
468
|
-
{ value: 'portrait', label: 'Portrait' },
|
|
469
|
-
{ value: 'landscape', label: 'Landscape' }
|
|
491
|
+
{ value: 'portrait', label: 'Portrait', icon: 'portrait' },
|
|
492
|
+
{ value: 'landscape', label: 'Landscape', icon: 'landscape' }
|
|
470
493
|
],
|
|
471
494
|
read: (target) => orientationOf(target.page),
|
|
472
495
|
write: (target, value) => setOrientation(target, value)
|
|
@@ -479,6 +502,186 @@ function pageFields(layout) {
|
|
|
479
502
|
}
|
|
480
503
|
|
|
481
504
|
|
|
505
|
+
/* ---------------- margins ---------------- */
|
|
506
|
+
|
|
507
|
+
export const MARGIN_SIDES = ['top', 'right', 'bottom', 'left'];
|
|
508
|
+
|
|
509
|
+
const SIDE_LABELS = { top: 'Top', right: 'Right', bottom: 'Bottom', left: 'Left' };
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* A margin is switched off by printing it as 0 and keeping what it was beside
|
|
514
|
+
* it, in `page.marginOff` - `{ left: 40 }` for a left margin switched off at
|
|
515
|
+
* 40px. Switching it back on puts the 40 back.
|
|
516
|
+
*
|
|
517
|
+
* `page.margin` therefore always holds the margins that print, and the engine,
|
|
518
|
+
* the renderer and the canvas - which all read it directly - never have to
|
|
519
|
+
* know a margin can be off. Only the rail and the validator do.
|
|
520
|
+
*
|
|
521
|
+
* `page.marginLinked` is the lock a design tool has on padding: while it is
|
|
522
|
+
* set, a number typed into any side is written to all four.
|
|
523
|
+
*
|
|
524
|
+
* Both keys are left off the file entirely when they say nothing, as `paper`
|
|
525
|
+
* is: a report with every margin on and no lock looks as it always did.
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
/** @returns {boolean} whether the side prints its margin */
|
|
530
|
+
export function marginIsOn(page, side) {
|
|
531
|
+
return !(page?.marginOff && side in page.marginOff);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
/** the side's number - what it prints, or what it will print once back on */
|
|
536
|
+
function marginValue(page, side) {
|
|
537
|
+
return marginIsOn(page, side) ? page?.margin?.[side] : page.marginOff[side];
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
/** an empty `marginOff` says nothing, so it is not written */
|
|
542
|
+
function tidyMarginOff(page) {
|
|
543
|
+
if (page.marginOff && !Object.keys(page.marginOff).length) delete page.marginOff;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Switches one side's margin off or back on.
|
|
549
|
+
*
|
|
550
|
+
* @param {object} page mutated in place
|
|
551
|
+
* @param {string} side
|
|
552
|
+
* @param {boolean} on
|
|
553
|
+
* @returns {boolean} whether anything changed
|
|
554
|
+
*/
|
|
555
|
+
export function setMarginOn(page, side, on) {
|
|
556
|
+
if (marginIsOn(page, side) === on) return false;
|
|
557
|
+
|
|
558
|
+
if (on) {
|
|
559
|
+
page.margin[side] = page.marginOff[side];
|
|
560
|
+
delete page.marginOff[side];
|
|
561
|
+
tidyMarginOff(page);
|
|
562
|
+
} else {
|
|
563
|
+
page.marginOff = { ...page.marginOff, [side]: page.margin[side] };
|
|
564
|
+
page.margin[side] = 0;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* The section's own switch: off takes every margin away, on puts every one
|
|
573
|
+
* back. It reads as on while any side is, so one click on a page with some
|
|
574
|
+
* margins switched off clears the rest, and the next brings them all back.
|
|
575
|
+
*
|
|
576
|
+
* @param {object} page mutated in place
|
|
577
|
+
* @param {boolean} on
|
|
578
|
+
* @returns {boolean} whether anything changed
|
|
579
|
+
*/
|
|
580
|
+
export function setMarginsOn(page, on) {
|
|
581
|
+
let changed = false;
|
|
582
|
+
for (const side of MARGIN_SIDES) changed = setMarginOn(page, side, on) || changed;
|
|
583
|
+
return changed;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Sets a side's number. A side that is off keeps the number for when it is
|
|
589
|
+
* switched on, and still prints nothing. With the lock on, every side takes it.
|
|
590
|
+
*
|
|
591
|
+
* @param {object} page mutated in place
|
|
592
|
+
* @param {string} side
|
|
593
|
+
* @param {number} value
|
|
594
|
+
* @returns {boolean} whether anything changed
|
|
595
|
+
*/
|
|
596
|
+
export function setMarginValue(page, side, value) {
|
|
597
|
+
const sides = page.marginLinked ? MARGIN_SIDES : [side];
|
|
598
|
+
let changed = false;
|
|
599
|
+
|
|
600
|
+
for (const one of sides) {
|
|
601
|
+
const store = marginIsOn(page, one) ? page.margin : page.marginOff;
|
|
602
|
+
if (store[one] === value) continue;
|
|
603
|
+
|
|
604
|
+
store[one] = value;
|
|
605
|
+
changed = true;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return changed;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Turns the lock on or off. Locking makes the four sides one number, so they
|
|
614
|
+
* all take the first side that is printing one - the top, usually - or the
|
|
615
|
+
* top's own if none is.
|
|
616
|
+
*
|
|
617
|
+
* @param {object} page mutated in place
|
|
618
|
+
* @param {boolean} linked
|
|
619
|
+
* @returns {boolean} whether anything changed
|
|
620
|
+
*/
|
|
621
|
+
export function setMarginLinked(page, linked) {
|
|
622
|
+
if (Boolean(page.marginLinked) === linked) return false;
|
|
623
|
+
|
|
624
|
+
if (!linked) {
|
|
625
|
+
delete page.marginLinked;
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
page.marginLinked = true;
|
|
630
|
+
|
|
631
|
+
const lead = MARGIN_SIDES.find(side => marginIsOn(page, side)) ?? 'top';
|
|
632
|
+
setMarginValue(page, lead, marginValue(page, lead));
|
|
633
|
+
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* The Margins section: a switch for all of them and the lock across the top,
|
|
640
|
+
* then a row per side - its switch on the left, its number on the right. A
|
|
641
|
+
* side that is off shows the number it will come back with, greyed and not
|
|
642
|
+
* editable; the switches rebuild the rail so the boxes follow them.
|
|
643
|
+
*
|
|
644
|
+
* The number boxes keep the paths they always had, so anything that finds a
|
|
645
|
+
* margin's box by `page.margin.top` still does.
|
|
646
|
+
*
|
|
647
|
+
* @param {object} layout
|
|
648
|
+
* @returns {object[]}
|
|
649
|
+
*/
|
|
650
|
+
function marginFields(layout) {
|
|
651
|
+
const all = {
|
|
652
|
+
key: 'page.marginsOn', label: 'All sides', type: 'toggle', half: true,
|
|
653
|
+
rebuilds: true,
|
|
654
|
+
read: (target) => MARGIN_SIDES.some(side => marginIsOn(target.page, side)),
|
|
655
|
+
write: (target, on) => setMarginsOn(target.page, on)
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const linked = {
|
|
659
|
+
key: 'page.marginLinked', label: 'Same value', type: 'toggle', half: true,
|
|
660
|
+
rebuilds: true,
|
|
661
|
+
read: (target) => Boolean(target.page?.marginLinked),
|
|
662
|
+
write: (target, on) => setMarginLinked(target.page, on)
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
const rows = MARGIN_SIDES.flatMap(side => [
|
|
666
|
+
{
|
|
667
|
+
key: `page.marginOn.${side}`, label: SIDE_LABELS[side], type: 'toggle', half: true,
|
|
668
|
+
rebuilds: true,
|
|
669
|
+
read: (target) => marginIsOn(target.page, side),
|
|
670
|
+
write: (target, on) => setMarginOn(target.page, side, on)
|
|
671
|
+
},
|
|
672
|
+
num(`page.margin.${side}`, `${SIDE_LABELS[side]} margin`, {
|
|
673
|
+
min: 0,
|
|
674
|
+
short: SIDE_LABELS[side][0],
|
|
675
|
+
disabled: !marginIsOn(layout.page, side),
|
|
676
|
+
read: (target) => marginValue(target.page, side),
|
|
677
|
+
write: (target, value) => setMarginValue(target.page, side, value)
|
|
678
|
+
})
|
|
679
|
+
]);
|
|
680
|
+
|
|
681
|
+
return [all, linked, ...rows];
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
|
|
482
685
|
/**
|
|
483
686
|
* The report's own properties - what the rail shows when no item is selected.
|
|
484
687
|
*
|
|
@@ -490,6 +693,11 @@ function pageFields(layout) {
|
|
|
490
693
|
* @returns {object[]} `{ title, fields }` sections
|
|
491
694
|
*/
|
|
492
695
|
export function reportFields(layout) {
|
|
696
|
+
/**
|
|
697
|
+
* No *Group by* here any more. Grouping is a table's own - each grouped
|
|
698
|
+
* table carries its field and the bands its groups are drawn with - so it
|
|
699
|
+
* is set on the table, where there is no question which one it means.
|
|
700
|
+
*/
|
|
493
701
|
if (!layout) return [];
|
|
494
702
|
|
|
495
703
|
return [
|
|
@@ -501,11 +709,6 @@ export function reportFields(layout) {
|
|
|
501
709
|
key: 'dataset', label: 'Dataset', type: 'text', nullable: true,
|
|
502
710
|
hint: 'The key in the data object that drives the rows, ' +
|
|
503
711
|
'for every table that does not name its own'
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
key: 'groupBy', label: 'Group by', type: 'text', nullable: true,
|
|
507
|
-
hint: 'A field name, or blank for no grouping. Groups the ' +
|
|
508
|
-
'first table, unless a table sets its own'
|
|
509
712
|
}
|
|
510
713
|
]
|
|
511
714
|
},
|
|
@@ -515,17 +718,73 @@ export function reportFields(layout) {
|
|
|
515
718
|
},
|
|
516
719
|
{
|
|
517
720
|
title: 'Margins',
|
|
721
|
+
fields: marginFields(layout)
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
/**
|
|
725
|
+
* What every number and date format in the report falls back on.
|
|
726
|
+
* A text item or a column says it is money or a date; how money
|
|
727
|
+
* and dates are written is said once, here.
|
|
728
|
+
*/
|
|
729
|
+
title: 'Numbers and dates',
|
|
518
730
|
fields: [
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
731
|
+
{
|
|
732
|
+
key: 'format.grouping', label: 'Digit groups', type: 'choice',
|
|
733
|
+
options: [
|
|
734
|
+
{ value: 'international', label: '1,234,567' },
|
|
735
|
+
{ value: 'indian', label: '12,34,567 (Indian)' },
|
|
736
|
+
{ value: 'none', label: '1234567' }
|
|
737
|
+
]
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
key: 'format.symbol', label: 'Currency', type: 'choice',
|
|
741
|
+
options: CURRENCY_SYMBOLS, custom: true,
|
|
742
|
+
hint: 'The symbol currency formats print; Custom… for one not listed'
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: 'format.symbolPosition', label: 'Symbol goes', type: 'choice',
|
|
746
|
+
options: [
|
|
747
|
+
{ value: 'before', label: 'Before ₹100' },
|
|
748
|
+
{ value: 'after', label: 'After 100 ₹' }
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
key: 'format.pattern', label: 'Dates', type: 'choice',
|
|
753
|
+
options: datePatternChoices(layout.format?.pattern),
|
|
754
|
+
hint: 'How a date prints unless its own format says otherwise'
|
|
755
|
+
}
|
|
756
|
+
],
|
|
757
|
+
actions: [{
|
|
758
|
+
action: 'format-india', label: 'Use Indian: ₹, 1,00,000, dd/MM/yyyy',
|
|
759
|
+
title: 'Indian digit groups, the rupee and day/month/year dates'
|
|
760
|
+
}]
|
|
524
761
|
}
|
|
525
762
|
];
|
|
526
763
|
}
|
|
527
764
|
|
|
528
765
|
|
|
766
|
+
/**
|
|
767
|
+
* The date layouts a choice offers, each shown as the date it prints - ISO
|
|
768
|
+
* first, being the default. A pattern the report already has that is not one
|
|
769
|
+
* of them is offered too, so the choice can show it.
|
|
770
|
+
* @param {string|undefined} current
|
|
771
|
+
* @returns {{value: string, label: string}[]}
|
|
772
|
+
*/
|
|
773
|
+
export function datePatternChoices(current) {
|
|
774
|
+
const patterns = ['yyyy-MM-dd', ...DATE_PATTERNS.filter(p => p !== 'yyyy-MM-dd')];
|
|
775
|
+
if (typeof current === 'string' && current && !patterns.includes(current)) patterns.push(current);
|
|
776
|
+
|
|
777
|
+
return patterns.map(pattern => ({
|
|
778
|
+
value: pattern,
|
|
779
|
+
label: formatValue(SAMPLE_DATE, { type: 'date', pattern })
|
|
780
|
+
}));
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
/** the day the format choices are shown with */
|
|
785
|
+
const SAMPLE_DATE = '2026-06-17';
|
|
786
|
+
|
|
787
|
+
|
|
529
788
|
export function allReportFields(layout) {
|
|
530
789
|
return reportFields(layout).flatMap(section => section.fields);
|
|
531
790
|
}
|
|
@@ -537,6 +796,25 @@ export function allFields(item) {
|
|
|
537
796
|
}
|
|
538
797
|
|
|
539
798
|
|
|
799
|
+
/**
|
|
800
|
+
* A table's *Group by*: the field its own grouping splits the rows by.
|
|
801
|
+
*
|
|
802
|
+
* Derived rather than a path, because there is more to turning grouping on
|
|
803
|
+
* than one value - a table that was not grouped gets a header to show its
|
|
804
|
+
* groups in, and clearing the box takes the grouping away. setGroupBy is where
|
|
805
|
+
* that is decided. It rebuilds the rail when it turns grouping on or off,
|
|
806
|
+
* since that is when the table's group band controls come and go.
|
|
807
|
+
*/
|
|
808
|
+
const GROUP_BY = {
|
|
809
|
+
key: 'groupBy', label: 'Group by', type: 'text', nullable: true,
|
|
810
|
+
hint: 'A field to group these rows by, or blank. Each grouped table has ' +
|
|
811
|
+
'its own group header and footer',
|
|
812
|
+
read: (table) => levelsOf(table)[0]?.by ?? table.groupBy ?? null,
|
|
813
|
+
write: (table, value) => setGroupBy(table, value),
|
|
814
|
+
rebuilds: (table) => levelsOf(table).length > 0
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
|
|
540
818
|
function pathOf(key) {
|
|
541
819
|
return key.split('.');
|
|
542
820
|
}
|
|
@@ -567,6 +845,37 @@ export function readField(item, field) {
|
|
|
567
845
|
}
|
|
568
846
|
|
|
569
847
|
|
|
848
|
+
/**
|
|
849
|
+
* Takes a value off an item, so it is as if it had never been set - which for
|
|
850
|
+
* a colour is "none": a box with no fill, text in the stylesheet's colour.
|
|
851
|
+
*
|
|
852
|
+
* Removed rather than written as null, because absent is what an item that was
|
|
853
|
+
* never given one says, and the engine and the renderer read the two alike.
|
|
854
|
+
*
|
|
855
|
+
* @param {object} item mutated in place
|
|
856
|
+
* @param {object} field
|
|
857
|
+
* @returns {boolean} true when there was a value to take off
|
|
858
|
+
*/
|
|
859
|
+
export function clearField(item, field) {
|
|
860
|
+
if (field.read || field.write) return false;
|
|
861
|
+
|
|
862
|
+
const path = pathOf(field.key);
|
|
863
|
+
const last = path.pop();
|
|
864
|
+
|
|
865
|
+
let node = item;
|
|
866
|
+
for (const step of path) {
|
|
867
|
+
if (node?.[step] == null || typeof node[step] !== 'object') return false;
|
|
868
|
+
node = node[step];
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/** a null standing in the file is already none */
|
|
872
|
+
if (node[last] == null) return false;
|
|
873
|
+
|
|
874
|
+
delete node[last];
|
|
875
|
+
return true;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
|
|
570
879
|
/**
|
|
571
880
|
* Puts a typed value onto an item, and says whether anything changed.
|
|
572
881
|
*
|
package/src/designer/geometry.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
import { DESIGN_ROWS, designHeight } from '../engine/measure.js';
|
|
12
|
+
import { DESIGN_ROWS, designHeight as printedDesignHeight } from '../engine/measure.js';
|
|
13
|
+
import { levelsOf } from '../engine/tables.js';
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
/** spec 5.2: positions snap to a 10px grid */
|
|
@@ -51,12 +52,84 @@ export function snap(value) {
|
|
|
51
52
|
* equivalent, and it is the same figure the canvas draws with, so the selection
|
|
52
53
|
* outline lands exactly on the table rather than near it.
|
|
53
54
|
*
|
|
54
|
-
*
|
|
55
|
+
* Built on the engine's figure rather than written twice: that is the height
|
|
55
56
|
* paginate.js treats as the table's designed size, and the canvas and the
|
|
56
|
-
* printed page have to agree about
|
|
57
|
+
* printed page have to agree about it or nothing below a table lands where it
|
|
57
58
|
* was put.
|
|
59
|
+
*
|
|
60
|
+
* A grouped table is drawn as one group - its column headings, its group
|
|
61
|
+
* header, the sample rows, its group footer - because that is the unit it
|
|
62
|
+
* prints in, so its box on the canvas is taller by its two group bands. The
|
|
63
|
+
* engine's figure leaves them out, and a table grows from that figure at print
|
|
64
|
+
* time, so what sits below the table still clears it there.
|
|
65
|
+
*
|
|
66
|
+
* @param {object} item
|
|
67
|
+
* @returns {number} pixels
|
|
68
|
+
*/
|
|
69
|
+
export function designHeight(item) {
|
|
70
|
+
const height = printedDesignHeight(item);
|
|
71
|
+
if (item?.type !== 'table') return height;
|
|
72
|
+
|
|
73
|
+
return height + levelsOf(item).reduce((sum, level) =>
|
|
74
|
+
sum + stripHeight(level?.header) + stripHeight(level?.footer), 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Where every group band of a grouped table sits inside its box, in the order a
|
|
80
|
+
* group draws them: below the column headings each level's header, outermost
|
|
81
|
+
* first; then the sample rows; then each level's footer, innermost first.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} table
|
|
84
|
+
* @returns {{kind: string, level: number, band: object, y: number, h: number}[]}
|
|
85
|
+
* offsets from the table's own top; only the bands the table has
|
|
86
|
+
*/
|
|
87
|
+
export function levelStrips(table) {
|
|
88
|
+
const levels = levelsOf(table);
|
|
89
|
+
|
|
90
|
+
const rowHeight = table?.rowHeight ?? 0;
|
|
91
|
+
let y = table?.showHeader ? (table.headerHeight ?? rowHeight) : 0;
|
|
92
|
+
|
|
93
|
+
const strips = [];
|
|
94
|
+
const add = (kind, level, band) => {
|
|
95
|
+
if (!band) return;
|
|
96
|
+
const h = stripHeight(band);
|
|
97
|
+
strips.push({ kind, level, band, y, h });
|
|
98
|
+
y += h;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
levels.forEach((level, n) => add('groupHeader', n, level?.header));
|
|
102
|
+
y += DESIGN_ROWS * rowHeight;
|
|
103
|
+
for (let n = levels.length - 1; n >= 0; n--) add('groupFooter', n, levels[n]?.footer);
|
|
104
|
+
|
|
105
|
+
return strips;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Where a grouped table's outermost group bands sit inside its box - what a
|
|
111
|
+
* table grouped at one level has. levelStrips has every level's.
|
|
112
|
+
*
|
|
113
|
+
* @param {object} table
|
|
114
|
+
* @returns {{groupHeader: {y: number, h: number}|null,
|
|
115
|
+
* groupFooter: {y: number, h: number}|null}}
|
|
116
|
+
* offsets from the table's own top; null for a band the table does not have
|
|
58
117
|
*/
|
|
59
|
-
export
|
|
118
|
+
export function groupStrips(table) {
|
|
119
|
+
const outer = (kind) => {
|
|
120
|
+
const strip = levelStrips(table).find(s => s.kind === kind && s.level === 0);
|
|
121
|
+
return strip ? { y: strip.y, h: strip.h } : null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return { groupHeader: outer('groupHeader'), groupFooter: outer('groupFooter') };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/** a group band's height, in pixels - only a number counts, as in validate.js */
|
|
129
|
+
export function stripHeight(band) {
|
|
130
|
+
const height = Number(band?.height);
|
|
131
|
+
return band && Number.isFinite(height) && height > 0 ? height : 0;
|
|
132
|
+
}
|
|
60
133
|
|
|
61
134
|
|
|
62
135
|
/** an item's box in band-relative coordinates */
|