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
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* choice.js is a choice that can be styled: the box a design tool draws, over
|
|
3
|
+
* a <select> that is still the control.
|
|
4
|
+
*
|
|
5
|
+
* A native select opens its list through the operating system, which no
|
|
6
|
+
* stylesheet reaches - so the list was the one part of the designer that could
|
|
7
|
+
* not look like the rest of it. The select stays, out of sight, and remains
|
|
8
|
+
* what the code around it reads and listens to: its value is the value, and a
|
|
9
|
+
* change is reported on it exactly as the select would report one. The button
|
|
10
|
+
* in front only shows what it holds, and opens the shared menu (dropdown.css)
|
|
11
|
+
* to choose from.
|
|
12
|
+
*
|
|
13
|
+
* Used by the properties rail and by the dialogs, so every choice in the
|
|
14
|
+
* designer opens the same list.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { esc } from '../render/items.js';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string|null} id the button's id - what a <label for> points at. The
|
|
22
|
+
* label, when there is one, is expected at `${id}-label`
|
|
23
|
+
* @param {string} attrs the select's own attributes: its binding, its role
|
|
24
|
+
* @param {{value: string, label: string}[]} options
|
|
25
|
+
* @param {*} value
|
|
26
|
+
* @param {object} [names]
|
|
27
|
+
* @param {string} [names.label] an accessible name, for a choice no label names
|
|
28
|
+
* @returns {string} markup
|
|
29
|
+
*/
|
|
30
|
+
export function choiceBox(id, attrs, options, value, { label = '' } = {}) {
|
|
31
|
+
const current = options.find(o => String(o.value) === String(value ?? '')) ?? options[0];
|
|
32
|
+
|
|
33
|
+
const valueId = id ? `${id}-value` : '';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Named by its label and then its value, so a screen reader says "Font,
|
|
37
|
+
* Helvetica" as it did for the select. A choice with no label element
|
|
38
|
+
* says what it is from its own aria-label instead.
|
|
39
|
+
*/
|
|
40
|
+
const naming = id && !label
|
|
41
|
+
? `aria-labelledby="${id}-label ${valueId}"`
|
|
42
|
+
: `aria-label="${esc(label)}"`;
|
|
43
|
+
|
|
44
|
+
return `
|
|
45
|
+
<span class="dz-choice">
|
|
46
|
+
<select class="dz-choice-native" ${attrs} tabindex="-1" aria-hidden="true">${options.map(o =>
|
|
47
|
+
`<option value="${esc(o.value)}"${o === current ? ' selected' : ''}
|
|
48
|
+
>${esc(o.label)}</option>`).join('')}</select>
|
|
49
|
+
<button type="button" class="dz-choice-trigger"${id ? ` id="${id}"` : ''}
|
|
50
|
+
aria-haspopup="listbox" aria-expanded="false" ${naming}>
|
|
51
|
+
<span class="dz-choice-value"${valueId ? ` id="${valueId}"` : ''}
|
|
52
|
+
>${esc(current?.label ?? '')}</span>
|
|
53
|
+
</button>
|
|
54
|
+
</span>`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Puts what a choice's select now holds onto the button in front of it.
|
|
60
|
+
* @param {HTMLSelectElement} select
|
|
61
|
+
*/
|
|
62
|
+
export function showChoice(select) {
|
|
63
|
+
const shown = select.closest?.('.dz-choice')?.querySelector('.dz-choice-value');
|
|
64
|
+
if (!shown) return;
|
|
65
|
+
|
|
66
|
+
shown.textContent = select.selectedOptions?.[0]?.textContent.trim() ?? '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Every choice's button in a container, brought up to date with its select -
|
|
72
|
+
* for code that sets a select, or rewrites its options, without a change.
|
|
73
|
+
* @param {Element} container
|
|
74
|
+
*/
|
|
75
|
+
export function refreshChoices(container) {
|
|
76
|
+
for (const select of container.querySelectorAll('.dz-choice select')) showChoice(select);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Wires the choices in a container: their buttons open the list, and the
|
|
82
|
+
* list sets the select. Delegated, so choices drawn into the container later -
|
|
83
|
+
* a rail rebuilt, a rule added - work without being wired again.
|
|
84
|
+
*
|
|
85
|
+
* The list is one element for the container, outside it: a container that
|
|
86
|
+
* scrolls would clip a menu inside it, and scroll it away. It sits in the
|
|
87
|
+
* designer instead - where the palette's custom properties still reach it -
|
|
88
|
+
* fixed to the window, and closes on anything that would move the button out
|
|
89
|
+
* from under it.
|
|
90
|
+
*
|
|
91
|
+
* @param {Element} container
|
|
92
|
+
* @returns {() => void} detaches, and takes the list away
|
|
93
|
+
*/
|
|
94
|
+
export function attachChoices(container) {
|
|
95
|
+
const doc = container.ownerDocument;
|
|
96
|
+
const view = doc.defaultView;
|
|
97
|
+
const host = container.closest('.report-designer') ?? container.parentElement ?? doc.body;
|
|
98
|
+
|
|
99
|
+
const list = doc.createElement('ul');
|
|
100
|
+
list.className = 'dropdown-menu dz-listbox';
|
|
101
|
+
|
|
102
|
+
/** a dialog's list is drawn at the dialog's size */
|
|
103
|
+
if (container.classList.contains('modal')) list.classList.add('is-roomy');
|
|
104
|
+
list.setAttribute('role', 'listbox');
|
|
105
|
+
list.hidden = true;
|
|
106
|
+
host.appendChild(list);
|
|
107
|
+
|
|
108
|
+
/** the button the list is open for, and the item the keys are on */
|
|
109
|
+
let opener = null;
|
|
110
|
+
let active = 0;
|
|
111
|
+
|
|
112
|
+
const items = () => [...list.children];
|
|
113
|
+
|
|
114
|
+
function paint() {
|
|
115
|
+
items().forEach((item, i) => item.classList.toggle('is-active', i === active));
|
|
116
|
+
|
|
117
|
+
const current = items()[active];
|
|
118
|
+
if (current) {
|
|
119
|
+
current.focus({ preventScroll: true });
|
|
120
|
+
current.scrollIntoView?.({ block: 'nearest' });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function open(trigger) {
|
|
125
|
+
const select = trigger.closest('.dz-choice')?.querySelector('select');
|
|
126
|
+
if (!select) return;
|
|
127
|
+
|
|
128
|
+
if (opener) close(false);
|
|
129
|
+
opener = trigger;
|
|
130
|
+
|
|
131
|
+
active = Math.max(select.selectedIndex, 0);
|
|
132
|
+
|
|
133
|
+
list.innerHTML = [...select.options].map((o, i) => `
|
|
134
|
+
<li class="dropdown-item" role="option" tabindex="-1" data-index="${i}"
|
|
135
|
+
aria-selected="${i === select.selectedIndex}">${esc(o.textContent.trim())}</li>`).join('');
|
|
136
|
+
|
|
137
|
+
if (trigger.id) list.setAttribute('aria-labelledby', `${trigger.id}-label`);
|
|
138
|
+
else list.removeAttribute('aria-labelledby');
|
|
139
|
+
|
|
140
|
+
list.hidden = false;
|
|
141
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
142
|
+
|
|
143
|
+
place(trigger);
|
|
144
|
+
paint();
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* On the next tick, or the press that opened the list would reach
|
|
148
|
+
* this listener on its way up and close it again.
|
|
149
|
+
*/
|
|
150
|
+
view.setTimeout(() => {
|
|
151
|
+
if (opener === trigger) doc.addEventListener('pointerdown', onOutside, true);
|
|
152
|
+
}, 0);
|
|
153
|
+
|
|
154
|
+
container.addEventListener('scroll', onAway, true);
|
|
155
|
+
view.addEventListener('resize', onAway);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* As a design tool places a menu: the chosen item over the button, so the
|
|
160
|
+
* pointer is already on it - and the whole list kept inside the window.
|
|
161
|
+
*/
|
|
162
|
+
function place(trigger) {
|
|
163
|
+
const box = trigger.getBoundingClientRect();
|
|
164
|
+
const chosen = items()[active];
|
|
165
|
+
|
|
166
|
+
list.style.minWidth = `${Math.round(box.width) + 8}px`;
|
|
167
|
+
list.style.left = '0px';
|
|
168
|
+
list.style.top = '0px';
|
|
169
|
+
|
|
170
|
+
const height = list.offsetHeight;
|
|
171
|
+
const width = list.offsetWidth;
|
|
172
|
+
const gap = 8;
|
|
173
|
+
|
|
174
|
+
let top = chosen
|
|
175
|
+
? box.top - chosen.offsetTop + (box.height - chosen.offsetHeight) / 2
|
|
176
|
+
: box.bottom + 4;
|
|
177
|
+
top = Math.min(Math.max(top, gap), Math.max(gap, view.innerHeight - height - gap));
|
|
178
|
+
|
|
179
|
+
let left = box.left - 4;
|
|
180
|
+
left = Math.min(Math.max(left, gap), Math.max(gap, view.innerWidth - width - gap));
|
|
181
|
+
|
|
182
|
+
list.style.top = `${Math.round(top)}px`;
|
|
183
|
+
list.style.left = `${Math.round(left)}px`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function close(refocus = true) {
|
|
187
|
+
if (!opener) return;
|
|
188
|
+
|
|
189
|
+
const trigger = opener;
|
|
190
|
+
opener = null;
|
|
191
|
+
|
|
192
|
+
list.hidden = true;
|
|
193
|
+
list.innerHTML = '';
|
|
194
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
195
|
+
|
|
196
|
+
doc.removeEventListener('pointerdown', onOutside, true);
|
|
197
|
+
container.removeEventListener('scroll', onAway, true);
|
|
198
|
+
view.removeEventListener('resize', onAway);
|
|
199
|
+
|
|
200
|
+
if (refocus && trigger.isConnected) trigger.focus();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Sets the select and reports it as a select would - input, then change -
|
|
205
|
+
* so the code around it takes it from there.
|
|
206
|
+
*
|
|
207
|
+
* That code may redraw what the choice was in: a rail rebuilt for a new
|
|
208
|
+
* paper size, a rule redrawn for a new test. Whatever it then focused is
|
|
209
|
+
* left alone; if it focused nothing, the focus goes to the button of the
|
|
210
|
+
* same id, or back to this one if it is still there.
|
|
211
|
+
*/
|
|
212
|
+
function choose(index) {
|
|
213
|
+
const trigger = opener;
|
|
214
|
+
const select = trigger?.closest('.dz-choice')?.querySelector('select');
|
|
215
|
+
close(false);
|
|
216
|
+
if (!select) return;
|
|
217
|
+
|
|
218
|
+
const id = trigger.id;
|
|
219
|
+
|
|
220
|
+
if (select.selectedIndex !== index) {
|
|
221
|
+
select.selectedIndex = index;
|
|
222
|
+
showChoice(select);
|
|
223
|
+
select.dispatchEvent(new Event('input', { bubbles: true }));
|
|
224
|
+
select.dispatchEvent(new Event('change', { bubbles: true }));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const focused = doc.activeElement;
|
|
228
|
+
if (focused && focused !== doc.body && container.contains(focused)) return;
|
|
229
|
+
|
|
230
|
+
const again = id ? doc.getElementById(id) : null;
|
|
231
|
+
if (again && container.contains(again)) again.focus();
|
|
232
|
+
else if (trigger.isConnected) trigger.focus();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function onOutside(event) {
|
|
236
|
+
if (list.contains(event.target) || opener?.contains(event.target)) return;
|
|
237
|
+
close(false);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function onAway() {
|
|
241
|
+
close(false);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function onListClick(event) {
|
|
245
|
+
const item = event.target.closest?.('.dropdown-item');
|
|
246
|
+
if (item) choose(Number(item.dataset.index));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** the pointer and the keys share one highlight, as a menu's do */
|
|
250
|
+
function onListHover(event) {
|
|
251
|
+
const item = event.target.closest?.('.dropdown-item');
|
|
252
|
+
if (!item) return;
|
|
253
|
+
|
|
254
|
+
active = Number(item.dataset.index);
|
|
255
|
+
items().forEach((one, i) => one.classList.toggle('is-active', i === active));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The list's keys. Every one it handles stops here: the designer reads
|
|
260
|
+
* arrows as a nudge and Escape as "select nothing" - and a dialog reads
|
|
261
|
+
* Escape as "cancel" - and none of those is meant.
|
|
262
|
+
* A letter jumps to the next item that starts with it.
|
|
263
|
+
*/
|
|
264
|
+
function onListKey(event) {
|
|
265
|
+
const count = items().length;
|
|
266
|
+
const to = (at) => () => { active = Math.min(Math.max(at, 0), count - 1); paint(); };
|
|
267
|
+
|
|
268
|
+
const handled = {
|
|
269
|
+
ArrowDown: to(active + 1),
|
|
270
|
+
ArrowUp: to(active - 1),
|
|
271
|
+
Home: to(0),
|
|
272
|
+
End: to(count - 1),
|
|
273
|
+
PageDown: to(active + 8),
|
|
274
|
+
PageUp: to(active - 8),
|
|
275
|
+
Enter: () => choose(active),
|
|
276
|
+
' ': () => choose(active),
|
|
277
|
+
Escape: () => close(true),
|
|
278
|
+
Tab: () => close(true)
|
|
279
|
+
}[event.key];
|
|
280
|
+
|
|
281
|
+
if (handled) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
event.stopPropagation();
|
|
284
|
+
handled();
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) return;
|
|
289
|
+
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
event.stopPropagation();
|
|
292
|
+
|
|
293
|
+
const letter = event.key.toLowerCase();
|
|
294
|
+
const all = items();
|
|
295
|
+
|
|
296
|
+
for (let step = 1; step <= all.length; step++) {
|
|
297
|
+
const at = (active + step) % all.length;
|
|
298
|
+
|
|
299
|
+
if (all[at].textContent.trim().toLowerCase().startsWith(letter)) {
|
|
300
|
+
active = at;
|
|
301
|
+
paint();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function onClick(event) {
|
|
308
|
+
const trigger = event.target.closest?.('.dz-choice-trigger');
|
|
309
|
+
if (!trigger || !container.contains(trigger)) return;
|
|
310
|
+
|
|
311
|
+
event.preventDefault();
|
|
312
|
+
|
|
313
|
+
if (opener === trigger) close(true);
|
|
314
|
+
else open(trigger);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* A choice's button behaves as the select it stands in for: the arrows,
|
|
319
|
+
* Enter and Space open it, and nothing else typed at it goes further - a
|
|
320
|
+
* native select swallowed Backspace, and here it would otherwise reach
|
|
321
|
+
* the designer and delete the item being edited.
|
|
322
|
+
*/
|
|
323
|
+
function onKey(event) {
|
|
324
|
+
const trigger = event.target.closest?.('.dz-choice-trigger');
|
|
325
|
+
if (!trigger) return;
|
|
326
|
+
|
|
327
|
+
if (event.key === 'Tab' || event.ctrlKey || event.metaKey) return;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Escape included: on the rail it would otherwise drop the selection.
|
|
331
|
+
* A dialog still closes on it - it listens on the way down, before
|
|
332
|
+
* this ever sees the key.
|
|
333
|
+
*/
|
|
334
|
+
event.stopPropagation();
|
|
335
|
+
|
|
336
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
open(trigger);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Code written for the select may still focus it - a dialog putting the
|
|
344
|
+
* caret back where it was after a redraw. The select is out of sight, so
|
|
345
|
+
* the focus is handed on to the button that stands for it.
|
|
346
|
+
*/
|
|
347
|
+
function onFocus(event) {
|
|
348
|
+
const node = event.target;
|
|
349
|
+
if (!node.classList?.contains('dz-choice-native')) return;
|
|
350
|
+
|
|
351
|
+
node.closest('.dz-choice')?.querySelector('.dz-choice-trigger')?.focus();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
list.addEventListener('click', onListClick);
|
|
355
|
+
list.addEventListener('pointermove', onListHover);
|
|
356
|
+
list.addEventListener('keydown', onListKey);
|
|
357
|
+
container.addEventListener('click', onClick);
|
|
358
|
+
container.addEventListener('keydown', onKey);
|
|
359
|
+
container.addEventListener('focusin', onFocus);
|
|
360
|
+
|
|
361
|
+
return function detach() {
|
|
362
|
+
close(false);
|
|
363
|
+
list.remove();
|
|
364
|
+
container.removeEventListener('click', onClick);
|
|
365
|
+
container.removeEventListener('keydown', onKey);
|
|
366
|
+
container.removeEventListener('focusin', onFocus);
|
|
367
|
+
};
|
|
368
|
+
}
|