report-studio 1.0.0 → 1.1.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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +129 -4
  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 +80 -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
@@ -1,125 +1,125 @@
1
- /**
2
- * modal.css is the dialog shell both screens use.
3
- *
4
- * Lifted out of the preview's stylesheet when the designer grew a dialog of its
5
- * own. A second copy would be a second thing to keep in step, and the one that
6
- * falls behind is the one nobody is looking at.
7
- *
8
- * Hand-written rather than <dialog>: that element is still unimplemented in the
9
- * environment the specs run in, and a stubbed showModal would test the stub
10
- * instead of the behaviour.
11
- *
12
- * What is NOT here: anything about what a particular dialog contains. The
13
- * export format cards stay with the preview, and the designer's own fields stay
14
- * with the designer.
15
- */
16
-
17
- .modal[hidden] {
18
- display: none;
19
- }
20
-
21
- .modal {
22
- position: fixed;
23
- inset: 0;
24
- z-index: 20;
25
- display: grid;
26
- place-items: center;
27
- font-family: "Instrument Sans", system-ui, sans-serif;
28
- color: var(--ink);
29
- }
30
-
31
- /* the scrim is the ink colour, so nothing new enters the palette */
32
- .modal-backdrop {
33
- position: absolute;
34
- inset: 0;
35
- background: rgba(34, 39, 44, .45);
36
- }
37
-
38
- .modal-card {
39
- position: relative;
40
- width: min(420px, calc(100vw - 32px));
41
- padding: 20px;
42
- border: 1px solid var(--border);
43
- background: var(--surface);
44
- box-shadow: 0 12px 40px rgba(34, 39, 44, .22);
45
- }
46
-
47
- .modal-card h2 {
48
- margin-bottom: 14px;
49
- font-size: 16px;
50
- font-weight: 600;
51
- }
52
-
53
- .modal-summary {
54
- min-height: 18px;
55
- margin: 12px 2px 0;
56
- font-size: 12px;
57
- color: var(--ink-soft);
58
- }
59
-
60
- .modal-actions {
61
- display: flex;
62
- justify-content: flex-end;
63
- gap: 8px;
64
- margin-top: 16px;
65
- }
66
-
67
- .modal-actions button {
68
- height: 34px;
69
- padding: 0 16px;
70
- border: 1px solid var(--border);
71
- border-radius: 6px;
72
- background: var(--surface);
73
- color: var(--ink);
74
- font: inherit;
75
- font-size: 13px;
76
- cursor: pointer;
77
- }
78
-
79
- .modal-actions button:hover:not(:disabled) {
80
- background: var(--accent-soft);
81
- border-color: var(--accent);
82
- }
83
-
84
- /* dark ink on the accent, never white: 7.25:1 against 2.08:1 */
85
- .modal-actions button.is-primary {
86
- border-color: var(--accent);
87
- background: var(--accent);
88
- color: var(--ink);
89
- font-weight: 600;
90
- }
91
-
92
- .modal-actions button.is-primary:hover:not(:disabled) {
93
- background: var(--accent-ink);
94
- border-color: var(--accent-ink);
95
- color: var(--surface);
96
- }
97
-
98
- /**
99
- * The button that throws something away. It stays a plain button rather than
100
- * taking a fill: it sits beside the one that keeps the work, and two filled
101
- * buttons in a row make the reader pick by position instead of by reading.
102
- * The colour arrives on hover, once the pointer is already on it.
103
- */
104
- .modal-actions button.is-danger {
105
- color: var(--danger);
106
- }
107
-
108
- .modal-actions button.is-danger:hover:not(:disabled) {
109
- background: var(--danger-soft);
110
- border-color: var(--danger);
111
- }
112
-
113
- .modal-actions button:disabled {
114
- opacity: .5;
115
- cursor: default;
116
- }
117
-
118
- .modal-actions button:focus-visible {
119
- outline: 2px solid var(--accent-strong);
120
- outline-offset: 2px;
121
- }
122
-
123
- @media print {
124
- .modal { display: none; }
125
- }
1
+ /**
2
+ * modal.css is the dialog shell both screens use.
3
+ *
4
+ * Lifted out of the preview's stylesheet when the designer grew a dialog of its
5
+ * own. A second copy would be a second thing to keep in step, and the one that
6
+ * falls behind is the one nobody is looking at.
7
+ *
8
+ * Hand-written rather than <dialog>: that element is still unimplemented in the
9
+ * environment the specs run in, and a stubbed showModal would test the stub
10
+ * instead of the behaviour.
11
+ *
12
+ * What is NOT here: anything about what a particular dialog contains. The
13
+ * export format cards stay with the preview, and the designer's own fields stay
14
+ * with the designer.
15
+ */
16
+
17
+ .modal[hidden] {
18
+ display: none;
19
+ }
20
+
21
+ .modal {
22
+ position: fixed;
23
+ inset: 0;
24
+ z-index: 20;
25
+ display: grid;
26
+ place-items: center;
27
+ font-family: "Instrument Sans", system-ui, sans-serif;
28
+ color: var(--ink);
29
+ }
30
+
31
+ /* the scrim is the ink colour, so nothing new enters the palette */
32
+ .modal-backdrop {
33
+ position: absolute;
34
+ inset: 0;
35
+ background: rgba(34, 39, 44, .45);
36
+ }
37
+
38
+ .modal-card {
39
+ position: relative;
40
+ width: min(420px, calc(100vw - 32px));
41
+ padding: 20px;
42
+ border: 1px solid var(--border);
43
+ background: var(--surface);
44
+ box-shadow: 0 12px 40px rgba(34, 39, 44, .22);
45
+ }
46
+
47
+ .modal-card h2 {
48
+ margin-bottom: 14px;
49
+ font-size: 16px;
50
+ font-weight: 600;
51
+ }
52
+
53
+ .modal-summary {
54
+ min-height: 18px;
55
+ margin: 12px 2px 0;
56
+ font-size: 12px;
57
+ color: var(--ink-soft);
58
+ }
59
+
60
+ .modal-actions {
61
+ display: flex;
62
+ justify-content: flex-end;
63
+ gap: 8px;
64
+ margin-top: 16px;
65
+ }
66
+
67
+ .modal-actions button {
68
+ height: 34px;
69
+ padding: 0 16px;
70
+ border: 1px solid var(--border);
71
+ border-radius: 6px;
72
+ background: var(--surface);
73
+ color: var(--ink);
74
+ font: inherit;
75
+ font-size: 13px;
76
+ cursor: pointer;
77
+ }
78
+
79
+ .modal-actions button:hover:not(:disabled) {
80
+ background: var(--accent-soft);
81
+ border-color: var(--accent);
82
+ }
83
+
84
+ /* dark ink on the accent, never white: 7.25:1 against 2.08:1 */
85
+ .modal-actions button.is-primary {
86
+ border-color: var(--accent);
87
+ background: var(--accent);
88
+ color: var(--ink);
89
+ font-weight: 600;
90
+ }
91
+
92
+ .modal-actions button.is-primary:hover:not(:disabled) {
93
+ background: var(--accent-ink);
94
+ border-color: var(--accent-ink);
95
+ color: var(--surface);
96
+ }
97
+
98
+ /**
99
+ * The button that throws something away. It stays a plain button rather than
100
+ * taking a fill: it sits beside the one that keeps the work, and two filled
101
+ * buttons in a row make the reader pick by position instead of by reading.
102
+ * The colour arrives on hover, once the pointer is already on it.
103
+ */
104
+ .modal-actions button.is-danger {
105
+ color: var(--danger);
106
+ }
107
+
108
+ .modal-actions button.is-danger:hover:not(:disabled) {
109
+ background: var(--danger-soft);
110
+ border-color: var(--danger);
111
+ }
112
+
113
+ .modal-actions button:disabled {
114
+ opacity: .5;
115
+ cursor: default;
116
+ }
117
+
118
+ .modal-actions button:focus-visible {
119
+ outline: 2px solid var(--accent-strong);
120
+ outline-offset: 2px;
121
+ }
122
+
123
+ @media print {
124
+ .modal { display: none; }
125
+ }
@@ -1,145 +1,145 @@
1
- /**
2
- * store.js is the browser's half of reading and writing report files.
3
- *
4
- * Four fetches against the four routes in src/server/routes.js. It knows
5
- * nothing about who answers them - the CLI's http server during
6
- * `npx report-studio design`, or the Vite plugin for a project already running
7
- * Vite. That is the whole point of the seam: the designer talks to URLs, and
8
- * swapping what serves them changes nothing here.
9
- *
10
- * Every failure is turned into an Error carrying what the server actually said,
11
- * because "failed to fetch" in a toast is how a user concludes the tool is
12
- * broken when the real answer was "there is no report called invoice".
13
- */
14
-
15
- import { DEFAULT_PREFIX } from './prefix.js';
16
-
17
-
18
- /**
19
- * @param {object} [options]
20
- * @param {string} [options.prefix] where the routes are mounted
21
- * @param {typeof fetch} [options.fetch] injectable, so the specs need no server
22
- * @returns {object} list, load, save, remove
23
- */
24
- export function createStore({
25
- prefix = DEFAULT_PREFIX,
26
- fetch: doFetch = (...args) => globalThis.fetch(...args)
27
- } = {}) {
28
-
29
- async function call(path, init) {
30
- let response;
31
-
32
- try {
33
- response = await doFetch(`${prefix}${path}`, init);
34
- } catch (cause) {
35
- /**
36
- * The routes only exist while a dev server is running. Someone who
37
- * opened the designer as a plain file, or built it into their own
38
- * page, gets this - and it should say what to do about it.
39
- */
40
- throw new StoreError(
41
- 'Cannot reach the report server. Start it with ' +
42
- '`npx report-studio design`.',
43
- { cause, offline: true }
44
- );
45
- }
46
-
47
- const body = await response.json().catch(() => null);
48
-
49
- if (!response.ok) {
50
- throw new StoreError(
51
- body?.error ?? `the server answered ${response.status}`,
52
- { status: response.status }
53
- );
54
- }
55
-
56
- return body;
57
- }
58
-
59
- return {
60
- /** @returns {Promise<object[]>} `{ id, name, updatedAt, readable }` */
61
- async list() {
62
- const body = await call('', { method: 'GET' });
63
- return Array.isArray(body?.reports) ? body.reports : [];
64
- },
65
-
66
- /** @returns {Promise<object>} the layout */
67
- load(id) {
68
- return call(`/${encodeURIComponent(id)}`, { method: 'GET' });
69
- },
70
-
71
- /** @returns {Promise<object>} `{ id, name, updatedAt }` */
72
- save(id, layout) {
73
- return call(`/${encodeURIComponent(id)}`, {
74
- method: 'PUT',
75
- headers: { 'Content-Type': 'application/json' },
76
- body: JSON.stringify(layout)
77
- });
78
- },
79
-
80
- remove(id) {
81
- return call(`/${encodeURIComponent(id)}`, { method: 'DELETE' });
82
- },
83
-
84
- /**
85
- * The report's data payload, kept beside it as `<id>.data.json`.
86
- *
87
- * @returns {Promise<object|null>} null when there is not one yet, which
88
- * is an ordinary state for a report nobody has supplied data for -
89
- * not a failure to report to the user
90
- */
91
- async loadData(id) {
92
- try {
93
- return await call(`/${encodeURIComponent(id)}/data`, { method: 'GET' });
94
- } catch (error) {
95
- if (error.status === 404) return null;
96
- throw error;
97
- }
98
- },
99
-
100
- saveData(id, data) {
101
- return call(`/${encodeURIComponent(id)}/data`, {
102
- method: 'PUT',
103
- headers: { 'Content-Type': 'application/json' },
104
- body: JSON.stringify(data, null, 2)
105
- });
106
- }
107
- };
108
- }
109
-
110
-
111
- /** carries the server's own words, and whether there was a server at all */
112
- export class StoreError extends Error {
113
- constructor(message, { cause, status = null, offline = false } = {}) {
114
- super(message, { cause });
115
-
116
- this.name = 'StoreError';
117
- this.status = status;
118
- this.offline = offline;
119
- }
120
- }
121
-
122
-
123
- /**
124
- * The id a report name would be saved as.
125
- *
126
- * The filename is the id (see routes.js), and routes.js accepts letters,
127
- * digits, dashes and underscores - so a name has to be reduced to that before
128
- * it can become one. Done here rather than on the server so the designer can
129
- * show what the file will be called before anything is written.
130
- *
131
- * @param {string} name
132
- * @returns {string} a usable id, or '' when nothing usable is left
133
- */
134
- export function toId(name) {
135
- const slug = String(name ?? '')
136
- .trim()
137
- .toLowerCase()
138
- .replace(/[^a-z0-9]+/g, '-')
139
- .replace(/^-+|-+$/g, '')
140
- .slice(0, 64)
141
- .replace(/-+$/, '');
142
-
143
- /** routes.js requires the first character to be a letter or digit */
144
- return /^[a-z0-9]/.test(slug) ? slug : '';
145
- }
1
+ /**
2
+ * store.js is the browser's half of reading and writing report files.
3
+ *
4
+ * Four fetches against the four routes in src/server/routes.js. It knows
5
+ * nothing about who answers them - the CLI's http server during
6
+ * `npx report-studio design`, or the Vite plugin for a project already running
7
+ * Vite. That is the whole point of the seam: the designer talks to URLs, and
8
+ * swapping what serves them changes nothing here.
9
+ *
10
+ * Every failure is turned into an Error carrying what the server actually said,
11
+ * because "failed to fetch" in a toast is how a user concludes the tool is
12
+ * broken when the real answer was "there is no report called invoice".
13
+ */
14
+
15
+ import { DEFAULT_PREFIX } from './prefix.js';
16
+
17
+
18
+ /**
19
+ * @param {object} [options]
20
+ * @param {string} [options.prefix] where the routes are mounted
21
+ * @param {typeof fetch} [options.fetch] injectable, so the specs need no server
22
+ * @returns {object} list, load, save, remove
23
+ */
24
+ export function createStore({
25
+ prefix = DEFAULT_PREFIX,
26
+ fetch: doFetch = (...args) => globalThis.fetch(...args)
27
+ } = {}) {
28
+
29
+ async function call(path, init) {
30
+ let response;
31
+
32
+ try {
33
+ response = await doFetch(`${prefix}${path}`, init);
34
+ } catch (cause) {
35
+ /**
36
+ * The routes only exist while a dev server is running. Someone who
37
+ * opened the designer as a plain file, or built it into their own
38
+ * page, gets this - and it should say what to do about it.
39
+ */
40
+ throw new StoreError(
41
+ 'Cannot reach the report server. Start it with ' +
42
+ '`npx report-studio design`.',
43
+ { cause, offline: true }
44
+ );
45
+ }
46
+
47
+ const body = await response.json().catch(() => null);
48
+
49
+ if (!response.ok) {
50
+ throw new StoreError(
51
+ body?.error ?? `the server answered ${response.status}`,
52
+ { status: response.status }
53
+ );
54
+ }
55
+
56
+ return body;
57
+ }
58
+
59
+ return {
60
+ /** @returns {Promise<object[]>} `{ id, name, updatedAt, readable }` */
61
+ async list() {
62
+ const body = await call('', { method: 'GET' });
63
+ return Array.isArray(body?.reports) ? body.reports : [];
64
+ },
65
+
66
+ /** @returns {Promise<object>} the layout */
67
+ load(id) {
68
+ return call(`/${encodeURIComponent(id)}`, { method: 'GET' });
69
+ },
70
+
71
+ /** @returns {Promise<object>} `{ id, name, updatedAt }` */
72
+ save(id, layout) {
73
+ return call(`/${encodeURIComponent(id)}`, {
74
+ method: 'PUT',
75
+ headers: { 'Content-Type': 'application/json' },
76
+ body: JSON.stringify(layout)
77
+ });
78
+ },
79
+
80
+ remove(id) {
81
+ return call(`/${encodeURIComponent(id)}`, { method: 'DELETE' });
82
+ },
83
+
84
+ /**
85
+ * The report's data payload, kept beside it as `<id>.data.json`.
86
+ *
87
+ * @returns {Promise<object|null>} null when there is not one yet, which
88
+ * is an ordinary state for a report nobody has supplied data for -
89
+ * not a failure to report to the user
90
+ */
91
+ async loadData(id) {
92
+ try {
93
+ return await call(`/${encodeURIComponent(id)}/data`, { method: 'GET' });
94
+ } catch (error) {
95
+ if (error.status === 404) return null;
96
+ throw error;
97
+ }
98
+ },
99
+
100
+ saveData(id, data) {
101
+ return call(`/${encodeURIComponent(id)}/data`, {
102
+ method: 'PUT',
103
+ headers: { 'Content-Type': 'application/json' },
104
+ body: JSON.stringify(data, null, 2)
105
+ });
106
+ }
107
+ };
108
+ }
109
+
110
+
111
+ /** carries the server's own words, and whether there was a server at all */
112
+ export class StoreError extends Error {
113
+ constructor(message, { cause, status = null, offline = false } = {}) {
114
+ super(message, { cause });
115
+
116
+ this.name = 'StoreError';
117
+ this.status = status;
118
+ this.offline = offline;
119
+ }
120
+ }
121
+
122
+
123
+ /**
124
+ * The id a report name would be saved as.
125
+ *
126
+ * The filename is the id (see routes.js), and routes.js accepts letters,
127
+ * digits, dashes and underscores - so a name has to be reduced to that before
128
+ * it can become one. Done here rather than on the server so the designer can
129
+ * show what the file will be called before anything is written.
130
+ *
131
+ * @param {string} name
132
+ * @returns {string} a usable id, or '' when nothing usable is left
133
+ */
134
+ export function toId(name) {
135
+ const slug = String(name ?? '')
136
+ .trim()
137
+ .toLowerCase()
138
+ .replace(/[^a-z0-9]+/g, '-')
139
+ .replace(/^-+|-+$/g, '')
140
+ .slice(0, 64)
141
+ .replace(/-+$/, '');
142
+
143
+ /** routes.js requires the first character to be a letter or digit */
144
+ return /^[a-z0-9]/.test(slug) ? slug : '';
145
+ }