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/src/designer/panel.js
CHANGED
|
@@ -19,9 +19,15 @@
|
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
21
|
fieldsFor, allFields, reportFields, allReportFields,
|
|
22
|
-
COLUMN_FIELDS, readField, writeField
|
|
22
|
+
COLUMN_FIELDS, readField, writeField, clearField
|
|
23
23
|
} from './fields.js';
|
|
24
|
-
import {
|
|
24
|
+
import { BAND_NOTES, hasBand, findBand, railBands } from './structure.js';
|
|
25
|
+
import {
|
|
26
|
+
parseBandKey, bandLabel, groupBandKey, groupedTables, setGroupBy, setGroupOption, GROUP_KINDS
|
|
27
|
+
} from './grouping.js';
|
|
28
|
+
import { levelsOf, MAX_GROUP_LEVELS } from '../engine/tables.js';
|
|
29
|
+
import { describeFormat } from '../engine/format.js';
|
|
30
|
+
import { describeHighlight } from '../engine/highlight.js';
|
|
25
31
|
import { esc, imageSrc } from '../render/items.js';
|
|
26
32
|
|
|
27
33
|
|
|
@@ -35,16 +41,183 @@ import { esc, imageSrc } from '../render/items.js';
|
|
|
35
41
|
/**
|
|
36
42
|
* The rail for a selected item.
|
|
37
43
|
* @param {object} item
|
|
44
|
+
* @param {object} [layout] the report it is in, which a grouped table's own
|
|
45
|
+
* group band controls need - the other grouped tables, to copy a design from
|
|
38
46
|
* @returns {string} markup
|
|
39
47
|
*/
|
|
40
|
-
export function drawPanel(item) {
|
|
48
|
+
export function drawPanel(item, layout = null) {
|
|
41
49
|
return `
|
|
42
50
|
<div class="dz-panel-head">
|
|
43
51
|
<span class="dz-panel-type">${esc(item.type)}</span>
|
|
44
52
|
<span class="dz-panel-id">${esc(item.id)}</span>
|
|
45
53
|
</div>
|
|
46
54
|
${sections(item, fieldsFor(item))}
|
|
47
|
-
${item.type === '
|
|
55
|
+
${item.type === 'text' ? `
|
|
56
|
+
<section class="dz-section">
|
|
57
|
+
<h3>Format</h3>
|
|
58
|
+
<div class="dz-field dz-field-format">
|
|
59
|
+
<label>Values</label>
|
|
60
|
+
${formatButton(item, layout)}
|
|
61
|
+
</div>
|
|
62
|
+
<div class="dz-field dz-field-format">
|
|
63
|
+
<label>Highlight</label>
|
|
64
|
+
${highlightButton(item.highlight, 'edit-highlight')}
|
|
65
|
+
</div>
|
|
66
|
+
</section>` : ''}
|
|
67
|
+
${item.type === 'table' ? `
|
|
68
|
+
<section class="dz-section">
|
|
69
|
+
<h3>Row highlight</h3>
|
|
70
|
+
<div class="dz-field dz-field-format">
|
|
71
|
+
<label>Rows</label>
|
|
72
|
+
${highlightButton(item.rowHighlight, 'edit-row-highlight')}
|
|
73
|
+
</div>
|
|
74
|
+
</section>` : ''}
|
|
75
|
+
${item.type === 'table' ? grouping(item, layout) : ''}
|
|
76
|
+
${item.type === 'table' ? columns(item, layout) : ''}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A grouped table's own group bands, switched on and off and sized here as
|
|
82
|
+
* well as in the report's band list - this is where somebody who has just set
|
|
83
|
+
* *Group by* is looking.
|
|
84
|
+
*
|
|
85
|
+
* And, when another table is grouped too, a way to give this one the same
|
|
86
|
+
* header and footer: each grouping is a table's own, so two that should look
|
|
87
|
+
* alike are made alike by copying.
|
|
88
|
+
*
|
|
89
|
+
* @param {object} table
|
|
90
|
+
* @param {object|null} layout
|
|
91
|
+
* @returns {string} markup, empty for a table that is not grouped
|
|
92
|
+
*/
|
|
93
|
+
function grouping(table, layout) {
|
|
94
|
+
const levels = levelsOf(table);
|
|
95
|
+
if (!levels.length) return '';
|
|
96
|
+
|
|
97
|
+
/** the table alone is enough to find its own bands */
|
|
98
|
+
const scope = layout ?? { bands: [{ type: 'detail', items: [table] }] };
|
|
99
|
+
|
|
100
|
+
const others = layout
|
|
101
|
+
? groupedTables(layout).filter(g => g.table !== table.id)
|
|
102
|
+
: [];
|
|
103
|
+
|
|
104
|
+
return `
|
|
105
|
+
<section class="dz-section dz-bands dz-grouping">
|
|
106
|
+
<h3>Grouping</h3>
|
|
107
|
+
${levels.map((level, n) => groupLevel(scope, table, level, n, levels.length)).join('')}
|
|
108
|
+
${levels.length < MAX_GROUP_LEVELS ? `
|
|
109
|
+
<button type="button" class="dz-add-row" data-action="add-group-level"
|
|
110
|
+
title="Split each group of this table again, by another field">
|
|
111
|
+
Group within each group</button>` : ''}
|
|
112
|
+
${others.map(g => `
|
|
113
|
+
<button type="button" class="dz-add-row" data-action="copy-grouping"
|
|
114
|
+
data-from="${esc(g.table)}"
|
|
115
|
+
title="Replace this table's group header and footer with copies of ${esc(g.table)}'s">
|
|
116
|
+
Copy group design from ${esc(g.table)}</button>`).join('')}
|
|
117
|
+
</section>`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* One level of a table's grouping: its band switches and, for a table grouped
|
|
123
|
+
* at more than one level, which field it groups by and the controls that move
|
|
124
|
+
* and remove it.
|
|
125
|
+
*
|
|
126
|
+
* The outermost level's field is the table's *Group by*, up with the table's
|
|
127
|
+
* other properties, so a table grouped once shows nothing here but its bands -
|
|
128
|
+
* as it always has.
|
|
129
|
+
*
|
|
130
|
+
* @param {object} scope a layout holding the table
|
|
131
|
+
* @param {object} table
|
|
132
|
+
* @param {object} level
|
|
133
|
+
* @param {number} n
|
|
134
|
+
* @param {number} depth how many levels the table has
|
|
135
|
+
* @returns {string} markup
|
|
136
|
+
*/
|
|
137
|
+
function groupLevel(scope, table, level, n, depth) {
|
|
138
|
+
const by = typeof level?.by === 'string' ? level.by : '';
|
|
139
|
+
const bands = levelBands(scope, table, by, n);
|
|
140
|
+
|
|
141
|
+
if (depth === 1) return `${levelOptions(level, n)}${bands}`;
|
|
142
|
+
|
|
143
|
+
const id = `dz-f-group-level-${n}`;
|
|
144
|
+
|
|
145
|
+
return `
|
|
146
|
+
<div class="dz-group-level" data-level="${n}">
|
|
147
|
+
<div class="dz-group-level-head">
|
|
148
|
+
<span class="dz-group-level-name">Level ${n + 1}${by ? ` · <b>${esc(by)}</b>` : ''}</span>
|
|
149
|
+
<span class="dz-group-level-actions">
|
|
150
|
+
${n > 0 ? `
|
|
151
|
+
<button type="button" class="dz-icon" data-action="move-group-level-out"
|
|
152
|
+
data-level="${n}"
|
|
153
|
+
title="Group by this before the level above it"
|
|
154
|
+
aria-label="Move level ${n + 1} out">↑</button>` : ''}
|
|
155
|
+
<button type="button" class="dz-icon" data-action="remove-group-level"
|
|
156
|
+
data-level="${n}"
|
|
157
|
+
title="Stop grouping by this, and remove its header and footer"
|
|
158
|
+
aria-label="Remove level ${n + 1}">×</button>
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
${n > 0 ? `
|
|
162
|
+
<div class="dz-field dz-field-text">
|
|
163
|
+
<label for="${id}">Then group by</label>
|
|
164
|
+
<input type="text" id="${id}" data-group-level="${n}"
|
|
165
|
+
value="${esc(by)}" spellcheck="false">
|
|
166
|
+
<p class="dz-hint">A field to group each group above by</p>
|
|
167
|
+
</div>` : ''}
|
|
168
|
+
${levelOptions(level, n)}
|
|
169
|
+
${bands}
|
|
170
|
+
</div>`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A level's header and footer switches, named for what they are inside the
|
|
176
|
+
* table's own section - "Header, before each region" - rather than by the key
|
|
177
|
+
* the report's band list needs.
|
|
178
|
+
*/
|
|
179
|
+
function levelBands(scope, table, by, n) {
|
|
180
|
+
const what = by || 'group';
|
|
181
|
+
|
|
182
|
+
return GROUP_KINDS.map(kind => bandRow(scope, groupBandKey(kind, table.id, n),
|
|
183
|
+
kind === 'groupHeader'
|
|
184
|
+
? { label: 'Group header', note: `Before each ${what}` }
|
|
185
|
+
: { label: 'Group footer', note: `After each ${what}` })).join('');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
/** the orders a level's groups can be put in, as the rail offers them */
|
|
190
|
+
const SORT_CHOICES = [
|
|
191
|
+
{ value: '', label: 'As they come' },
|
|
192
|
+
{ value: 'asc', label: 'A to Z, 0 to 9' },
|
|
193
|
+
{ value: 'desc', label: 'Z to A, 9 to 0' }
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* How one level's groups are ordered, and whether each starts a page.
|
|
199
|
+
* @param {object} level
|
|
200
|
+
* @param {number} n
|
|
201
|
+
* @returns {string} markup
|
|
202
|
+
*/
|
|
203
|
+
function levelOptions(level, n) {
|
|
204
|
+
const sort = typeof level?.sort === 'string' ? level.sort : '';
|
|
205
|
+
const id = `dz-f-group-${n}`;
|
|
206
|
+
|
|
207
|
+
return `
|
|
208
|
+
<div class="dz-field dz-field-choice">
|
|
209
|
+
<label for="${id}-sort">Order groups</label>
|
|
210
|
+
<select id="${id}-sort" data-group-option="sort" data-level="${n}">
|
|
211
|
+
${SORT_CHOICES.map(o => `<option value="${o.value}"${o.value === sort ? ' selected' : ''}
|
|
212
|
+
>${esc(o.label)}</option>`).join('')}
|
|
213
|
+
</select>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="dz-field dz-field-toggle">
|
|
216
|
+
<label for="${id}-page">New page for each group</label>
|
|
217
|
+
<input type="checkbox" id="${id}-page" data-group-option="newPage" data-level="${n}"
|
|
218
|
+
${level?.newPage === true ? 'checked' : ''}>
|
|
219
|
+
<p class="dz-hint">Every group but the first starts at the top of a page</p>
|
|
220
|
+
</div>`;
|
|
48
221
|
}
|
|
49
222
|
|
|
50
223
|
|
|
@@ -104,10 +277,60 @@ function sections(target, list) {
|
|
|
104
277
|
<section class="dz-section">
|
|
105
278
|
<h3>${esc(section.title)}</h3>
|
|
106
279
|
${section.fields.map(field => control(target, field)).join('')}
|
|
280
|
+
${(section.actions ?? []).map(a => `
|
|
281
|
+
<button type="button" class="dz-add-row dz-section-action"
|
|
282
|
+
data-action="${esc(a.action)}" title="${esc(a.title ?? '')}">
|
|
283
|
+
${esc(a.label)}</button>`).join('')}
|
|
107
284
|
</section>`).join('');
|
|
108
285
|
}
|
|
109
286
|
|
|
110
287
|
|
|
288
|
+
/**
|
|
289
|
+
* How a text item's values print: one line saying so, and the button that
|
|
290
|
+
* opens the Format Editor. The editor is a dialog rather than controls here -
|
|
291
|
+
* a currency alone is five choices, and the rail has only just got its room
|
|
292
|
+
* back.
|
|
293
|
+
*
|
|
294
|
+
* @param {object} owner a text item, or a column
|
|
295
|
+
* @param {object|null} layout for the report's defaults the summary shows through
|
|
296
|
+
* @param {string} [index] the column's place in its table, for a column
|
|
297
|
+
* @returns {string} markup
|
|
298
|
+
*/
|
|
299
|
+
function formatButton(owner, layout, index) {
|
|
300
|
+
const summary = describeFormat(owner?.format, layout?.format);
|
|
301
|
+
|
|
302
|
+
return `
|
|
303
|
+
<button type="button" class="dz-format" data-action="edit-format"
|
|
304
|
+
${index != null ? `data-index="${esc(index)}"` : ''}
|
|
305
|
+
title="${esc(summary)} - click to change how values print">
|
|
306
|
+
<span class="dz-format-summary">${esc(summary)}</span>
|
|
307
|
+
<span class="dz-format-edit">Edit</span>
|
|
308
|
+
</button>`;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The same summary-and-Edit button for highlight rules: how many there are,
|
|
314
|
+
* and the editor they are changed in.
|
|
315
|
+
*
|
|
316
|
+
* @param {object[]|null|undefined} rules
|
|
317
|
+
* @param {string} action the designer action that opens the editor
|
|
318
|
+
* @param {string} [index] a column's place, for a column's rules
|
|
319
|
+
* @returns {string} markup
|
|
320
|
+
*/
|
|
321
|
+
function highlightButton(rules, action, index) {
|
|
322
|
+
const summary = describeHighlight(rules);
|
|
323
|
+
|
|
324
|
+
return `
|
|
325
|
+
<button type="button" class="dz-format" data-action="${esc(action)}"
|
|
326
|
+
${index != null ? `data-index="${esc(index)}"` : ''}
|
|
327
|
+
title="${esc(summary)} - click to style values by what they are">
|
|
328
|
+
<span class="dz-format-summary">${esc(summary)}</span>
|
|
329
|
+
<span class="dz-format-edit">Edit</span>
|
|
330
|
+
</button>`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
111
334
|
function control(target, field, extra = '') {
|
|
112
335
|
const value = readField(target, field);
|
|
113
336
|
const id = `dz-f-${field.key.replace(/\./g, '-')}${extra ? `-${extra}` : ''}`;
|
|
@@ -158,18 +381,12 @@ function input(id, bind, field, value) {
|
|
|
158
381
|
</div>`;
|
|
159
382
|
|
|
160
383
|
case 'choice':
|
|
161
|
-
return `<select id="${id}" ${bind}>${field.options.map(o =>
|
|
384
|
+
return field.custom ? customChoice(id, bind, field, value) : `<select id="${id}" ${bind}>${field.options.map(o =>
|
|
162
385
|
`<option value="${esc(o.value)}"${o.value === value ? ' selected' : ''}
|
|
163
386
|
>${esc(o.label)}</option>`).join('')}</select>`;
|
|
164
387
|
|
|
165
388
|
case 'color':
|
|
166
|
-
|
|
167
|
-
* A colour input cannot hold null, and several style fields are
|
|
168
|
-
* legitimately absent - so the swatch falls back to black and the
|
|
169
|
-
* value is only written once someone actually picks one.
|
|
170
|
-
*/
|
|
171
|
-
return `<input type="color" id="${id}" ${bind}
|
|
172
|
-
value="${esc(value ?? '#000000')}">`;
|
|
389
|
+
return colorInput(id, bind, field, value);
|
|
173
390
|
|
|
174
391
|
case 'toggle':
|
|
175
392
|
return `<input type="checkbox" id="${id}" ${bind}
|
|
@@ -208,11 +425,96 @@ function input(id, bind, field, value) {
|
|
|
208
425
|
}
|
|
209
426
|
|
|
210
427
|
|
|
428
|
+
/**
|
|
429
|
+
* A group band's background: the same swatch a colour field has - "none" with
|
|
430
|
+
* a slash through it until one is picked, and a button to take it off again.
|
|
431
|
+
*/
|
|
432
|
+
function bandFill(type, band, label) {
|
|
433
|
+
const color = typeof band?.background === 'string' && band.background ? band.background : null;
|
|
434
|
+
|
|
435
|
+
return `
|
|
436
|
+
<span class="dz-swatch dz-band-fill${color ? '' : ' is-none'}"
|
|
437
|
+
title="${esc(label)} background">
|
|
438
|
+
<span class="dz-swatch-well">
|
|
439
|
+
<input type="color" data-band-fill="${esc(type)}" value="${esc(color ?? '#ffffff')}"
|
|
440
|
+
aria-label="${esc(label)} background">
|
|
441
|
+
</span>
|
|
442
|
+
<button type="button" class="dz-icon dz-swatch-clear" data-action="clear-band-fill"
|
|
443
|
+
data-fill-for="${esc(type)}" title="No background"
|
|
444
|
+
aria-label="Remove ${esc(label)} background">×</button>
|
|
445
|
+
</span>`;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
/** what a choice's Custom… option says, which no real value can */
|
|
450
|
+
const CUSTOM_CHOICE = '__custom__';
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A choice of the usual values, and Custom… for any other - the currency
|
|
455
|
+
* symbol, where ₹ and $ cover most reports and CHF still has to be possible.
|
|
456
|
+
*
|
|
457
|
+
* The select and the box are both bound to the field. The select writes what
|
|
458
|
+
* it is set to, except Custom…, which only shows the box; the box writes what
|
|
459
|
+
* is typed into it. A value that is none of the options shows as Custom…,
|
|
460
|
+
* with the box holding it.
|
|
461
|
+
*/
|
|
462
|
+
function customChoice(id, bind, field, value) {
|
|
463
|
+
const listed = field.options.some(o => o.value === (value ?? ''));
|
|
464
|
+
const selected = listed ? (value ?? '') : CUSTOM_CHOICE;
|
|
465
|
+
|
|
466
|
+
return `
|
|
467
|
+
<span class="dz-choice-custom">
|
|
468
|
+
<select id="${id}" ${bind}>${[...field.options, { value: CUSTOM_CHOICE, label: 'Custom…' }]
|
|
469
|
+
.map(o => `<option value="${esc(o.value)}"${o.value === selected ? ' selected' : ''}
|
|
470
|
+
>${esc(o.label)}</option>`).join('')}</select>
|
|
471
|
+
<input type="text" ${bind} data-custom="true" value="${esc(listed ? '' : value ?? '')}"
|
|
472
|
+
spellcheck="false" maxlength="6" aria-label="${esc(field.label)}, custom"
|
|
473
|
+
placeholder="such as CHF"${listed ? ' hidden' : ''}>
|
|
474
|
+
</span>`;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* A colour, or none.
|
|
480
|
+
*
|
|
481
|
+
* A colour input cannot hold null, and several style fields are legitimately
|
|
482
|
+
* absent - a box with no fill, text in the stylesheet's colour. Drawn as the
|
|
483
|
+
* input's black, an absent colour looked like a chosen one. So the input sits
|
|
484
|
+
* under a "none" swatch while there is no colour, and still opens the picker
|
|
485
|
+
* when clicked; the value is only written once someone actually picks one.
|
|
486
|
+
* A chosen colour gets a button that takes it off again.
|
|
487
|
+
*
|
|
488
|
+
* Whether it is none is a class on the wrapper, which the input and syncPanel
|
|
489
|
+
* keep up to date - rebuilding the rail while the picker is open would close it.
|
|
490
|
+
*/
|
|
491
|
+
function colorInput(id, bind, field, value) {
|
|
492
|
+
const none = value == null || value === '';
|
|
493
|
+
|
|
494
|
+
return `
|
|
495
|
+
<span class="dz-swatch${none ? ' is-none' : ''}">
|
|
496
|
+
<span class="dz-swatch-well">
|
|
497
|
+
<input type="color" id="${id}" ${bind} value="${esc(none ? '#000000' : value)}">
|
|
498
|
+
</span>
|
|
499
|
+
<span class="dz-swatch-none" aria-hidden="true">None</span>
|
|
500
|
+
<button type="button" class="dz-icon dz-swatch-clear" data-action="clear-color"
|
|
501
|
+
data-for="${esc(field.key)}"
|
|
502
|
+
title="No colour" aria-label="Remove ${esc(field.label)} colour">×</button>
|
|
503
|
+
</span>`;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
/** shows a colour control as none, or as its colour */
|
|
508
|
+
function markSwatch(node, none) {
|
|
509
|
+
node.closest?.('.dz-swatch')?.classList.toggle('is-none', none);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
211
513
|
/**
|
|
212
514
|
* A table's columns, one card each. Four controls on one row would be 60px wide
|
|
213
515
|
* apiece in a rail this narrow, so they stack and the card carries the number.
|
|
214
516
|
*/
|
|
215
|
-
function columns(table) {
|
|
517
|
+
function columns(table, layout) {
|
|
216
518
|
const list = table.columns || [];
|
|
217
519
|
|
|
218
520
|
return `
|
|
@@ -230,6 +532,14 @@ function columns(table) {
|
|
|
230
532
|
</div>
|
|
231
533
|
${COLUMN_FIELDS.map(field =>
|
|
232
534
|
control(column, field, String(index))).join('')}
|
|
535
|
+
<div class="dz-field dz-field-format">
|
|
536
|
+
<label>Format</label>
|
|
537
|
+
${formatButton(column, layout, String(index))}
|
|
538
|
+
</div>
|
|
539
|
+
<div class="dz-field dz-field-format">
|
|
540
|
+
<label>Highlight</label>
|
|
541
|
+
${highlightButton(column.highlight, 'edit-highlight', String(index))}
|
|
542
|
+
</div>
|
|
233
543
|
</div>`).join('')}
|
|
234
544
|
<button type="button" class="dz-add-row" data-action="add-column">
|
|
235
545
|
Add column</button>
|
|
@@ -242,37 +552,73 @@ function columns(table) {
|
|
|
242
552
|
*
|
|
243
553
|
* A checkbox each, in page order, rather than a list that can be reordered -
|
|
244
554
|
* validate.js allows one band of each type and regions.js decides where each
|
|
245
|
-
* sits, so there is no order here for anyone to choose.
|
|
555
|
+
* sits, so there is no order here for anyone to choose. Each grouped table's
|
|
556
|
+
* own header and footer are listed with the report's, named for their table.
|
|
246
557
|
*/
|
|
247
558
|
function bands(layout) {
|
|
248
559
|
return `
|
|
249
560
|
<section class="dz-section dz-bands">
|
|
250
561
|
<h3>Bands</h3>
|
|
251
|
-
${
|
|
252
|
-
const band = findBand(layout, type);
|
|
253
|
-
const on = hasBand(layout, type);
|
|
254
|
-
|
|
255
|
-
return `
|
|
256
|
-
<div class="dz-band-row${on ? ' is-on' : ''}">
|
|
257
|
-
<label class="dz-band-name">
|
|
258
|
-
<input type="checkbox" data-band="${esc(type)}" ${on ? 'checked' : ''}>
|
|
259
|
-
<span>${esc(type)}</span>
|
|
260
|
-
</label>
|
|
261
|
-
${on && type !== 'detail'
|
|
262
|
-
? `<input type="text" class="dz-band-height"
|
|
263
|
-
data-band-height="${esc(type)}"
|
|
264
|
-
value="${esc(band.height ?? '')}"
|
|
265
|
-
placeholder="auto" spellcheck="false"
|
|
266
|
-
aria-label="${esc(type)} height">`
|
|
267
|
-
: `<span class="dz-band-height-none">${
|
|
268
|
-
type === 'detail' ? 'what is left' : ''}</span>`}
|
|
269
|
-
<p class="dz-hint">${esc(BAND_NOTES[type] ?? '')}</p>
|
|
270
|
-
</div>`;
|
|
271
|
-
}).join('')}
|
|
562
|
+
${railBands(layout).map(type => bandRow(layout, type)).join('')}
|
|
272
563
|
</section>`;
|
|
273
564
|
}
|
|
274
565
|
|
|
275
566
|
|
|
567
|
+
/** what a band row says under its name */
|
|
568
|
+
function bandNote(type) {
|
|
569
|
+
const parsed = parseBandKey(type);
|
|
570
|
+
if (!parsed) return BAND_NOTES[type] ?? '';
|
|
571
|
+
|
|
572
|
+
const whose = parsed.level > 0
|
|
573
|
+
? `level ${parsed.level + 1} group of ${parsed.table}`
|
|
574
|
+
: `group of ${parsed.table}`;
|
|
575
|
+
|
|
576
|
+
return parsed.kind === 'groupHeader' ? `Before each ${whose}` : `After each ${whose}`;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* One band's switch and height, by key.
|
|
582
|
+
*
|
|
583
|
+
* The report's band list names a table's group band in full - whose it is and
|
|
584
|
+
* which level - because it sits among every other band. Inside the table's own
|
|
585
|
+
* grouping section both are already said by where it is, so that section
|
|
586
|
+
* passes a shorter name and note of its own.
|
|
587
|
+
*
|
|
588
|
+
* @param {object} layout
|
|
589
|
+
* @param {string} type a band type, or a table's group band key
|
|
590
|
+
* @param {{label?: string, note?: string}} [names]
|
|
591
|
+
* @returns {string} markup
|
|
592
|
+
*/
|
|
593
|
+
function bandRow(layout, type, names = {}) {
|
|
594
|
+
const band = findBand(layout, type);
|
|
595
|
+
const on = hasBand(layout, type);
|
|
596
|
+
const label = names.label ?? bandLabel(type);
|
|
597
|
+
const note = names.note ?? bandNote(type);
|
|
598
|
+
|
|
599
|
+
/** a table's group band, switched on, can be shaded */
|
|
600
|
+
const fillable = on && parseBandKey(type) != null;
|
|
601
|
+
|
|
602
|
+
return `
|
|
603
|
+
<div class="dz-band-row${on ? ' is-on' : ''}${fillable ? ' has-fill' : ''}">
|
|
604
|
+
<label class="dz-band-name">
|
|
605
|
+
<input type="checkbox" data-band="${esc(type)}" ${on ? 'checked' : ''}>
|
|
606
|
+
<span>${esc(label)}</span>
|
|
607
|
+
</label>
|
|
608
|
+
${fillable ? bandFill(type, band, label) : ''}
|
|
609
|
+
${on && type !== 'detail'
|
|
610
|
+
? `<input type="text" class="dz-band-height"
|
|
611
|
+
data-band-height="${esc(type)}"
|
|
612
|
+
value="${esc(band.height ?? '')}"
|
|
613
|
+
placeholder="auto" spellcheck="false"
|
|
614
|
+
aria-label="${esc(label)} height">`
|
|
615
|
+
: `<span class="dz-band-height-none">${
|
|
616
|
+
type === 'detail' ? 'what is left' : ''}</span>`}
|
|
617
|
+
${note ? `<p class="dz-hint">${esc(note)}</p>` : ''}
|
|
618
|
+
</div>`;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
|
|
276
622
|
/**
|
|
277
623
|
* Wires one delegated listener set onto the rail. The rail element survives a
|
|
278
624
|
* redraw of its contents, so these are attached once and never rebound.
|
|
@@ -289,10 +635,12 @@ function bands(layout) {
|
|
|
289
635
|
* @param {(action: string, data: DOMStringMap) => void} options.act a button was pressed
|
|
290
636
|
* @param {(type: string, on: boolean) => void} options.toggleBand
|
|
291
637
|
* @param {(type: string, height: string) => void} options.setBandHeight
|
|
638
|
+
* @param {(type: string, color: string|null) => void} [options.setBandFill] a
|
|
639
|
+
* group band's background, null for none
|
|
292
640
|
* @returns {() => void} detaches
|
|
293
641
|
*/
|
|
294
642
|
export function attachPanel({
|
|
295
|
-
panel, getTarget, getItem, changed, act, toggleBand, setBandHeight
|
|
643
|
+
panel, getTarget, getItem, changed, act, toggleBand, setBandHeight, setBandFill = () => { }
|
|
296
644
|
}) {
|
|
297
645
|
/** keeps the marking layer under the text it belongs to */
|
|
298
646
|
function repaint(node) {
|
|
@@ -304,11 +652,36 @@ export function attachPanel({
|
|
|
304
652
|
|
|
305
653
|
|
|
306
654
|
function onInput(event) {
|
|
307
|
-
const node = event.target.closest?.(
|
|
655
|
+
const node = event.target.closest?.(
|
|
656
|
+
'[data-field], [data-band], [data-band-height], [data-band-fill], [data-group-level], [data-group-option]');
|
|
308
657
|
if (!node) return;
|
|
309
658
|
|
|
310
659
|
if (node.tagName === 'TEXTAREA') repaint(node);
|
|
311
660
|
|
|
661
|
+
/** how one level's groups are ordered and placed, on the selected table */
|
|
662
|
+
if (node.dataset.groupOption != null) {
|
|
663
|
+
const item = getItem();
|
|
664
|
+
const level = Number(node.dataset.level);
|
|
665
|
+
const option = node.dataset.groupOption;
|
|
666
|
+
const value = node.type === 'checkbox' ? node.checked : node.value;
|
|
667
|
+
|
|
668
|
+
if (item?.type === 'table' && setGroupOption(item, level, option, value)) {
|
|
669
|
+
changed(`group-option:${level}:${option}`);
|
|
670
|
+
}
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/** an inner level's field, on the selected table */
|
|
675
|
+
if (node.dataset.groupLevel != null) {
|
|
676
|
+
const item = getItem();
|
|
677
|
+
const level = Number(node.dataset.groupLevel);
|
|
678
|
+
|
|
679
|
+
if (item?.type === 'table' && setGroupBy(item, node.value.trim(), level)) {
|
|
680
|
+
changed(`group-level:${level}`);
|
|
681
|
+
}
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
|
|
312
685
|
if (node.dataset.band != null) {
|
|
313
686
|
toggleBand(node.dataset.band, node.checked);
|
|
314
687
|
return;
|
|
@@ -319,6 +692,13 @@ export function attachPanel({
|
|
|
319
692
|
return;
|
|
320
693
|
}
|
|
321
694
|
|
|
695
|
+
/** a colour picked is no longer none */
|
|
696
|
+
if (node.dataset.bandFill != null) {
|
|
697
|
+
markSwatch(node, false);
|
|
698
|
+
setBandFill(node.dataset.bandFill, node.value);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
|
|
322
702
|
/** a column control is bound to the column, not to the item */
|
|
323
703
|
if (node.dataset.column != null) {
|
|
324
704
|
const item = getItem();
|
|
@@ -338,15 +718,40 @@ export function attachPanel({
|
|
|
338
718
|
const field = bound.fields.find(f => f.key === node.dataset.field);
|
|
339
719
|
if (!field) return;
|
|
340
720
|
|
|
721
|
+
if (node.tagName === 'SELECT' && node.value === CUSTOM_CHOICE) {
|
|
722
|
+
const box = node.parentElement?.querySelector('[data-custom]');
|
|
723
|
+
if (box) {
|
|
724
|
+
box.hidden = false;
|
|
725
|
+
box.focus();
|
|
726
|
+
}
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
|
|
341
730
|
const raw = field.type === 'toggle' ? node.checked : node.value;
|
|
342
731
|
|
|
732
|
+
/** a colour picked is no longer none, even one picked as black */
|
|
733
|
+
if (field.type === 'color') markSwatch(node, false);
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* A field may say which reading of its object decides the rail's
|
|
737
|
+
* shape, rather than that every edit to it does - *Group by* changes
|
|
738
|
+
* the controls only when it turns grouping on or off, not on every
|
|
739
|
+
* letter of the field name.
|
|
740
|
+
*/
|
|
741
|
+
const shape = typeof field.rebuilds === 'function' ? field.rebuilds : null;
|
|
742
|
+
const before = shape ? shape(bound.target) : null;
|
|
743
|
+
|
|
343
744
|
if (writeField(bound.target, field, raw)) {
|
|
344
745
|
/**
|
|
345
746
|
* Some fields change which fields there are - choosing a named
|
|
346
747
|
* sheet takes the width and height boxes away, and Custom brings
|
|
347
748
|
* them back. The caller is told, because it owns the rail.
|
|
348
749
|
*/
|
|
349
|
-
|
|
750
|
+
const rebuild = shape
|
|
751
|
+
? shape(bound.target) !== before
|
|
752
|
+
: Boolean(field.rebuilds);
|
|
753
|
+
|
|
754
|
+
changed(`field:${field.key}`, { rebuild });
|
|
350
755
|
}
|
|
351
756
|
}
|
|
352
757
|
|
|
@@ -366,6 +771,25 @@ export function attachPanel({
|
|
|
366
771
|
return;
|
|
367
772
|
}
|
|
368
773
|
|
|
774
|
+
/** a group band's background, back to none */
|
|
775
|
+
if (node.dataset.action === 'clear-band-fill') {
|
|
776
|
+
markSwatch(node, true);
|
|
777
|
+
setBandFill(node.dataset.fillFor, null);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** handled here too: it is bound to a field, as the colour beside it is */
|
|
782
|
+
if (node.dataset.action === 'clear-color') {
|
|
783
|
+
const bound = getTarget();
|
|
784
|
+
const field = bound?.fields.find(f => f.key === node.dataset.for);
|
|
785
|
+
|
|
786
|
+
if (field && clearField(bound.target, field)) {
|
|
787
|
+
markSwatch(node, true);
|
|
788
|
+
changed(`field:${field.key}`);
|
|
789
|
+
}
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
|
|
369
793
|
act(node.dataset.action, node.dataset);
|
|
370
794
|
}
|
|
371
795
|
|
|
@@ -431,6 +855,22 @@ export function syncPanel(panel, item, layout) {
|
|
|
431
855
|
|
|
432
856
|
const value = readField(source, field);
|
|
433
857
|
|
|
858
|
+
/** an undo can take a colour off, or put one back */
|
|
859
|
+
if (field.type === 'color') markSwatch(node, value == null || value === '');
|
|
860
|
+
|
|
861
|
+
/** a choice with Custom…: the select says which, the box holds any other */
|
|
862
|
+
if (field.custom) {
|
|
863
|
+
const listed = field.options.some(o => o.value === (value ?? ''));
|
|
864
|
+
|
|
865
|
+
if (node.dataset.custom) {
|
|
866
|
+
node.value = listed ? '' : String(value ?? '');
|
|
867
|
+
node.hidden = listed;
|
|
868
|
+
} else {
|
|
869
|
+
node.value = listed ? String(value ?? '') : CUSTOM_CHOICE;
|
|
870
|
+
}
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
|
|
434
874
|
if (field.type === 'toggle') {
|
|
435
875
|
node.checked = Boolean(value);
|
|
436
876
|
} else if (value != null) {
|
package/src/designer/rulers.js
CHANGED
|
@@ -207,13 +207,15 @@ export function guideNear(layout, axis, at, within = GRAB) {
|
|
|
207
207
|
/**
|
|
208
208
|
* The guides that apply inside one band, in that band's own coordinates.
|
|
209
209
|
*
|
|
210
|
-
* A
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
210
|
+
* A horizontal guide is a different `y` in every band, which is the whole
|
|
211
|
+
* reason bands hold their items in their own coordinates in the first place.
|
|
212
|
+
* A vertical one is the same `x` in every band that runs the page's width,
|
|
213
|
+
* and is moved over for a table's group band, which starts where its table
|
|
214
|
+
* does.
|
|
214
215
|
*
|
|
215
216
|
* @param {object} layout
|
|
216
|
-
* @param {{originY: number, h: number}} band
|
|
217
|
+
* @param {{originX: number, originY: number, w: number, h: number}} band
|
|
218
|
+
* from canvas.bandBox
|
|
217
219
|
* @returns {{x: number[], y: number[]}}
|
|
218
220
|
*/
|
|
219
221
|
export function guidesInBand(layout, band) {
|
|
@@ -221,8 +223,14 @@ export function guidesInBand(layout, band) {
|
|
|
221
223
|
|
|
222
224
|
if (!band) return { x: all.x, y: [] };
|
|
223
225
|
|
|
226
|
+
const originX = band.originX ?? 0;
|
|
227
|
+
|
|
224
228
|
return {
|
|
225
|
-
x:
|
|
229
|
+
x: originX === 0
|
|
230
|
+
? all.x
|
|
231
|
+
: all.x
|
|
232
|
+
.map(at => at - originX)
|
|
233
|
+
.filter(at => at >= 0 && at <= (band.w ?? 0)),
|
|
226
234
|
/** only the ones that actually cross this band; the rest are elsewhere */
|
|
227
235
|
y: all.y
|
|
228
236
|
.map(at => at - (band.originY ?? 0))
|