report-studio 0.0.1 → 1.0.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -4
  3. package/dist/designer.js +3209 -0
  4. package/dist/index.js +2 -4
  5. package/dist/viewer-D-c0lKzQ.js +1576 -0
  6. package/package.json +66 -33
  7. package/src/asset/images/icon.png +0 -0
  8. package/src/asset/images/logo.png +0 -0
  9. package/src/cli/index.js +282 -0
  10. package/src/cli/serve.js +135 -0
  11. package/src/designer/blank.js +53 -0
  12. package/src/designer/canvas.js +518 -0
  13. package/src/designer/designer.js +1900 -0
  14. package/src/designer/dialog.js +708 -0
  15. package/src/designer/fields.js +584 -0
  16. package/src/designer/geometry.js +154 -0
  17. package/src/designer/guides.js +370 -0
  18. package/src/designer/history.js +113 -0
  19. package/src/designer/icons.js +118 -0
  20. package/src/designer/index.html +28 -0
  21. package/src/designer/main.js +39 -0
  22. package/src/designer/menu.js +126 -0
  23. package/src/designer/panel.js +478 -0
  24. package/src/designer/preview.js +95 -0
  25. package/src/designer/rulers.js +231 -0
  26. package/src/designer/sample-data.js +240 -0
  27. package/src/designer/select.js +699 -0
  28. package/src/designer/structure.js +604 -0
  29. package/src/designer/styles.css +1616 -0
  30. package/src/designer/toast.js +62 -0
  31. package/src/designer/tokens.js +284 -0
  32. package/src/engine/csv.js +315 -0
  33. package/src/engine/group.js +304 -0
  34. package/src/engine/index.js +34 -0
  35. package/src/engine/measure.js +390 -0
  36. package/src/engine/paginate.js +861 -0
  37. package/src/engine/regions.js +175 -0
  38. package/src/engine/resolve.js +171 -0
  39. package/src/engine/search.js +129 -0
  40. package/src/engine/text-metrics.js +206 -0
  41. package/src/engine/validate.js +328 -0
  42. package/src/index.html +79 -0
  43. package/src/index.js +50 -0
  44. package/src/preview/chrome.css +505 -0
  45. package/src/preview/chrome.js +147 -0
  46. package/src/preview/index.html +28 -0
  47. package/src/preview/main.js +66 -0
  48. package/src/preview/styles.css +16 -0
  49. package/src/preview/viewer.js +745 -0
  50. package/src/render/items.js +425 -0
  51. package/src/render/render.js +98 -0
  52. package/src/render/report.css +202 -0
  53. package/src/server/routes.js +331 -0
  54. package/src/shared/brand.css +29 -0
  55. package/src/shared/dropdown.css +136 -0
  56. package/src/shared/dropdown.js +166 -0
  57. package/src/shared/modal.css +125 -0
  58. package/src/shared/prefix.js +13 -0
  59. package/src/shared/store.js +145 -0
  60. package/src/shared/theme.css +72 -0
  61. package/src/shared/window.js +138 -0
  62. package/src/vite/index.js +53 -0
  63. package/dist/react.js +0 -4
@@ -0,0 +1,118 @@
1
+ /**
2
+ * icons.js holds the designer's glyphs as inline SVG.
3
+ *
4
+ * Written out rather than pulled from an icon set: the package ships with zero
5
+ * dependencies and no binary assets, and an inline path costs nothing to load,
6
+ * stays sharp at any size, and takes its colour from `currentColor` - so a
7
+ * button's hover and focus states carry the glyph with them without a second
8
+ * file per state.
9
+ *
10
+ * Every glyph is aria-hidden and unfocusable. The button around it carries the
11
+ * label, so a screen reader hears "Add a text box" once rather than twice.
12
+ */
13
+
14
+
15
+ const wrap = (body) => `<svg viewBox="0 0 16 16" width="16" height="16"
16
+ fill="none" stroke="currentColor" stroke-width="1.5"
17
+ stroke-linecap="round" stroke-linejoin="round"
18
+ aria-hidden="true" focusable="false">${body}</svg>`;
19
+
20
+
21
+ export const ICONS = {
22
+ /** a serifed capital T, the tool mark every design app uses for type */
23
+ text: wrap(`<path d="M3 3.75h10M8 3.75v8.5M6.25 12.25h3.5"/>`),
24
+
25
+ /** a grid whose first row is ruled off, so it reads as a table not a frame */
26
+ table: wrap(`<rect x="2.25" y="3.25" width="11.5" height="9.5" rx="1.25"/>
27
+ <path d="M2.25 6.5h11.5M6.5 6.5v6.25M10 6.5v6.25"/>`),
28
+
29
+ /** an empty rectangle: the frame, and nothing in it */
30
+ box: wrap(`<rect x="2.5" y="3.75" width="11" height="8.5" rx="1.25"/>`),
31
+
32
+ /** a rule across the middle, with the dashes that say it need not be solid */
33
+ line: wrap(`<path d="M2 8h3.5M7.25 8h1.5M10.5 8H14"/>`),
34
+
35
+ /** a rule with its ticks - the tool, drawn as itself */
36
+ ruler: wrap(`<rect x="1.75" y="5.25" width="12.5" height="5.5" rx="1"/>
37
+ <path d="M4.5 5.25v2M7 5.25v3M9.5 5.25v2M12 5.25v3"/>`),
38
+
39
+ /** an arrow curving back on itself, the mark undo has had for forty years */
40
+ undo: wrap(`<path d="M6 4.5 2.75 7.75 6 11"/>
41
+ <path d="M2.75 7.75h6.75a3.75 3.75 0 0 1 0 7.5H7"/>`),
42
+
43
+ /** and its mirror, so the pair reads as one control at a glance */
44
+ redo: wrap(`<path d="M10 4.5l3.25 3.25L10 11"/>
45
+ <path d="M13.25 7.75H6.5a3.75 3.75 0 0 0 0 7.5H9"/>`),
46
+
47
+ /** a folder, opened - the report being swapped for another */
48
+ open: wrap(`<path d="M1.75 12.5V4a.75.75 0 0 1 .75-.75h3.4l1.5 1.75h5.35
49
+ a.75.75 0 0 1 .75.75v1.5"/>
50
+ <path d="M1.75 12.5 3.6 7.5h11.15l-1.85 5z"/>`),
51
+
52
+ /** braces - the mark a placeholder wears everywhere in this format */
53
+ field: wrap(`<path d="M6.25 2.75c-1.5 0-2 .8-2 2v1.4c0 .9-.55 1.5-1.5 1.85
54
+ .95.35 1.5.95 1.5 1.85v1.4c0 1.2.5 2 2 2"/>
55
+ <path d="M9.75 2.75c1.5 0 2 .8 2 2v1.4c0 .9.55 1.5 1.5 1.85
56
+ -.95.35-1.5.95-1.5 1.85v1.4c0 1.2-.5 2-2 2"/>`),
57
+
58
+ /** an arrow leaving its box: the preview screen, opened beside this one */
59
+ external: wrap(`<path d="M9.5 2.75h3.75V6.5"/>
60
+ <path d="M13.25 2.75 7.5 8.5"/>
61
+ <path d="M11.5 9.25v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7
62
+ a1 1 0 0 1 1-1h3"/>`),
63
+
64
+ /** an eye: what the report looks like once it has run */
65
+ preview: wrap(`<path d="M1 8s2.6-4.25 7-4.25S15 8 15 8s-2.6 4.25-7 4.25S1 8 1 8z"/>
66
+ <circle cx="8" cy="8" r="1.9"/>`),
67
+
68
+ /** a pencil, for going back to arranging it */
69
+ design: wrap(`<path d="M11.4 2.85 13.15 4.6 5.3 12.45l-2.4.65.65-2.4z"/>
70
+ <path d="M10.15 4.1l1.75 1.75"/>`),
71
+
72
+ /** stacked discs, the mark a database or a dataset has always had */
73
+ data: wrap(`<ellipse cx="8" cy="4" rx="5.25" ry="2"/>
74
+ <path d="M2.75 4v8c0 1.1 2.35 2 5.25 2s5.25-.9 5.25-2V4"/>
75
+ <path d="M2.75 8c0 1.1 2.35 2 5.25 2s5.25-.9 5.25-2"/>`),
76
+
77
+ /**
78
+ * Two plain squares, offset: one more of the same thing. Deliberately not
79
+ * the two-sheets mark below - duplicate and copy sit next to each other in
80
+ * the rail, and two glyphs that differ only in detail are two glyphs nobody
81
+ * can tell apart at 16px.
82
+ */
83
+ duplicate: wrap(`<rect x="2.5" y="2.5" width="8" height="8" rx="1.25"/>
84
+ <rect x="5.5" y="5.5" width="8" height="8" rx="1.25"/>`),
85
+
86
+ /** a sheet over a sheet: the copy mark, notched corner and all */
87
+ copy: wrap(`<path d="M6 2.25h3.6L12.25 4.9v5.85a.75.75 0 0 1-.75.75H6
88
+ a.75.75 0 0 1-.75-.75V3a.75.75 0 0 1 .75-.75z"/>
89
+ <path d="M9.35 2.4v2.65h2.75"/>
90
+ <path d="M3.9 5.5H3a.75.75 0 0 0-.75.75V13a.75.75 0 0 0 .75.75h5.4
91
+ a.75.75 0 0 0 .75-.75v-.75"/>`),
92
+
93
+ /** a bin, for the one action in the menu worth drawing in red */
94
+ delete: wrap(`<path d="M2.75 4.5h10.5"/>
95
+ <path d="M6.25 4.5V3.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 .75.75V4.5"/>
96
+ <path d="M4.4 4.5l.55 8.15a.85.85 0 0 0 .85.8h4.4a.85.85 0 0 0 .85-.8L11.6 4.5"/>
97
+ <path d="M6.85 7v3.75M9.15 7v3.75"/>`),
98
+
99
+ /** a clipboard, clip and all - where a copy comes back from */
100
+ paste: wrap(`<path d="M6.25 3.25H4.5a.75.75 0 0 0-.75.75v8.75
101
+ a.75.75 0 0 0 .75.75h7a.75.75 0 0 0 .75-.75V4
102
+ a.75.75 0 0 0-.75-.75H9.75"/>
103
+ <rect x="6.25" y="1.75" width="3.5" height="2.75" rx=".85"/>`),
104
+
105
+ /** a disk: the shutter above, the label below */
106
+ save: wrap(`<path d="M2.75 3.25h8.5l2.5 2.5v7a.5.5 0 0 1-.5.5h-11
107
+ a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5z"/>
108
+ <path d="M5 3.25v3.5h5.5v-3.5M5 13.25V9.5h6v3.75"/>`)
109
+ };
110
+
111
+
112
+ /**
113
+ * @param {string} name
114
+ * @returns {string} markup, or empty for a glyph that does not exist
115
+ */
116
+ export function icon(name) {
117
+ return ICONS[name] ?? '';
118
+ }
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Report Designer</title>
8
+ <link rel="icon" type="image/png" href="../asset/images/icon.png">
9
+ <link rel="stylesheet" href="./styles.css">
10
+ <link rel="preconnect" href="https://fonts.googleapis.com">
11
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12
+ <link
13
+ href="https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700&family=Instrument+Sans:ital,wght@0,400..700;1,400..700&display=swap"
14
+ rel="stylesheet">
15
+ </head>
16
+
17
+ <body>
18
+ <!--
19
+ The whole host-facing API: one empty element. createDesigner builds its
20
+ own bar, gutter and canvas inside this, so a consumer never copies
21
+ markup out of here to get a working designer.
22
+ -->
23
+ <div id="report-designer"></div>
24
+
25
+ <script type="module" src="./main.js"></script>
26
+ </body>
27
+
28
+ </html>
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The designer page's entry.
3
+ *
4
+ * It opens whatever the URL asks for:
5
+ *
6
+ * /designer/ a blank report
7
+ * /designer/?report=<id> a saved report, through the dev server
8
+ * /designer/?fixture the sales-summary fixture, for poking at
9
+ *
10
+ * The fixture is loaded dynamically and its failure is survivable, because it
11
+ * is a development file that sits outside what the CLI serves. A static import
12
+ * of it would make this page work under `npm run dev` and break under
13
+ * `npx report-studio design`, which is the shipped path of the two.
14
+ */
15
+
16
+ import { createDesigner } from './designer.js';
17
+ import { createStore } from '../shared/store.js';
18
+
19
+ const params = new URLSearchParams(location.search);
20
+ const wanted = params.get('report');
21
+
22
+ const designer = createDesigner({ mount: '#report-designer', layout: {} });
23
+
24
+ if (wanted) {
25
+ /**
26
+ * Loaded through the store rather than fetched here, so a missing report
27
+ * reports itself the way it would for anyone else.
28
+ */
29
+ createStore().load(wanted)
30
+ .then(layout => designer.open(layout, wanted))
31
+ .catch(error => console.warn(`could not open "${wanted}": ${error.message}`));
32
+ } else if (params.has('fixture')) {
33
+ import('../../fixtures/test-data.js')
34
+ .then(({ rptJson }) => designer.open(structuredClone(rptJson)))
35
+ .catch(() => console.warn('the fixtures are only there under `npm run dev`'));
36
+ }
37
+
38
+ /** handy from the devtools console while poking at a layout */
39
+ window.designer = designer;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * menu.js is the pill that opens where you right-click.
3
+ *
4
+ * Duplicate, copy, paste and delete used to live in the properties rail and the
5
+ * tool strip - which meant a round trip to the edge of the screen to act on the
6
+ * thing under the cursor, and a rail that was only drawn for a selection could
7
+ * never offer paste at all. They belong at the pointer, on the item they act on.
8
+ *
9
+ * What it offers is a pure function of what is selected and what is on the
10
+ * clipboard, and where it lands is arithmetic - so both are specified here,
11
+ * without a browser. What is left in designer.js is measuring the pill and
12
+ * putting it on the page.
13
+ */
14
+
15
+ import { icon } from './icons.js';
16
+ import { esc } from '../render/items.js';
17
+
18
+
19
+ /** the gap kept between the pill and the edge it would otherwise cross */
20
+ export const MENU_EDGE_GAP = 8;
21
+
22
+
23
+ /**
24
+ * What the menu offers.
25
+ *
26
+ * Paste is always listed, disabled when there is nothing to paste: a right
27
+ * click that opens an empty pill says the menu is broken, while one that opens
28
+ * a greyed Paste says the clipboard is empty, which is the true answer.
29
+ *
30
+ * @param {object} options
31
+ * @param {number} [options.count] how many items are selected
32
+ * @param {boolean} [options.canPaste] whether the clipboard holds anything
33
+ * @param {boolean} [options.canDuplicate] false when a copy of the selection
34
+ * would be one the report cannot hold - a second table, today
35
+ * @returns {object[]} entries, in the order they are drawn
36
+ */
37
+ export function menuActions({
38
+ count = 0, canPaste = false, canDuplicate = true
39
+ } = {}) {
40
+ const many = count > 1 ? ` ${count} items` : '';
41
+
42
+ const paste = {
43
+ action: 'paste-items',
44
+ glyph: 'paste',
45
+ label: 'Paste',
46
+ hint: 'ctrl+V',
47
+ disabled: !canPaste
48
+ };
49
+
50
+ if (count < 1) return [paste];
51
+
52
+ return [
53
+ {
54
+ action: 'duplicate-item',
55
+ glyph: 'duplicate',
56
+ label: canDuplicate
57
+ ? `Duplicate${many}`
58
+ : 'A report holds one table',
59
+ hint: 'ctrl+D, or alt-drag',
60
+ disabled: !canDuplicate
61
+ },
62
+ {
63
+ action: 'copy-items',
64
+ glyph: 'copy',
65
+ label: `Copy${many}`,
66
+ hint: 'ctrl+C'
67
+ },
68
+ paste,
69
+ { separator: true },
70
+ {
71
+ action: 'delete-item',
72
+ glyph: 'delete',
73
+ label: `Delete${many}`,
74
+ hint: 'del',
75
+ tone: 'danger'
76
+ }
77
+ ];
78
+ }
79
+
80
+
81
+ /**
82
+ * The pill's markup. Icon-only, like the bar and the tool strip: the label is
83
+ * on the button for a screen reader and in the tooltip for everyone else, so
84
+ * the pill stays small enough to open over the page without covering it.
85
+ *
86
+ * @param {object[]} actions from menuActions
87
+ * @returns {string} markup
88
+ */
89
+ export function drawMenu(actions) {
90
+ const entry = (one) => one.separator
91
+ ? '<span class="dz-menu-sep" aria-hidden="true"></span>'
92
+ : `<button type="button" role="menuitem"
93
+ class="dz-menu-item${one.tone ? ` is-${esc(one.tone)}` : ''}"
94
+ data-action="${esc(one.action)}"
95
+ title="${esc(one.label)} (${esc(one.hint)})"
96
+ aria-label="${esc(one.label)}"
97
+ ${one.disabled ? 'disabled' : ''}
98
+ >${icon(one.glyph)}</button>`;
99
+
100
+ return `<div class="dz-menu" data-role="menu" role="menu"
101
+ aria-label="Item actions">${actions.map(entry).join('')}</div>`;
102
+ }
103
+
104
+
105
+ /**
106
+ * Where the pill sits, in the coordinates of the area it is drawn into.
107
+ *
108
+ * Clamped rather than flipped: a pill is a strip a few buttons wide, so sliding
109
+ * it back inside the edge keeps it beside the pointer, where flipping it would
110
+ * throw it to the far side of whatever was clicked.
111
+ *
112
+ * @param {{x: number, y: number}} point the pointer, relative to `bounds`
113
+ * @param {{width: number, height: number}} size the pill, as measured
114
+ * @param {{width: number, height: number}} bounds the area it must stay inside
115
+ * @param {number} [gap]
116
+ * @returns {{left: number, top: number}}
117
+ */
118
+ export function menuPosition(point, size, bounds, gap = MENU_EDGE_GAP) {
119
+ const fit = (at, extent, limit) =>
120
+ Math.min(Math.max(gap, at), Math.max(gap, limit - extent - gap));
121
+
122
+ return {
123
+ left: fit(point.x, size.width, bounds.width),
124
+ top: fit(point.y, size.height, bounds.height)
125
+ };
126
+ }