report-studio 1.3.0 → 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/dist/{designer-Dj330bWd.js → designer-_sWqzOj8.js} +1361 -999
- package/dist/designer.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react-designer.js +1 -1
- package/dist/react.js +1 -1
- package/dist/{viewer-BewnkhfP.js → viewer-4I7C1Rnd.js} +1053 -998
- package/package.json +1 -1
- package/src/designer/choice.js +368 -0
- package/src/designer/designer.js +30 -1
- package/src/designer/dialog.js +49 -25
- package/src/designer/fields.js +219 -27
- package/src/designer/icons.js +13 -0
- package/src/designer/panel.js +419 -56
- package/src/designer/select.js +21 -1
- package/src/designer/styles.css +1196 -545
- package/src/engine/validate.js +39 -0
- package/src/preview/chrome.css +302 -84
- package/src/preview/chrome.js +70 -58
- package/src/preview/viewer.js +137 -85
- 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 +8 -1
- package/types/layout.d.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "report-studio",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Visual report designer and paginated report viewer for the browser. Zero runtime dependencies; plain JS, React components and a Vite plugin.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -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
|
+
}
|
package/src/designer/designer.js
CHANGED
|
@@ -452,15 +452,35 @@ export function createDesigner({
|
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
|
|
455
|
+
/**
|
|
456
|
+
* How far down the rail was, for each kind of thing it has shown - the
|
|
457
|
+
* report, a box, a text item, several at once.
|
|
458
|
+
*
|
|
459
|
+
* Without it, the place someone had scrolled the report's rail to went
|
|
460
|
+
* whenever an item was selected: a box's rail fits without scrolling, so
|
|
461
|
+
* the offset collapsed to 0, and deselecting brought the report back at
|
|
462
|
+
* its top. Kept per kind rather than per item, so stepping from one text
|
|
463
|
+
* item to the next stays on the font being changed.
|
|
464
|
+
*/
|
|
465
|
+
const railScroll = new Map();
|
|
466
|
+
let railShowing = null;
|
|
467
|
+
|
|
455
468
|
function drawRail() {
|
|
456
469
|
/** a rendered report has no item to describe and no report to restructure */
|
|
457
470
|
if (state.mode === 'preview') return;
|
|
458
471
|
|
|
459
472
|
const many = state.selection.length;
|
|
473
|
+
const item = selected();
|
|
474
|
+
const showing = many > 1 ? 'many' : (item ? `item:${item.type}` : 'report');
|
|
475
|
+
|
|
476
|
+
if (railShowing) railScroll.set(railShowing, panel.scrollTop);
|
|
460
477
|
|
|
461
478
|
panel.innerHTML = many > 1
|
|
462
479
|
? drawManyPanel(selectedItems())
|
|
463
|
-
: (
|
|
480
|
+
: (item ? drawPanel(item, state.layout) : drawReportPanel(state.layout));
|
|
481
|
+
|
|
482
|
+
panel.scrollTop = railScroll.get(showing) ?? 0;
|
|
483
|
+
railShowing = showing;
|
|
464
484
|
}
|
|
465
485
|
|
|
466
486
|
|
|
@@ -1891,7 +1911,16 @@ export function createDesigner({
|
|
|
1891
1911
|
*/
|
|
1892
1912
|
changed: (key, { rebuild = false } = {}) => {
|
|
1893
1913
|
draw();
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* An edit can change more than the box it was typed in - with the
|
|
1917
|
+
* margins' Same value on, a number typed into one side is all four
|
|
1918
|
+
* - so the rest of the rail is brought up to date. syncPanel leaves
|
|
1919
|
+
* the focused box alone, so the caret stays where it is.
|
|
1920
|
+
*/
|
|
1894
1921
|
if (rebuild) redrawRailKeepingFocus();
|
|
1922
|
+
else syncPanel(panel, selected(), state.layout);
|
|
1923
|
+
|
|
1895
1924
|
record(key);
|
|
1896
1925
|
},
|
|
1897
1926
|
act,
|
package/src/designer/dialog.js
CHANGED
|
@@ -17,6 +17,7 @@ import { bandLabel } from './grouping.js';
|
|
|
17
17
|
import { toId } from '../shared/store.js';
|
|
18
18
|
import { esc } from '../render/items.js';
|
|
19
19
|
import { createDropdown } from '../shared/dropdown.js';
|
|
20
|
+
import { choiceBox, refreshChoices, attachChoices } from './choice.js';
|
|
20
21
|
import {
|
|
21
22
|
effectiveFormat, formatValue, toNumber, DATE_PATTERNS, DATETIME_PATTERNS, MAX_DECIMALS,
|
|
22
23
|
CURRENCY_SYMBOLS
|
|
@@ -190,6 +191,12 @@ export function askDiscard(root, name = '') {
|
|
|
190
191
|
* @param {(host: Element, done: (value: any) => void) => void} wire
|
|
191
192
|
* @returns {Promise<any>} whatever `done` was given, or null if cancelled
|
|
192
193
|
*/
|
|
194
|
+
/** the close button's ×, drawn so it sits on the same grid as the other glyphs */
|
|
195
|
+
const CLOSE_GLYPH = `<svg viewBox="0 0 16 16" width="14" height="14" fill="none"
|
|
196
|
+
stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
|
|
197
|
+
aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8"/></svg>`;
|
|
198
|
+
|
|
199
|
+
|
|
193
200
|
function open(root, role, body, wire) {
|
|
194
201
|
return new Promise(resolve => {
|
|
195
202
|
/** created in the document the designer is mounted in, not always this one */
|
|
@@ -198,14 +205,28 @@ function open(root, role, body, wire) {
|
|
|
198
205
|
host.dataset.role = role;
|
|
199
206
|
host.innerHTML = body;
|
|
200
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Every dialog gets the × a design tool's dialog has, in its title
|
|
210
|
+
* bar. Added here rather than in each dialog's markup, and given a
|
|
211
|
+
* role of its own: [data-role="cancel"] is a button some dialogs
|
|
212
|
+
* label and style as something else ("Keep editing").
|
|
213
|
+
*/
|
|
214
|
+
host.querySelector('.modal-card')?.insertAdjacentHTML('afterbegin', `
|
|
215
|
+
<button type="button" class="modal-close" data-role="close"
|
|
216
|
+
title="Close" aria-label="Close">${CLOSE_GLYPH}</button>`);
|
|
217
|
+
|
|
201
218
|
root.appendChild(host);
|
|
202
219
|
|
|
220
|
+
/** a dialog's choices open the same list the rail's do */
|
|
221
|
+
const detachChoices = attachChoices(host);
|
|
222
|
+
|
|
203
223
|
let settled = false;
|
|
204
224
|
|
|
205
225
|
function close(value) {
|
|
206
226
|
if (settled) return;
|
|
207
227
|
|
|
208
228
|
settled = true;
|
|
229
|
+
detachChoices();
|
|
209
230
|
/** so a dropdown inside can drop its document listener */
|
|
210
231
|
host.dispatchEvent(new CustomEvent('dz-closing'));
|
|
211
232
|
host.remove();
|
|
@@ -231,7 +252,8 @@ function open(root, role, body, wire) {
|
|
|
231
252
|
close(null);
|
|
232
253
|
}
|
|
233
254
|
|
|
234
|
-
for (const node of host.querySelectorAll(
|
|
255
|
+
for (const node of host.querySelectorAll(
|
|
256
|
+
'[data-role="cancel"], [data-role="backdrop"], [data-role="close"]')) {
|
|
235
257
|
node.addEventListener('click', () => close(null));
|
|
236
258
|
}
|
|
237
259
|
|
|
@@ -806,6 +828,9 @@ export function askFormat(root, current, defaults, { title = 'Format' } = {}) {
|
|
|
806
828
|
/** zero prints with the places chosen: 0, 0.00, 0.000 */
|
|
807
829
|
const zero = host.querySelector('[data-role="zero"] option[value="zero"]');
|
|
808
830
|
if (zero) zero.textContent = zeroLabel(shown.decimals);
|
|
831
|
+
|
|
832
|
+
/** a relabelled zero, a new list of layouts: the buttons say so too */
|
|
833
|
+
refreshChoices(host);
|
|
809
834
|
host.querySelector('[data-role="sample"]').innerHTML = shown.type === 'text'
|
|
810
835
|
? '<span>Printed as the data has it</span>'
|
|
811
836
|
: (SAMPLES[shown.type] ?? []).map(v =>
|
|
@@ -887,27 +912,30 @@ function syncPatterns(host, type, pattern) {
|
|
|
887
912
|
}
|
|
888
913
|
|
|
889
914
|
|
|
890
|
-
|
|
915
|
+
/** a type's date layouts, each shown as the sample it prints, then Custom… */
|
|
916
|
+
function patternList(list, type) {
|
|
891
917
|
const sample = SAMPLES[type][0];
|
|
892
918
|
|
|
893
919
|
return [
|
|
894
|
-
...list.map(p =>
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
].join('');
|
|
920
|
+
...list.map(p => ({ value: p, label: `${formatValue(sample, { type, pattern: p })} (${p})` })),
|
|
921
|
+
{ value: CUSTOM, label: 'Custom…' }
|
|
922
|
+
];
|
|
898
923
|
}
|
|
899
924
|
|
|
900
925
|
|
|
901
|
-
function
|
|
902
|
-
const
|
|
903
|
-
|
|
926
|
+
function patternOptions(list, type, selected) {
|
|
927
|
+
const chosen = list.includes(selected) ? selected : CUSTOM;
|
|
928
|
+
|
|
929
|
+
return patternList(list, type).map(o => `<option value="${esc(o.value)}"
|
|
930
|
+
${o.value === chosen ? ' selected' : ''}>${esc(o.label)}</option>`).join('');
|
|
931
|
+
}
|
|
932
|
+
|
|
904
933
|
|
|
934
|
+
function formatMarkup(f, title) {
|
|
905
935
|
const select = (role, label, options, current) => `
|
|
906
936
|
<div class="dz-field">
|
|
907
|
-
<label for="dz-format-${role}">${esc(label)}</label>
|
|
908
|
-
|
|
909
|
-
${options.map(option(current)).join('')}
|
|
910
|
-
</select>
|
|
937
|
+
<label for="dz-format-${role}" id="dz-format-${role}-label">${esc(label)}</label>
|
|
938
|
+
${choiceBox(`dz-format-${role}`, `data-role="${role}"`, options, current)}
|
|
911
939
|
</div>`;
|
|
912
940
|
|
|
913
941
|
const dateType = f.type === 'datetime' ? 'datetime' : 'date';
|
|
@@ -925,12 +953,14 @@ function formatMarkup(f, title) {
|
|
|
925
953
|
<form>
|
|
926
954
|
<fieldset class="dz-format-types">
|
|
927
955
|
<legend>Type</legend>
|
|
956
|
+
<div class="dz-format-track">
|
|
928
957
|
${FORMAT_CHOICES.map(o => `
|
|
929
958
|
<label class="dz-format-type">
|
|
930
959
|
<input type="radio" name="format-type" value="${o.value}"
|
|
931
960
|
${o.value === f.type ? 'checked' : ''}>
|
|
932
961
|
<span>${esc(o.label)}</span>
|
|
933
962
|
</label>`).join('')}
|
|
963
|
+
</div>
|
|
934
964
|
</fieldset>
|
|
935
965
|
|
|
936
966
|
<div class="dz-format-group" data-role="number-options">
|
|
@@ -975,10 +1005,9 @@ function formatMarkup(f, title) {
|
|
|
975
1005
|
|
|
976
1006
|
<div class="dz-format-group" data-role="date-options">
|
|
977
1007
|
<div class="dz-field">
|
|
978
|
-
<label for="dz-format-pattern">Layout</label>
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
</select>
|
|
1008
|
+
<label for="dz-format-pattern" id="dz-format-pattern-label">Layout</label>
|
|
1009
|
+
${choiceBox('dz-format-pattern', `data-role="pattern" data-for="${dateType}"`,
|
|
1010
|
+
patternList(patterns, dateType), isCustom ? CUSTOM : f.pattern)}
|
|
982
1011
|
</div>
|
|
983
1012
|
<div class="dz-field" data-role="custom-row"${isCustom ? '' : ' hidden'}>
|
|
984
1013
|
<label for="dz-format-custom">Pattern</label>
|
|
@@ -1209,8 +1238,6 @@ function ruleMarkup(rule, n, count, subjects, rows, format) {
|
|
|
1209
1238
|
const when = rule.when ?? {};
|
|
1210
1239
|
const style = rule.style ?? {};
|
|
1211
1240
|
const unary = UNARY_OPS.includes(when.op);
|
|
1212
|
-
const option = (current) => (o) => `<option value="${esc(o.value)}"
|
|
1213
|
-
${o.value === current ? 'selected' : ''}>${esc(o.label)}</option>`;
|
|
1214
1241
|
|
|
1215
1242
|
const subjectChoices = [
|
|
1216
1243
|
...(rows ? [] : [{ value: THIS_VALUE, label: 'this value' }]),
|
|
@@ -1243,12 +1270,9 @@ function ruleMarkup(rule, n, count, subjects, rows, format) {
|
|
|
1243
1270
|
<div class="dz-hl-rule" data-n="${n}">
|
|
1244
1271
|
<span class="dz-hl-label">${n === 0 ? 'When' : 'Else when'}</span>
|
|
1245
1272
|
<div class="dz-hl-when">
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
<select data-key="op" aria-label="Test">
|
|
1250
|
-
${OP_CHOICES.map(option(when.op)).join('')}
|
|
1251
|
-
</select>
|
|
1273
|
+
${choiceBox(null, 'data-key="field"', subjectChoices, when.field ?? THIS_VALUE,
|
|
1274
|
+
{ label: 'What to test' })}
|
|
1275
|
+
${choiceBox(null, 'data-key="op"', OP_CHOICES, when.op, { label: 'Test' })}
|
|
1252
1276
|
<span class="dz-hl-values">
|
|
1253
1277
|
${unary ? '<span class="dz-hl-novalue">no value needed</span>' : `
|
|
1254
1278
|
<input type="text" data-key="value" value="${esc(when.value ?? '')}"
|