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/src/designer/panel.js
CHANGED
|
@@ -29,13 +29,60 @@ import { levelsOf, MAX_GROUP_LEVELS } from '../engine/tables.js';
|
|
|
29
29
|
import { describeFormat } from '../engine/format.js';
|
|
30
30
|
import { describeHighlight } from '../engine/highlight.js';
|
|
31
31
|
import { esc, imageSrc } from '../render/items.js';
|
|
32
|
+
import { icon } from './icons.js';
|
|
33
|
+
import { choiceBox, showChoice, refreshChoices, attachChoices } from './choice.js';
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* The rail describes what a thing is; what you can do to it lives in the pill
|
|
36
38
|
* that opens on a right-click, beside the item rather than at the edge of the
|
|
37
39
|
* screen. See menu.js.
|
|
40
|
+
*
|
|
41
|
+
* It is laid out the way a design tool's inspector is: sections divided by a
|
|
42
|
+
* rule rather than boxed, a two-column grid that pairs X with Y and W with H,
|
|
43
|
+
* borderless boxes that only outline themselves on hover, and the label inside
|
|
44
|
+
* the box wherever a letter says enough. Every number's label can be dragged
|
|
45
|
+
* sideways to change it, as in Figma.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The row across the top of the rail: what is selected, by its glyph and id.
|
|
51
|
+
* @param {string} type shown under the id, and what the tests read
|
|
52
|
+
* @param {string} [name]
|
|
53
|
+
* @param {string} [glyph] markup for the icon
|
|
54
|
+
* @returns {string} markup
|
|
55
|
+
*/
|
|
56
|
+
function panelHead(type, name, glyph = '') {
|
|
57
|
+
return `
|
|
58
|
+
<div class="dz-panel-head">
|
|
59
|
+
${glyph ? `<span class="dz-panel-icon">${glyph}</span>` : ''}
|
|
60
|
+
${name != null ? `<span class="dz-panel-id">${esc(name)}</span>` : ''}
|
|
61
|
+
<span class="dz-panel-type">${esc(type)}</span>
|
|
62
|
+
</div>`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A section's title, with any buttons that act on the section as a whole on
|
|
68
|
+
* the right of it - where the + that adds a row sits in a design tool.
|
|
69
|
+
* @param {string} title
|
|
70
|
+
* @param {string} [actions] markup
|
|
71
|
+
* @returns {string} markup
|
|
38
72
|
*/
|
|
73
|
+
function sectionHead(title, actions = '') {
|
|
74
|
+
return `
|
|
75
|
+
<div class="dz-section-head">
|
|
76
|
+
<h3>${esc(title)}</h3>
|
|
77
|
+
${actions ? `<span class="dz-section-tools">${actions}</span>` : ''}
|
|
78
|
+
</div>`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/** a + drawn rather than typed, so it sits on the same grid as the glyphs */
|
|
83
|
+
const PLUS = `<svg viewBox="0 0 16 16" width="14" height="14" fill="none"
|
|
84
|
+
stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
|
|
85
|
+
aria-hidden="true" focusable="false"><path d="M8 3.5v9M3.5 8h9"/></svg>`;
|
|
39
86
|
|
|
40
87
|
|
|
41
88
|
/**
|
|
@@ -47,28 +94,25 @@ import { esc, imageSrc } from '../render/items.js';
|
|
|
47
94
|
*/
|
|
48
95
|
export function drawPanel(item, layout = null) {
|
|
49
96
|
return `
|
|
50
|
-
|
|
51
|
-
<span class="dz-panel-type">${esc(item.type)}</span>
|
|
52
|
-
<span class="dz-panel-id">${esc(item.id)}</span>
|
|
53
|
-
</div>
|
|
97
|
+
${panelHead(item.type, item.id, icon(item.type))}
|
|
54
98
|
${sections(item, fieldsFor(item))}
|
|
55
99
|
${item.type === 'text' ? `
|
|
56
100
|
<section class="dz-section">
|
|
57
|
-
|
|
101
|
+
${sectionHead('Format')}
|
|
58
102
|
<div class="dz-field dz-field-format">
|
|
59
|
-
<label>Values</label>
|
|
103
|
+
<label class="dz-label">Values</label>
|
|
60
104
|
${formatButton(item, layout)}
|
|
61
105
|
</div>
|
|
62
106
|
<div class="dz-field dz-field-format">
|
|
63
|
-
<label>Highlight</label>
|
|
107
|
+
<label class="dz-label">Highlight</label>
|
|
64
108
|
${highlightButton(item.highlight, 'edit-highlight')}
|
|
65
109
|
</div>
|
|
66
110
|
</section>` : ''}
|
|
67
111
|
${item.type === 'table' ? `
|
|
68
112
|
<section class="dz-section">
|
|
69
|
-
|
|
113
|
+
${sectionHead('Row highlight')}
|
|
70
114
|
<div class="dz-field dz-field-format">
|
|
71
|
-
<label>Rows</label>
|
|
115
|
+
<label class="dz-label">Rows</label>
|
|
72
116
|
${highlightButton(item.rowHighlight, 'edit-row-highlight')}
|
|
73
117
|
</div>
|
|
74
118
|
</section>` : ''}
|
|
@@ -103,7 +147,7 @@ function grouping(table, layout) {
|
|
|
103
147
|
|
|
104
148
|
return `
|
|
105
149
|
<section class="dz-section dz-bands dz-grouping">
|
|
106
|
-
|
|
150
|
+
${sectionHead('Grouping')}
|
|
107
151
|
${levels.map((level, n) => groupLevel(scope, table, level, n, levels.length)).join('')}
|
|
108
152
|
${levels.length < MAX_GROUP_LEVELS ? `
|
|
109
153
|
<button type="button" class="dz-add-row" data-action="add-group-level"
|
|
@@ -160,7 +204,7 @@ function groupLevel(scope, table, level, n, depth) {
|
|
|
160
204
|
</div>
|
|
161
205
|
${n > 0 ? `
|
|
162
206
|
<div class="dz-field dz-field-text">
|
|
163
|
-
<label for="${id}">Then group by</label>
|
|
207
|
+
<label class="dz-label" for="${id}">Then group by</label>
|
|
164
208
|
<input type="text" id="${id}" data-group-level="${n}"
|
|
165
209
|
value="${esc(by)}" spellcheck="false">
|
|
166
210
|
<p class="dz-hint">A field to group each group above by</p>
|
|
@@ -206,11 +250,8 @@ function levelOptions(level, n) {
|
|
|
206
250
|
|
|
207
251
|
return `
|
|
208
252
|
<div class="dz-field dz-field-choice">
|
|
209
|
-
<label for="${id}-sort">Order groups</label>
|
|
210
|
-
|
|
211
|
-
${SORT_CHOICES.map(o => `<option value="${o.value}"${o.value === sort ? ' selected' : ''}
|
|
212
|
-
>${esc(o.label)}</option>`).join('')}
|
|
213
|
-
</select>
|
|
253
|
+
<label class="dz-label" id="${id}-sort-label" for="${id}-sort">Order groups</label>
|
|
254
|
+
${choiceBox(`${id}-sort`, `data-group-option="sort" data-level="${n}"`, SORT_CHOICES, sort)}
|
|
214
255
|
</div>
|
|
215
256
|
<div class="dz-field dz-field-toggle">
|
|
216
257
|
<label for="${id}-page">New page for each group</label>
|
|
@@ -235,9 +276,7 @@ function levelOptions(level, n) {
|
|
|
235
276
|
*/
|
|
236
277
|
export function drawManyPanel(items) {
|
|
237
278
|
return `
|
|
238
|
-
|
|
239
|
-
<span class="dz-panel-type">${items.length} items</span>
|
|
240
|
-
</div>
|
|
279
|
+
${panelHead(`${items.length} items`)}
|
|
241
280
|
|
|
242
281
|
<section class="dz-section">
|
|
243
282
|
<ul class="dz-selected">
|
|
@@ -263,10 +302,7 @@ export function drawManyPanel(items) {
|
|
|
263
302
|
*/
|
|
264
303
|
export function drawReportPanel(layout) {
|
|
265
304
|
return `
|
|
266
|
-
|
|
267
|
-
<span class="dz-panel-type">report</span>
|
|
268
|
-
<span class="dz-panel-id">${esc(layout.name ?? 'Untitled')}</span>
|
|
269
|
-
</div>
|
|
305
|
+
${panelHead('report', layout.name ?? 'Untitled', icon('open'))}
|
|
270
306
|
${sections(layout, reportFields(layout))}
|
|
271
307
|
${bands(layout)}`;
|
|
272
308
|
}
|
|
@@ -275,7 +311,7 @@ export function drawReportPanel(layout) {
|
|
|
275
311
|
function sections(target, list) {
|
|
276
312
|
return list.map(section => `
|
|
277
313
|
<section class="dz-section">
|
|
278
|
-
|
|
314
|
+
${sectionHead(section.title)}
|
|
279
315
|
${section.fields.map(field => control(target, field)).join('')}
|
|
280
316
|
${(section.actions ?? []).map(a => `
|
|
281
317
|
<button type="button" class="dz-add-row dz-section-action"
|
|
@@ -343,20 +379,43 @@ function control(target, field, extra = '') {
|
|
|
343
379
|
* by hand is the one part of this format nobody should have to do twice -
|
|
344
380
|
* and a placeholder is only a placeholder if both braces are there.
|
|
345
381
|
*/
|
|
382
|
+
/**
|
|
383
|
+
* A number with a short label carries it inside the box, and the label
|
|
384
|
+
* proper is kept for screen readers and the tests that read it. Any
|
|
385
|
+
* number's visible label - inside or above - is the handle that scrubs it.
|
|
386
|
+
*/
|
|
387
|
+
const inside = field.type === 'number' && field.short;
|
|
388
|
+
const scrub = field.type === 'number' ? ' dz-scrub' : '';
|
|
389
|
+
|
|
346
390
|
const label = field.type === 'textarea'
|
|
347
391
|
? `<span class="dz-field-top">
|
|
348
|
-
<label for="${id}">${esc(field.label)}</label>
|
|
392
|
+
<label class="dz-label" for="${id}">${esc(field.label)}</label>
|
|
349
393
|
<button type="button" class="dz-brace" data-action="insert-brace"
|
|
350
394
|
data-for="${esc(field.key)}"
|
|
351
395
|
title="Wrap the selected text in braces, or insert a pair"
|
|
352
396
|
aria-label="Insert a placeholder">{ }</button>
|
|
353
397
|
</span>`
|
|
354
|
-
|
|
398
|
+
/**
|
|
399
|
+
* A row of glyph buttons is named by its radiogroup instead: a label
|
|
400
|
+
* for its first button would choose Left whenever "Align" was clicked.
|
|
401
|
+
*/
|
|
402
|
+
: `<label class="dz-label${inside ? ' dz-sr' : scrub}" id="${id}-label"${field.segmented ? '' : ` for="${id}"`}
|
|
403
|
+
${scrub ? 'title="Drag sideways to change"' : ''}>${esc(field.label)}</label>`;
|
|
404
|
+
|
|
405
|
+
const half = field.half || field.type === 'number' || field.type === 'color';
|
|
406
|
+
|
|
407
|
+
const box = inside
|
|
408
|
+
? `<span class="dz-input">
|
|
409
|
+
<span class="dz-input-prefix dz-scrub" aria-hidden="true"
|
|
410
|
+
title="${esc(field.label)} - drag sideways to change">${esc(field.short)}</span>
|
|
411
|
+
${input(id, bind, field, value)}
|
|
412
|
+
</span>`
|
|
413
|
+
: input(id, bind, field, value);
|
|
355
414
|
|
|
356
415
|
return `
|
|
357
|
-
<div class="dz-field dz-field-${field.type}">
|
|
416
|
+
<div class="dz-field dz-field-${field.type}${half ? ' is-half' : ''}">
|
|
358
417
|
${label}
|
|
359
|
-
${
|
|
418
|
+
${box}
|
|
360
419
|
${field.hint ? `<p class="dz-hint">${esc(field.hint)}</p>` : ''}
|
|
361
420
|
</div>`;
|
|
362
421
|
}
|
|
@@ -381,9 +440,11 @@ function input(id, bind, field, value) {
|
|
|
381
440
|
</div>`;
|
|
382
441
|
|
|
383
442
|
case 'choice':
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
443
|
+
if (field.segmented) return segmented(id, bind, field, value);
|
|
444
|
+
|
|
445
|
+
return field.custom
|
|
446
|
+
? customChoice(id, bind, field, value)
|
|
447
|
+
: choiceBox(id, bind, field.options, value);
|
|
387
448
|
|
|
388
449
|
case 'color':
|
|
389
450
|
return colorInput(id, bind, field, value);
|
|
@@ -416,11 +477,17 @@ function input(id, bind, field, value) {
|
|
|
416
477
|
return `<input type="text" id="${id}" ${bind}
|
|
417
478
|
value="${esc(value ?? '')}" spellcheck="false">`;
|
|
418
479
|
|
|
480
|
+
/**
|
|
481
|
+
* A number can be shown and not be editable - a margin switched off
|
|
482
|
+
* shows what it will come back as. Disabled rather than hidden, so the
|
|
483
|
+
* rows beside it in the rail's grid stay where they are.
|
|
484
|
+
*/
|
|
419
485
|
default:
|
|
420
486
|
return `<input type="number" id="${id}" ${bind}
|
|
421
487
|
value="${esc(value ?? '')}"
|
|
422
488
|
${field.min != null ? `min="${field.min}"` : ''}
|
|
423
|
-
${field.max != null ? `max="${field.max}"` : ''} step="1"
|
|
489
|
+
${field.max != null ? `max="${field.max}"` : ''} step="1"
|
|
490
|
+
${field.disabled ? 'disabled' : ''}>`;
|
|
424
491
|
}
|
|
425
492
|
}
|
|
426
493
|
|
|
@@ -465,9 +532,7 @@ function customChoice(id, bind, field, value) {
|
|
|
465
532
|
|
|
466
533
|
return `
|
|
467
534
|
<span class="dz-choice-custom">
|
|
468
|
-
|
|
469
|
-
.map(o => `<option value="${esc(o.value)}"${o.value === selected ? ' selected' : ''}
|
|
470
|
-
>${esc(o.label)}</option>`).join('')}</select>
|
|
535
|
+
${choiceBox(id, bind, [...field.options, { value: CUSTOM_CHOICE, label: 'Custom…' }], selected)}
|
|
471
536
|
<input type="text" ${bind} data-custom="true" value="${esc(listed ? '' : value ?? '')}"
|
|
472
537
|
spellcheck="false" maxlength="6" aria-label="${esc(field.label)}, custom"
|
|
473
538
|
placeholder="such as CHF"${listed ? ' hidden' : ''}>
|
|
@@ -475,6 +540,33 @@ function customChoice(id, bind, field, value) {
|
|
|
475
540
|
}
|
|
476
541
|
|
|
477
542
|
|
|
543
|
+
/**
|
|
544
|
+
* A short choice as a row of glyph buttons - text alignment, which way a line
|
|
545
|
+
* runs, which way up the page is - as a design tool draws them.
|
|
546
|
+
*
|
|
547
|
+
* Radio buttons under the glyphs rather than buttons that act: a radio is
|
|
548
|
+
* already a choice of one, reports through the same change event a select
|
|
549
|
+
* does, and brings the arrow keys with it. The first carries the id, so the
|
|
550
|
+
* field's label still names the group.
|
|
551
|
+
*
|
|
552
|
+
* @returns {string} markup
|
|
553
|
+
*/
|
|
554
|
+
function segmented(id, bind, field, value) {
|
|
555
|
+
const name = id;
|
|
556
|
+
|
|
557
|
+
return `
|
|
558
|
+
<span class="dz-segmented" role="radiogroup" aria-label="${esc(field.label)}">
|
|
559
|
+
${field.options.map((o, n) => `
|
|
560
|
+
<label class="dz-seg" title="${esc(o.label)}">
|
|
561
|
+
<input type="radio" ${n === 0 ? `id="${id}"` : ''} name="${esc(name)}" ${bind}
|
|
562
|
+
value="${esc(o.value)}"${o.value === value ? ' checked' : ''}
|
|
563
|
+
aria-label="${esc(o.label)}">
|
|
564
|
+
<span class="dz-seg-glyph">${icon(o.icon) || esc(o.label)}</span>
|
|
565
|
+
</label>`).join('')}
|
|
566
|
+
</span>`;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
|
|
478
570
|
/**
|
|
479
571
|
* A colour, or none.
|
|
480
572
|
*
|
|
@@ -491,12 +583,21 @@ function customChoice(id, bind, field, value) {
|
|
|
491
583
|
function colorInput(id, bind, field, value) {
|
|
492
584
|
const none = value == null || value === '';
|
|
493
585
|
|
|
586
|
+
/**
|
|
587
|
+
* Beside the chip, the colour as hex - which is also a box it can be typed
|
|
588
|
+
* into, as a fill is in a design tool. It is not bound to the field itself:
|
|
589
|
+
* half a hex code is not a colour, so it writes through the picker once
|
|
590
|
+
* what is typed is one. See onHex.
|
|
591
|
+
*/
|
|
494
592
|
return `
|
|
495
|
-
<span class="dz-swatch${none ? ' is-none' : ''}">
|
|
593
|
+
<span class="dz-swatch dz-input${none ? ' is-none' : ''}">
|
|
496
594
|
<span class="dz-swatch-well">
|
|
497
595
|
<input type="color" id="${id}" ${bind} value="${esc(none ? '#000000' : value)}">
|
|
498
596
|
</span>
|
|
499
|
-
<
|
|
597
|
+
<input type="text" class="dz-hex" data-hex="${esc(field.key)}"
|
|
598
|
+
value="${esc(none ? '' : hexText(value))}" placeholder="None"
|
|
599
|
+
maxlength="7" spellcheck="false" autocomplete="off"
|
|
600
|
+
aria-label="${esc(field.label)}, as hex">
|
|
500
601
|
<button type="button" class="dz-icon dz-swatch-clear" data-action="clear-color"
|
|
501
602
|
data-for="${esc(field.key)}"
|
|
502
603
|
title="No colour" aria-label="Remove ${esc(field.label)} colour">×</button>
|
|
@@ -504,6 +605,44 @@ function colorInput(id, bind, field, value) {
|
|
|
504
605
|
}
|
|
505
606
|
|
|
506
607
|
|
|
608
|
+
/** a colour as the hex box shows it: no hash, upper case */
|
|
609
|
+
function hexText(value) {
|
|
610
|
+
const text = String(value ?? '');
|
|
611
|
+
return text.startsWith('#') ? text.slice(1).toUpperCase() : text;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* What was typed into a hex box, as the picker's #rrggbb - or null while it is
|
|
617
|
+
* not a colour yet. Three digits only count once the box is left, since "ff9"
|
|
618
|
+
* is as likely to be the start of "ff9c4b" as it is #ffff99.
|
|
619
|
+
*
|
|
620
|
+
* @param {string} text
|
|
621
|
+
* @param {boolean} final whether the box has been left or Enter pressed
|
|
622
|
+
* @returns {string|null}
|
|
623
|
+
*/
|
|
624
|
+
export function parseHex(text, final = false) {
|
|
625
|
+
const bare = String(text ?? '').trim().replace(/^#/, '').toLowerCase();
|
|
626
|
+
|
|
627
|
+
if (/^[0-9a-f]{6}$/.test(bare)) return `#${bare}`;
|
|
628
|
+
if (final && /^[0-9a-f]{3}$/.test(bare)) return `#${[...bare].map(c => c + c).join('')}`;
|
|
629
|
+
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
/** a column's closed row, kept saying what the column now is */
|
|
635
|
+
function summarise(node, column) {
|
|
636
|
+
if (!node) return;
|
|
637
|
+
|
|
638
|
+
const name = node.querySelector('.dz-column-name');
|
|
639
|
+
const width = node.querySelector('.dz-column-width');
|
|
640
|
+
|
|
641
|
+
if (name) name.textContent = column.label || column.field || '';
|
|
642
|
+
if (width) width.textContent = String(column.width ?? '');
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
|
|
507
646
|
/** shows a colour control as none, or as its colour */
|
|
508
647
|
function markSwatch(node, none) {
|
|
509
648
|
node.closest?.('.dz-swatch')?.classList.toggle('is-none', none);
|
|
@@ -511,39 +650,95 @@ function markSwatch(node, none) {
|
|
|
511
650
|
|
|
512
651
|
|
|
513
652
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
653
|
+
* Puts the colour a control now holds into its hex box - unless that box is
|
|
654
|
+
* the one being typed in, which would move the caret under the typist.
|
|
655
|
+
*/
|
|
656
|
+
function showHex(node, value) {
|
|
657
|
+
const hex = node.closest?.('.dz-swatch')?.querySelector('.dz-hex');
|
|
658
|
+
if (!hex || hex === hex.ownerDocument.activeElement) return;
|
|
659
|
+
|
|
660
|
+
hex.value = value == null || value === '' ? '' : hexText(value);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Which columns are open, by the column object itself.
|
|
666
|
+
*
|
|
667
|
+
* A table of ten columns, all open, is a rail ten screens long - so a column
|
|
668
|
+
* is a row that opens, as a layer is. The rail is rebuilt often (a column
|
|
669
|
+
* added, the selection changed and changed back), and a column somebody had
|
|
670
|
+
* open should still be open when it is drawn again, so the state is kept here
|
|
671
|
+
* rather than in the markup.
|
|
672
|
+
*
|
|
673
|
+
* Weak, and keyed by object, so nothing has to be cleaned up: an undo hands
|
|
674
|
+
* the designer a fresh copy of the layout, whose columns simply start closed.
|
|
675
|
+
*/
|
|
676
|
+
const openColumns = new WeakMap();
|
|
677
|
+
|
|
678
|
+
/** tables whose columns have been drawn at least once */
|
|
679
|
+
const drawnTables = new WeakSet();
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Whether a column is drawn open. One that has been opened or closed keeps
|
|
684
|
+
* that. One never seen before is closed - unless its table has been drawn
|
|
685
|
+
* already, in which case it has just been added, and is opened to be filled in.
|
|
686
|
+
*/
|
|
687
|
+
function isOpen(table, column) {
|
|
688
|
+
if (openColumns.has(column)) return openColumns.get(column);
|
|
689
|
+
|
|
690
|
+
const open = drawnTables.has(table);
|
|
691
|
+
openColumns.set(column, open);
|
|
692
|
+
return open;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* A table's columns, a row each that opens onto the rail's two-column grid -
|
|
698
|
+
* field and label side by side, then width and alignment. Closed, the row
|
|
699
|
+
* still says which column it is, what it shows and how wide it is. Adding one
|
|
700
|
+
* is the + on the section's title, where a design tool puts it.
|
|
516
701
|
*/
|
|
517
702
|
function columns(table, layout) {
|
|
518
703
|
const list = table.columns || [];
|
|
519
704
|
|
|
520
|
-
|
|
705
|
+
const add = `
|
|
706
|
+
<button type="button" class="dz-icon" data-action="add-column"
|
|
707
|
+
title="Add column" aria-label="Add column">${PLUS}</button>`;
|
|
708
|
+
|
|
709
|
+
const markup = `
|
|
521
710
|
<section class="dz-section dz-columns">
|
|
522
|
-
|
|
711
|
+
${sectionHead('Columns', add)}
|
|
523
712
|
${list.map((column, index) => `
|
|
524
|
-
<
|
|
525
|
-
<
|
|
526
|
-
<span
|
|
713
|
+
<details class="dz-column" data-index="${index}"${isOpen(table, column) ? ' open' : ''}>
|
|
714
|
+
<summary class="dz-column-head">
|
|
715
|
+
<span class="dz-column-caret" aria-hidden="true"></span>
|
|
716
|
+
<span class="dz-column-number">${index + 1}</span>
|
|
717
|
+
<span class="dz-column-name">${esc(column.label || column.field || '')}</span>
|
|
718
|
+
<span class="dz-column-width">${esc(column.width ?? '')}</span>
|
|
527
719
|
${list.length > 1 ? `
|
|
528
720
|
<button type="button" class="dz-icon"
|
|
529
721
|
data-action="remove-column" data-index="${index}"
|
|
530
722
|
title="Remove this column"
|
|
531
723
|
aria-label="Remove column ${index + 1}">×</button>` : ''}
|
|
532
|
-
</
|
|
724
|
+
</summary>
|
|
725
|
+
<div class="dz-column-body">
|
|
533
726
|
${COLUMN_FIELDS.map(field =>
|
|
534
727
|
control(column, field, String(index))).join('')}
|
|
535
|
-
<div class="dz-field dz-field-format">
|
|
536
|
-
<label>Format</label>
|
|
728
|
+
<div class="dz-field dz-field-format is-half">
|
|
729
|
+
<label class="dz-label">Format</label>
|
|
537
730
|
${formatButton(column, layout, String(index))}
|
|
538
731
|
</div>
|
|
539
|
-
<div class="dz-field dz-field-format">
|
|
540
|
-
<label>Highlight</label>
|
|
732
|
+
<div class="dz-field dz-field-format is-half">
|
|
733
|
+
<label class="dz-label">Highlight</label>
|
|
541
734
|
${highlightButton(column.highlight, 'edit-highlight', String(index))}
|
|
542
735
|
</div>
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
Add column</button>
|
|
736
|
+
</div>
|
|
737
|
+
</details>`).join('')}
|
|
546
738
|
</section>`;
|
|
739
|
+
|
|
740
|
+
drawnTables.add(table);
|
|
741
|
+
return markup;
|
|
547
742
|
}
|
|
548
743
|
|
|
549
744
|
|
|
@@ -558,7 +753,7 @@ function columns(table, layout) {
|
|
|
558
753
|
function bands(layout) {
|
|
559
754
|
return `
|
|
560
755
|
<section class="dz-section dz-bands">
|
|
561
|
-
|
|
756
|
+
${sectionHead('Bands')}
|
|
562
757
|
${railBands(layout).map(type => bandRow(layout, type)).join('')}
|
|
563
758
|
</section>`;
|
|
564
759
|
}
|
|
@@ -651,13 +846,41 @@ export function attachPanel({
|
|
|
651
846
|
}
|
|
652
847
|
|
|
653
848
|
|
|
849
|
+
/**
|
|
850
|
+
* A hex box writes through the picker beside it, once what is typed is a
|
|
851
|
+
* colour - so a colour typed and a colour picked are the same edit, and
|
|
852
|
+
* the field, the swatch and the history all hear about it one way.
|
|
853
|
+
*/
|
|
854
|
+
function onHex(node, final) {
|
|
855
|
+
const hex = parseHex(node.value, final);
|
|
856
|
+
if (!hex) return;
|
|
857
|
+
|
|
858
|
+
const picker = node.closest('.dz-swatch')?.querySelector('input[type="color"]');
|
|
859
|
+
if (!picker) return;
|
|
860
|
+
|
|
861
|
+
const none = node.closest('.dz-swatch').classList.contains('is-none');
|
|
862
|
+
if (picker.value === hex && !none) return;
|
|
863
|
+
|
|
864
|
+
picker.value = hex;
|
|
865
|
+
picker.dispatchEvent(new Event('input', { bubbles: true }));
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
|
|
654
869
|
function onInput(event) {
|
|
870
|
+
if (event.target.dataset?.hex != null) {
|
|
871
|
+
onHex(event.target, event.type === 'change');
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
|
|
655
875
|
const node = event.target.closest?.(
|
|
656
876
|
'[data-field], [data-band], [data-band-height], [data-band-fill], [data-group-level], [data-group-option]');
|
|
657
877
|
if (!node) return;
|
|
658
878
|
|
|
659
879
|
if (node.tagName === 'TEXTAREA') repaint(node);
|
|
660
880
|
|
|
881
|
+
/** a choice's button shows what its select holds, however it was set */
|
|
882
|
+
if (node.tagName === 'SELECT') showChoice(node);
|
|
883
|
+
|
|
661
884
|
/** how one level's groups are ordered and placed, on the selected table */
|
|
662
885
|
if (node.dataset.groupOption != null) {
|
|
663
886
|
const item = getItem();
|
|
@@ -707,6 +930,7 @@ export function attachPanel({
|
|
|
707
930
|
|
|
708
931
|
const field = COLUMN_FIELDS.find(f => f.key === node.dataset.field);
|
|
709
932
|
if (field && writeField(column, field, node.value)) {
|
|
933
|
+
summarise(node.closest('.dz-column'), column);
|
|
710
934
|
changed(`column:${node.dataset.column}:${field.key}`);
|
|
711
935
|
}
|
|
712
936
|
return;
|
|
@@ -719,7 +943,7 @@ export function attachPanel({
|
|
|
719
943
|
if (!field) return;
|
|
720
944
|
|
|
721
945
|
if (node.tagName === 'SELECT' && node.value === CUSTOM_CHOICE) {
|
|
722
|
-
const box = node.
|
|
946
|
+
const box = node.closest('.dz-choice-custom')?.querySelector('[data-custom]');
|
|
723
947
|
if (box) {
|
|
724
948
|
box.hidden = false;
|
|
725
949
|
box.focus();
|
|
@@ -730,7 +954,10 @@ export function attachPanel({
|
|
|
730
954
|
const raw = field.type === 'toggle' ? node.checked : node.value;
|
|
731
955
|
|
|
732
956
|
/** a colour picked is no longer none, even one picked as black */
|
|
733
|
-
if (field.type === 'color')
|
|
957
|
+
if (field.type === 'color') {
|
|
958
|
+
markSwatch(node, false);
|
|
959
|
+
showHex(node, node.value);
|
|
960
|
+
}
|
|
734
961
|
|
|
735
962
|
/**
|
|
736
963
|
* A field may say which reading of its object decides the rail's
|
|
@@ -785,6 +1012,7 @@ export function attachPanel({
|
|
|
785
1012
|
|
|
786
1013
|
if (field && clearField(bound.target, field)) {
|
|
787
1014
|
markSwatch(node, true);
|
|
1015
|
+
showHex(node, null);
|
|
788
1016
|
changed(`field:${field.key}`);
|
|
789
1017
|
}
|
|
790
1018
|
return;
|
|
@@ -793,6 +1021,111 @@ export function attachPanel({
|
|
|
793
1021
|
act(node.dataset.action, node.dataset);
|
|
794
1022
|
}
|
|
795
1023
|
|
|
1024
|
+
/**
|
|
1025
|
+
* A column opened or closed stays that way through the next rebuild.
|
|
1026
|
+
* `toggle` does not bubble, so this listens on the way down.
|
|
1027
|
+
*/
|
|
1028
|
+
function onToggle(event) {
|
|
1029
|
+
const node = event.target;
|
|
1030
|
+
if (!node.classList?.contains('dz-column')) return;
|
|
1031
|
+
|
|
1032
|
+
const column = getItem()?.columns?.[Number(node.dataset.index)];
|
|
1033
|
+
if (column) openColumns.set(column, node.open);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* A hex box left holding something that is not a colour goes back to the
|
|
1038
|
+
* colour the field has - as a number box does to its last good value.
|
|
1039
|
+
*/
|
|
1040
|
+
function onLeave(event) {
|
|
1041
|
+
const node = event.target;
|
|
1042
|
+
if (node.dataset?.hex == null) return;
|
|
1043
|
+
|
|
1044
|
+
const swatch = node.closest('.dz-swatch');
|
|
1045
|
+
const picker = swatch?.querySelector('input[type="color"]');
|
|
1046
|
+
if (!picker) return;
|
|
1047
|
+
|
|
1048
|
+
node.value = swatch.classList.contains('is-none') ? '' : hexText(picker.value);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** Enter in a hex box settles it, three-digit shorthand included */
|
|
1052
|
+
function onKey(event) {
|
|
1053
|
+
if (event.key !== 'Enter' || event.target.dataset?.hex == null) return;
|
|
1054
|
+
|
|
1055
|
+
event.preventDefault();
|
|
1056
|
+
onHex(event.target, true);
|
|
1057
|
+
event.target.blur();
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Scrubbing: drag a number's label sideways to change it, a unit for every
|
|
1062
|
+
* two pixels and ten with Shift held - Figma's gesture.
|
|
1063
|
+
*
|
|
1064
|
+
* Each step is written into the box and announced as ordinary input, so
|
|
1065
|
+
* the write path, the clamping and the history's merging of one control's
|
|
1066
|
+
* edits into one step all apply without a second route in. A press that
|
|
1067
|
+
* never moves is a click, and puts the caret in the box as a label does.
|
|
1068
|
+
*/
|
|
1069
|
+
function onPress(event) {
|
|
1070
|
+
const handle = event.target.closest?.('.dz-scrub');
|
|
1071
|
+
if (!handle || event.button !== 0) return;
|
|
1072
|
+
|
|
1073
|
+
const box = handle.closest('.dz-field')?.querySelector('input[type="number"]');
|
|
1074
|
+
if (!box || box.disabled) return;
|
|
1075
|
+
|
|
1076
|
+
event.preventDefault();
|
|
1077
|
+
|
|
1078
|
+
const startX = event.clientX;
|
|
1079
|
+
const start = Number(box.value) || 0;
|
|
1080
|
+
const min = box.min !== '' ? Number(box.min) : -Infinity;
|
|
1081
|
+
const max = box.max !== '' ? Number(box.max) : Infinity;
|
|
1082
|
+
let moved = false;
|
|
1083
|
+
|
|
1084
|
+
handle.setPointerCapture?.(event.pointerId);
|
|
1085
|
+
|
|
1086
|
+
function move(e) {
|
|
1087
|
+
const dx = e.clientX - startX;
|
|
1088
|
+
if (!moved && Math.abs(dx) < 3) return;
|
|
1089
|
+
|
|
1090
|
+
if (!moved) {
|
|
1091
|
+
moved = true;
|
|
1092
|
+
panel.classList.add('is-scrubbing');
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
const step = e.shiftKey ? 10 : 1;
|
|
1096
|
+
const next = Math.min(max, Math.max(min, start + Math.round(dx / 2) * step));
|
|
1097
|
+
|
|
1098
|
+
if (String(next) === box.value) return;
|
|
1099
|
+
|
|
1100
|
+
box.value = String(next);
|
|
1101
|
+
box.dispatchEvent(new Event('input', { bubbles: true }));
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function end() {
|
|
1105
|
+
handle.removeEventListener('pointermove', move);
|
|
1106
|
+
handle.removeEventListener('pointerup', end);
|
|
1107
|
+
handle.removeEventListener('pointercancel', end);
|
|
1108
|
+
panel.classList.remove('is-scrubbing');
|
|
1109
|
+
|
|
1110
|
+
if (!moved) {
|
|
1111
|
+
box.focus();
|
|
1112
|
+
box.select?.();
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* The label is a <label>, whose click would put the caret in the
|
|
1118
|
+
* box at the end of a drag. One click is swallowed, and only the
|
|
1119
|
+
* one that ends this drag.
|
|
1120
|
+
*/
|
|
1121
|
+
handle.addEventListener('click', (e) => e.preventDefault(), { once: true, capture: true });
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
handle.addEventListener('pointermove', move);
|
|
1125
|
+
handle.addEventListener('pointerup', end);
|
|
1126
|
+
handle.addEventListener('pointercancel', end);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
796
1129
|
/**
|
|
797
1130
|
* A long value scrolls inside the box, and the layer behind it must scroll
|
|
798
1131
|
* by the same amount or the marks part company with the characters.
|
|
@@ -810,12 +1143,24 @@ export function attachPanel({
|
|
|
810
1143
|
/** a <select> and a colour picker report on change, not input */
|
|
811
1144
|
panel.addEventListener('change', onInput);
|
|
812
1145
|
panel.addEventListener('click', onClick);
|
|
1146
|
+
panel.addEventListener('focusout', onLeave);
|
|
1147
|
+
panel.addEventListener('keydown', onKey);
|
|
1148
|
+
panel.addEventListener('pointerdown', onPress);
|
|
1149
|
+
panel.addEventListener('toggle', onToggle, true);
|
|
1150
|
+
|
|
1151
|
+
/** the choices open the shared list rather than the operating system's */
|
|
1152
|
+
const detachChoices = attachChoices(panel);
|
|
813
1153
|
|
|
814
1154
|
return function detach() {
|
|
1155
|
+
detachChoices();
|
|
1156
|
+
panel.removeEventListener('toggle', onToggle, true);
|
|
815
1157
|
panel.removeEventListener('scroll', onScroll, true);
|
|
816
1158
|
panel.removeEventListener('input', onInput);
|
|
817
1159
|
panel.removeEventListener('change', onInput);
|
|
818
1160
|
panel.removeEventListener('click', onClick);
|
|
1161
|
+
panel.removeEventListener('focusout', onLeave);
|
|
1162
|
+
panel.removeEventListener('keydown', onKey);
|
|
1163
|
+
panel.removeEventListener('pointerdown', onPress);
|
|
819
1164
|
};
|
|
820
1165
|
}
|
|
821
1166
|
|
|
@@ -836,6 +1181,12 @@ export function syncPanel(panel, item, layout) {
|
|
|
836
1181
|
const target = item ?? layout;
|
|
837
1182
|
if (!target) return;
|
|
838
1183
|
|
|
1184
|
+
/** a closed column's row says its name and width, which an undo can change */
|
|
1185
|
+
for (const node of panel.querySelectorAll('.dz-column')) {
|
|
1186
|
+
const column = item?.columns?.[Number(node.dataset.index)];
|
|
1187
|
+
if (column) summarise(node, column);
|
|
1188
|
+
}
|
|
1189
|
+
|
|
839
1190
|
const fields = item ? allFields(item) : allReportFields(layout);
|
|
840
1191
|
|
|
841
1192
|
for (const node of panel.querySelectorAll('[data-field]')) {
|
|
@@ -856,7 +1207,16 @@ export function syncPanel(panel, item, layout) {
|
|
|
856
1207
|
const value = readField(source, field);
|
|
857
1208
|
|
|
858
1209
|
/** an undo can take a colour off, or put one back */
|
|
859
|
-
if (field.type === 'color')
|
|
1210
|
+
if (field.type === 'color') {
|
|
1211
|
+
markSwatch(node, value == null || value === '');
|
|
1212
|
+
showHex(node, value);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/** a row of glyph buttons: each one only says whether it is the one */
|
|
1216
|
+
if (node.type === 'radio') {
|
|
1217
|
+
node.checked = node.value === String(value ?? '');
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
860
1220
|
|
|
861
1221
|
/** a choice with Custom…: the select says which, the box holds any other */
|
|
862
1222
|
if (field.custom) {
|
|
@@ -884,6 +1244,9 @@ export function syncPanel(panel, item, layout) {
|
|
|
884
1244
|
}
|
|
885
1245
|
}
|
|
886
1246
|
}
|
|
1247
|
+
|
|
1248
|
+
/** every choice's button says what its select now holds */
|
|
1249
|
+
refreshChoices(panel);
|
|
887
1250
|
}
|
|
888
1251
|
|
|
889
1252
|
|