report-studio 1.0.0 → 1.2.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 (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +171 -22
  3. package/dist/designer-qy59eEux.js +3416 -0
  4. package/dist/designer.js +2 -3209
  5. package/dist/index.js +2 -2
  6. package/dist/react-designer.js +41 -0
  7. package/dist/react.js +60 -0
  8. package/dist/{viewer-D-c0lKzQ.js → viewer-xa17tyMJ.js} +682 -537
  9. package/package.json +105 -66
  10. package/src/cli/serve.js +135 -135
  11. package/src/designer/designer.js +2054 -1900
  12. package/src/designer/dialog.js +708 -708
  13. package/src/designer/fields.js +51 -2
  14. package/src/designer/icons.js +5 -0
  15. package/src/designer/index.html +28 -28
  16. package/src/designer/main.js +39 -39
  17. package/src/designer/menu.js +2 -2
  18. package/src/designer/panel.js +21 -1
  19. package/src/designer/sample-data.js +180 -9
  20. package/src/designer/structure.js +87 -6
  21. package/src/designer/styles.css +1654 -1616
  22. package/src/designer/tokens.js +9 -0
  23. package/src/engine/csv.js +350 -315
  24. package/src/engine/group.js +128 -65
  25. package/src/engine/index.js +35 -34
  26. package/src/engine/measure.js +13 -12
  27. package/src/engine/paginate.js +8 -4
  28. package/src/engine/resolve.js +37 -0
  29. package/src/engine/tables.js +87 -0
  30. package/src/engine/validate.js +97 -22
  31. package/src/index.html +79 -79
  32. package/src/index.js +51 -50
  33. package/src/preview/chrome.css +505 -505
  34. package/src/preview/chrome.js +147 -147
  35. package/src/preview/index.html +28 -28
  36. package/src/preview/viewer.js +763 -745
  37. package/src/react/designer.js +87 -0
  38. package/src/react/index.js +117 -0
  39. package/src/render/items.js +94 -1
  40. package/src/render/report.css +30 -0
  41. package/src/server/routes.js +331 -331
  42. package/src/shared/brand.css +29 -29
  43. package/src/shared/dropdown.css +136 -136
  44. package/src/shared/modal.css +125 -125
  45. package/src/shared/store.js +145 -145
  46. package/src/shared/theme.css +72 -72
  47. package/src/shared/window.js +138 -138
  48. package/types/designer.d.ts +85 -0
  49. package/types/index.d.ts +204 -0
  50. package/types/layout.d.ts +179 -0
  51. package/types/react-designer.d.ts +29 -0
  52. package/types/react.d.ts +30 -0
  53. package/types/vite.d.ts +18 -0
@@ -1,72 +1,72 @@
1
- /**
2
- * 60 - 30 - 10.
3
- *
4
- * 60% --surface #fdfdfe paper, toolbar, dialog: every calm surface
5
- * 30% --accent #ff9c4b every action, highlight and selected state
6
- * 10% --border #cdd4db borders and dividers, nothing else
7
- *
8
- * The backdrop is neutral rather than accent-tinted, so the accent has to earn
9
- * its share through the Export button, search hits and selected cards instead
10
- * of through one large wash. Tint --backdrop toward --accent to give it more.
11
- *
12
- * The three shades below are mixes of those, not new colours - each one exists
13
- * because the base is too light to carry contrast on its own, and each says
14
- * which ratio it buys. Change the three above and the shades stay in family.
15
- *
16
- * The product's two marks come in with it, from brand.css: they are drawn from
17
- * this palette, so whoever takes the palette should get them as well.
18
- */
19
- @import "./brand.css";
20
-
21
- :root {
22
- /* the palette */
23
- --surface: #fdfdfe;
24
- --accent: #ff9c4b;
25
- --border: #cdd4db;
26
-
27
- /* the ground the page sits on - a shade cooler than the paper, so the sheet
28
- is told apart by its border rather than by a change in temperature */
29
- --backdrop: #fbfcfd;
30
- /* accent at 12% over surface - selected rows and cards */
31
- --accent-soft: #fdf1e9;
32
- /* accent at 70% over surface - a search hit you can see but are not standing on.
33
- 1.66:1 against the paper, where the yellow it replaces managed 1.23:1 */
34
- --accent-tint: #feb981;
35
- /* accent darkened - 3.5:1 on surface, enough for focus rings and active borders */
36
- --accent-strong: #cc6f20;
37
- /* darker still - 5.8:1 both ways, so it can carry text or sit under it */
38
- --accent-ink: #8f572a;
39
- /* border at 25% over surface - table headers and other quiet fills */
40
- --surface-muted: #f1f3f5;
41
-
42
- /* the one destructive action in the designer, and the tint behind it */
43
- --danger: #b3261e;
44
- --danger-soft: #fdecec;
45
-
46
- /* ink. #ff9c4b is light, so text on the accent is dark, never white: 7.25:1 */
47
- --ink: #22272c;
48
- --ink-soft: #667080;
49
-
50
- --bar-height: 56px;
51
- --pager-height: 44px;
52
- /* how far the floating pager sits off the bottom edge */
53
- --pager-offset: 20px;
54
- }
55
-
56
- * {
57
- box-sizing: border-box;
58
- margin: 0;
59
- padding: 0;
60
- }
61
-
62
- body {
63
- font-family: "Courier Prime", monospace;
64
- font-weight: 400;
65
- font-style: normal;
66
- }
67
-
68
- /*
69
- * Lifted out of the preview's stylesheet so the designer inherits exactly the
70
- * same palette. A second copy of these values is a second thing to keep in
71
- * step, and the one that falls behind is always the one nobody is looking at.
72
- */
1
+ /**
2
+ * 60 - 30 - 10.
3
+ *
4
+ * 60% --surface #fdfdfe paper, toolbar, dialog: every calm surface
5
+ * 30% --accent #ff9c4b every action, highlight and selected state
6
+ * 10% --border #cdd4db borders and dividers, nothing else
7
+ *
8
+ * The backdrop is neutral rather than accent-tinted, so the accent has to earn
9
+ * its share through the Export button, search hits and selected cards instead
10
+ * of through one large wash. Tint --backdrop toward --accent to give it more.
11
+ *
12
+ * The three shades below are mixes of those, not new colours - each one exists
13
+ * because the base is too light to carry contrast on its own, and each says
14
+ * which ratio it buys. Change the three above and the shades stay in family.
15
+ *
16
+ * The product's two marks come in with it, from brand.css: they are drawn from
17
+ * this palette, so whoever takes the palette should get them as well.
18
+ */
19
+ @import "./brand.css";
20
+
21
+ :root {
22
+ /* the palette */
23
+ --surface: #fdfdfe;
24
+ --accent: #ff9c4b;
25
+ --border: #cdd4db;
26
+
27
+ /* the ground the page sits on - a shade cooler than the paper, so the sheet
28
+ is told apart by its border rather than by a change in temperature */
29
+ --backdrop: #fbfcfd;
30
+ /* accent at 12% over surface - selected rows and cards */
31
+ --accent-soft: #fdf1e9;
32
+ /* accent at 70% over surface - a search hit you can see but are not standing on.
33
+ 1.66:1 against the paper, where the yellow it replaces managed 1.23:1 */
34
+ --accent-tint: #feb981;
35
+ /* accent darkened - 3.5:1 on surface, enough for focus rings and active borders */
36
+ --accent-strong: #cc6f20;
37
+ /* darker still - 5.8:1 both ways, so it can carry text or sit under it */
38
+ --accent-ink: #8f572a;
39
+ /* border at 25% over surface - table headers and other quiet fills */
40
+ --surface-muted: #f1f3f5;
41
+
42
+ /* the one destructive action in the designer, and the tint behind it */
43
+ --danger: #b3261e;
44
+ --danger-soft: #fdecec;
45
+
46
+ /* ink. #ff9c4b is light, so text on the accent is dark, never white: 7.25:1 */
47
+ --ink: #22272c;
48
+ --ink-soft: #667080;
49
+
50
+ --bar-height: 56px;
51
+ --pager-height: 44px;
52
+ /* how far the floating pager sits off the bottom edge */
53
+ --pager-offset: 20px;
54
+ }
55
+
56
+ * {
57
+ box-sizing: border-box;
58
+ margin: 0;
59
+ padding: 0;
60
+ }
61
+
62
+ body {
63
+ font-family: "Courier Prime", monospace;
64
+ font-weight: 400;
65
+ font-style: normal;
66
+ }
67
+
68
+ /*
69
+ * Lifted out of the preview's stylesheet so the designer inherits exactly the
70
+ * same palette. A second copy of these values is a second thing to keep in
71
+ * step, and the one that falls behind is always the one nobody is looking at.
72
+ */
@@ -1,138 +1,138 @@
1
- /**
2
- * window.js opens a screen in a window of its own.
3
- *
4
- * A designer or a viewer normally takes over an element on the host's page.
5
- * Sometimes the host would rather it were somewhere else entirely - a second
6
- * monitor, beside the application rather than inside it - and a report is a
7
- * page-shaped thing that a browser tab suits better than a panel.
8
- *
9
- * Opened blank and built here rather than navigated to a URL: the package is
10
- * usable with no server at all, and a report being designed has not been saved
11
- * anywhere a URL could reach. What the new window needs is the host's own
12
- * stylesheets, which are copied across - so the screen looks the same in its
13
- * own window as it did in the page, without the host linking anything twice.
14
- */
15
-
16
-
17
- /** big enough for an A4 page and the chrome round it, on a laptop screen */
18
- const DEFAULT_WIDTH = 1280;
19
- const DEFAULT_HEIGHT = 900;
20
-
21
-
22
- /**
23
- * Copies the opener's stylesheets into a new document.
24
- *
25
- * Both kinds, because a host may do either: a `<link>` to a file, or a `<style>`
26
- * a bundler inlined. Links are copied by href rather than cloned wholesale, so
27
- * the new document fetches them itself and the browser's cache does the work.
28
- *
29
- * A cross-origin sheet cannot be read, only linked - which is exactly what
30
- * happens here, so nothing is lost to it.
31
- *
32
- * @param {Document} from
33
- * @param {Document} to
34
- */
35
- function copyStyles(from, to) {
36
- for (const node of from.querySelectorAll('link[rel="stylesheet"], style')) {
37
- if (node.tagName === 'LINK') {
38
- const link = to.createElement('link');
39
-
40
- link.rel = 'stylesheet';
41
- link.href = node.href;
42
- to.head.appendChild(link);
43
- continue;
44
- }
45
-
46
- const style = to.createElement('style');
47
-
48
- style.textContent = node.textContent;
49
- to.head.appendChild(style);
50
- }
51
- }
52
-
53
-
54
- /**
55
- * Opens a blank window and prepares it to be mounted into.
56
- *
57
- * Must be called from something the user did - a click, a key - or the browser
58
- * treats it as a popup and blocks it. A blocked window is null rather than an
59
- * exception, because a host that cannot open one usually wants to fall back to
60
- * mounting in the page rather than to fail.
61
- *
62
- * @param {object} [options]
63
- * @param {string} [options.title] the window's title, and its taskbar name
64
- * @param {number} [options.width]
65
- * @param {number} [options.height]
66
- * @param {string} [options.features] passed to window.open as given, for a host
67
- * that wants something other than a plain resizable window
68
- * @param {Window} [options.opener] whose stylesheets to copy; this one by default
69
- * @returns {{window: Window, document: Document, mount: Element, close: Function}|null}
70
- * null when the browser refused to open it
71
- */
72
- export function openWindow({
73
- title = 'Report Studio',
74
- width = DEFAULT_WIDTH,
75
- height = DEFAULT_HEIGHT,
76
- features,
77
- opener = globalThis
78
- } = {}) {
79
- const spec = features
80
- ?? `width=${width},height=${height},resizable=yes,scrollbars=yes`;
81
-
82
- const win = opener.open?.('', '_blank', spec);
83
-
84
- /** blocked, or opened into something that is not a window we can build in */
85
- if (!win || !win.document) return null;
86
-
87
- const doc = win.document;
88
-
89
- doc.open();
90
- doc.write('<!doctype html><html><head><meta charset="utf-8">' +
91
- '</head><body></body></html>');
92
- doc.close();
93
-
94
- doc.title = title;
95
- copyStyles(opener.document, doc);
96
-
97
- /**
98
- * The screens take over an element and build the rest inside it, so what
99
- * they are given is one empty div - the same contract as mounting in a page.
100
- */
101
- const mount = doc.createElement('div');
102
-
103
- mount.id = 'report-studio';
104
- mount.style.height = '100vh';
105
- doc.body.style.margin = '0';
106
- doc.body.appendChild(mount);
107
-
108
- return {
109
- window: win,
110
- document: doc,
111
- mount,
112
- close: () => win.close()
113
- };
114
- }
115
-
116
-
117
- /**
118
- * Closes the window when the page that opened it goes.
119
- *
120
- * A window left behind by a navigated-away opener is one nobody can reach the
121
- * report data for: what it is showing was passed in memory, and the page that
122
- * held it has gone. Better to take it with us than to leave a dead screen open.
123
- *
124
- * @param {Window} opener
125
- * @param {Window} win
126
- * @param {Function} [detach] the screen's own teardown
127
- * @returns {Function} stops watching, without closing anything
128
- */
129
- export function closeWithOpener(opener, win, detach = () => { }) {
130
- const onUnload = () => {
131
- detach();
132
- win.close();
133
- };
134
-
135
- opener.addEventListener('pagehide', onUnload);
136
-
137
- return () => opener.removeEventListener('pagehide', onUnload);
138
- }
1
+ /**
2
+ * window.js opens a screen in a window of its own.
3
+ *
4
+ * A designer or a viewer normally takes over an element on the host's page.
5
+ * Sometimes the host would rather it were somewhere else entirely - a second
6
+ * monitor, beside the application rather than inside it - and a report is a
7
+ * page-shaped thing that a browser tab suits better than a panel.
8
+ *
9
+ * Opened blank and built here rather than navigated to a URL: the package is
10
+ * usable with no server at all, and a report being designed has not been saved
11
+ * anywhere a URL could reach. What the new window needs is the host's own
12
+ * stylesheets, which are copied across - so the screen looks the same in its
13
+ * own window as it did in the page, without the host linking anything twice.
14
+ */
15
+
16
+
17
+ /** big enough for an A4 page and the chrome round it, on a laptop screen */
18
+ const DEFAULT_WIDTH = 1280;
19
+ const DEFAULT_HEIGHT = 900;
20
+
21
+
22
+ /**
23
+ * Copies the opener's stylesheets into a new document.
24
+ *
25
+ * Both kinds, because a host may do either: a `<link>` to a file, or a `<style>`
26
+ * a bundler inlined. Links are copied by href rather than cloned wholesale, so
27
+ * the new document fetches them itself and the browser's cache does the work.
28
+ *
29
+ * A cross-origin sheet cannot be read, only linked - which is exactly what
30
+ * happens here, so nothing is lost to it.
31
+ *
32
+ * @param {Document} from
33
+ * @param {Document} to
34
+ */
35
+ function copyStyles(from, to) {
36
+ for (const node of from.querySelectorAll('link[rel="stylesheet"], style')) {
37
+ if (node.tagName === 'LINK') {
38
+ const link = to.createElement('link');
39
+
40
+ link.rel = 'stylesheet';
41
+ link.href = node.href;
42
+ to.head.appendChild(link);
43
+ continue;
44
+ }
45
+
46
+ const style = to.createElement('style');
47
+
48
+ style.textContent = node.textContent;
49
+ to.head.appendChild(style);
50
+ }
51
+ }
52
+
53
+
54
+ /**
55
+ * Opens a blank window and prepares it to be mounted into.
56
+ *
57
+ * Must be called from something the user did - a click, a key - or the browser
58
+ * treats it as a popup and blocks it. A blocked window is null rather than an
59
+ * exception, because a host that cannot open one usually wants to fall back to
60
+ * mounting in the page rather than to fail.
61
+ *
62
+ * @param {object} [options]
63
+ * @param {string} [options.title] the window's title, and its taskbar name
64
+ * @param {number} [options.width]
65
+ * @param {number} [options.height]
66
+ * @param {string} [options.features] passed to window.open as given, for a host
67
+ * that wants something other than a plain resizable window
68
+ * @param {Window} [options.opener] whose stylesheets to copy; this one by default
69
+ * @returns {{window: Window, document: Document, mount: Element, close: Function}|null}
70
+ * null when the browser refused to open it
71
+ */
72
+ export function openWindow({
73
+ title = 'Report Studio',
74
+ width = DEFAULT_WIDTH,
75
+ height = DEFAULT_HEIGHT,
76
+ features,
77
+ opener = globalThis
78
+ } = {}) {
79
+ const spec = features
80
+ ?? `width=${width},height=${height},resizable=yes,scrollbars=yes`;
81
+
82
+ const win = opener.open?.('', '_blank', spec);
83
+
84
+ /** blocked, or opened into something that is not a window we can build in */
85
+ if (!win || !win.document) return null;
86
+
87
+ const doc = win.document;
88
+
89
+ doc.open();
90
+ doc.write('<!doctype html><html><head><meta charset="utf-8">' +
91
+ '</head><body></body></html>');
92
+ doc.close();
93
+
94
+ doc.title = title;
95
+ copyStyles(opener.document, doc);
96
+
97
+ /**
98
+ * The screens take over an element and build the rest inside it, so what
99
+ * they are given is one empty div - the same contract as mounting in a page.
100
+ */
101
+ const mount = doc.createElement('div');
102
+
103
+ mount.id = 'report-studio';
104
+ mount.style.height = '100vh';
105
+ doc.body.style.margin = '0';
106
+ doc.body.appendChild(mount);
107
+
108
+ return {
109
+ window: win,
110
+ document: doc,
111
+ mount,
112
+ close: () => win.close()
113
+ };
114
+ }
115
+
116
+
117
+ /**
118
+ * Closes the window when the page that opened it goes.
119
+ *
120
+ * A window left behind by a navigated-away opener is one nobody can reach the
121
+ * report data for: what it is showing was passed in memory, and the page that
122
+ * held it has gone. Better to take it with us than to leave a dead screen open.
123
+ *
124
+ * @param {Window} opener
125
+ * @param {Window} win
126
+ * @param {Function} [detach] the screen's own teardown
127
+ * @returns {Function} stops watching, without closing anything
128
+ */
129
+ export function closeWithOpener(opener, win, detach = () => { }) {
130
+ const onUnload = () => {
131
+ detach();
132
+ win.close();
133
+ };
134
+
135
+ opener.addEventListener('pagehide', onUnload);
136
+
137
+ return () => opener.removeEventListener('pagehide', onUnload);
138
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * report-studio/designer - the visual report designer.
3
+ */
4
+
5
+ import type { BandType, Layout, ReportData } from './layout.js';
6
+ import type { WindowOptions } from './index.js';
7
+
8
+ export type * from './layout.js';
9
+
10
+
11
+ /**
12
+ * Where the designer's Open and Save read and write. Leave it out to use the
13
+ * dev server's routes (`npx report-studio design` or the Vite plugin).
14
+ */
15
+ export interface ReportStore {
16
+ /** the reports there are; the picker shows `name` and opens `id` */
17
+ list(): Promise<Array<{ id: string; name: string; [key: string]: unknown }>>;
18
+ load(id: string): Promise<Layout>;
19
+ save(id: string, layout: Layout): Promise<unknown>;
20
+ /** resolve to null, not throw, when the report has no data yet */
21
+ loadData?(id: string): Promise<ReportData | null>;
22
+ saveData?(id: string, data: ReportData): Promise<unknown>;
23
+ /** enables Delete in the report picker */
24
+ remove?(id: string): Promise<unknown>;
25
+ }
26
+
27
+ export interface DesignerOptions {
28
+ /** the element to take over, or a selector for it */
29
+ mount: Element | string;
30
+ /** the report to edit; absent starts a blank one */
31
+ layout?: Layout;
32
+ /** the report's filename stem, when it has one */
33
+ id?: string | null;
34
+ store?: ReportStore;
35
+ /** confirm before a tab with unsaved changes closes; default true */
36
+ guardUnload?: boolean;
37
+ /**
38
+ * Called after every edit, undo and redo. Receives the designer's own
39
+ * object: clone it before keeping it.
40
+ */
41
+ onChange?: ((layout: Layout) => void) | null;
42
+ }
43
+
44
+ export interface DesignerSelection {
45
+ band: BandType;
46
+ id: string;
47
+ }
48
+
49
+ export interface DesignerHandle {
50
+ /** the layout as it currently stands */
51
+ readonly layout: Layout;
52
+ readonly mode: 'design' | 'preview';
53
+ /** the data the report asks for, derived from the layout */
54
+ readonly sampleData: ReportData;
55
+ /** the most recently selected item, or null */
56
+ readonly selection: DesignerSelection | null;
57
+ /** every selected item, oldest first */
58
+ readonly selections: DesignerSelection[];
59
+ /** the filename stem the report is saved under, or null */
60
+ readonly id: string | null;
61
+ /** whether there are unsaved changes */
62
+ readonly dirty: boolean;
63
+ select(
64
+ next: DesignerSelection | DesignerSelection[] | null,
65
+ options?: { add?: boolean }
66
+ ): void;
67
+ togglePreview(): Promise<void>;
68
+ /** swap the report being edited; returns its validation issues */
69
+ open(layout: Layout | null, id?: string | null): string[];
70
+ /** save where it came from, asking for a name the first time */
71
+ save(): Promise<void>;
72
+ redraw(): void;
73
+ destroy(): void;
74
+ }
75
+
76
+ /** mounts the designer into an element */
77
+ export function createDesigner(options: DesignerOptions): DesignerHandle;
78
+
79
+ /**
80
+ * Opens the designer in a window of its own. Call it from a click or a keypress.
81
+ * @returns null when the browser blocked the window
82
+ */
83
+ export function openDesignerWindow(
84
+ options: Omit<DesignerOptions, 'mount'> & WindowOptions
85
+ ): (DesignerHandle & { window: Window }) | null;