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
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Mohammed Shafick A
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohammed Shafick A
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,7 +8,7 @@ that layout its own data and gets back a page-by-page report viewer, with
8
8
  navigation, zoom, search, print and CSV export.
9
9
 
10
10
  No framework, no runtime dependencies. The renderer is plain DOM, so it works
11
- in any project: plain JS.
11
+ in any project: plain JS, or React through the included components.
12
12
 
13
13
  ## Installation
14
14
 
@@ -54,9 +54,11 @@ report asks for: a key for every text placeholder, a row array for every table,
54
54
  and the fields your totals are taken over. Read it as the answer to "what does
55
55
  my app have to supply?" — it is the shape, filled in with placeholder values.
56
56
 
57
- It is only written the first time a report is saved. Once you have put real
58
- figures in it, later saves leave it alone. Your app never reads this file; it
59
- passes its own data to `buildPages`.
57
+ It is created the first time a report is saved. Later saves only *add* to it,
58
+ for anything the layout has asked for since: a new table's rows, a new
59
+ placeholder's key, a new image field. Values already in the file, including
60
+ real figures you have typed in, are never changed. Your app never reads this
61
+ file; it passes its own data to `buildPages`.
60
62
 
61
63
  The designer is a design-time tool. It reads and writes files inside `--dir`
62
64
  and nowhere else — keep it on localhost and do not run it in production.
@@ -142,6 +144,70 @@ To open the report in a window of its own instead of inside your page, use
142
144
  `openViewerWindow({ paginated, title })` — same viewer, called from a click or
143
145
  a keypress so the browser does not block the window.
144
146
 
147
+ ### Several tables
148
+
149
+ A report can hold any number of tables. Each one reads the dataset named in
150
+ its *Dataset* property, or the report's dataset if it names none, so each gets
151
+ its own array in your data:
152
+
153
+ ```js
154
+ buildPages(layout, {
155
+ orders: [ { item: 'Widget', qty: 2, amount: 50 } ],
156
+ refunds: [ { item: 'Gadget', qty: 1, amount: 20 } ]
157
+ });
158
+ ```
159
+
160
+ Tables in the same band are stacked, one under another. Each splits across
161
+ pages on its own, and a table below another moves down by however far the one
162
+ above really ran. Two tables side by side are refused, because they would print
163
+ one after the other rather than together.
164
+
165
+ Totals can name the dataset they add up:
166
+
167
+ | Placeholder | Means |
168
+ | --- | --- |
169
+ | `{sum(orders.amount)}` | `amount` summed over every row of `orders` |
170
+ | `{count(refunds)}` | the number of rows in `refunds` |
171
+ | `{sum(amount)}` | `amount` over the first table's rows, as before |
172
+
173
+ The named dataset does not need a table of its own. Any array in the data can
174
+ be totalled this way.
175
+
176
+ One table per report can be grouped. Set *Group by* on that table. A layout
177
+ with a report-wide *Group by* still groups its first table. The group header
178
+ and footer bands are shared, which is why only one table can use them.
179
+
180
+ For CSV, the viewer's export writes every table in the order they print. From
181
+ code, `toCSV(pages, { table: 'refunds' })` writes one table, and
182
+ `reportTables(pages)` lists the tables a report has.
183
+
184
+ ### Images
185
+
186
+ An image item can get its picture in two ways:
187
+
188
+ * **Stored in the layout.** In the designer, click *Upload* in the image's
189
+ properties. The picture is saved inside the layout JSON as a `data:` URI, so
190
+ keep it small: files over 200 KB show a warning and files over 1 MB are
191
+ refused. PNG, JPEG, GIF and WebP are accepted.
192
+ * **Read from your data.** Set *From data* to a path such as `company.logo`,
193
+ and supply that path's URL in the data you pass to `buildPages`:
194
+
195
+ ```js
196
+ buildPages(layout, {
197
+ company: { logo: 'https://cdn.example.com/acme.png' },
198
+ sales: [ /* ... */ ]
199
+ });
200
+ ```
201
+
202
+ If an image has both, the data wins, so a stored picture works as a default
203
+ that your data can replace per customer. *Fit* controls how the picture sits in
204
+ its box: `contain` (fit inside), `cover` (fill and crop) or `fill` (stretch).
205
+
206
+ Image URLs may be `http:`, `https:`, `blob:`, relative paths, or `data:` URIs
207
+ for PNG, JPEG, GIF, WebP, AVIF and BMP. Anything else, including `javascript:`
208
+ and SVG `data:` URIs, is not drawn. Remote images must be reachable from the
209
+ viewer's page. The viewer waits for images to finish loading before it prints.
210
+
145
211
  ### With a bundler
146
212
 
147
213
  Vite, webpack and the rest resolve bare names themselves, so there is no import
@@ -160,6 +226,65 @@ import 'report-studio/viewer.css';
160
226
  | `report-studio/designer.css` | the designer's styles, likewise |
161
227
  | `report-studio/report.css` | the report alone, for drawing pages with no chrome |
162
228
 
229
+ ## React
230
+
231
+ React components are included. React itself is not bundled: install it
232
+ yourself (version 18 or newer). Apps that don't use React never load it.
233
+
234
+ ```jsx
235
+ import { ReportViewer } from 'report-studio/react';
236
+ import 'report-studio/viewer.css';
237
+
238
+ function SalesReport({ layout, sales }) {
239
+ return (
240
+ <ReportViewer
241
+ layout={layout}
242
+ data={{ report: { period: 'June 2026' }, sales }}
243
+ title={layout.name}
244
+ style={{ height: '100vh' }}
245
+ />
246
+ );
247
+ }
248
+ ```
249
+
250
+ * Pass `layout` and `data`, or `paginated` if you've already called
251
+ `buildPages`.
252
+ * Give the component a height. The viewer fills it and scrolls inside it.
253
+ * When `data` changes, the report is rebuilt and the reader stays on the same
254
+ page and zoom level. Passing the same objects again rebuilds nothing, so keep
255
+ `data` stable (state or `useMemo`) rather than building a new object on every
256
+ render.
257
+ * A layout or data the engine can't use throws a `ReportError` while
258
+ rendering. Wrap the component in an error boundary to show it.
259
+ * A `ref` gives you the viewer's controls: `next()`, `prev()`, `show(index)`,
260
+ `find(text)`, `print()`, `downloadCSV()`, `setZoom(n)`, `fitWidth()`, and
261
+ `page`, `pageCount` and `zoom`.
262
+
263
+ The designer is a separate import, like the plain-JS one:
264
+
265
+ ```jsx
266
+ import { ReportDesigner } from 'report-studio/react/designer';
267
+ import 'report-studio/designer.css';
268
+
269
+ // a new report: no layout, the designer starts blank
270
+ <ReportDesigner store={store} style={{ height: '100vh' }} />
271
+
272
+ // reopening a saved report: pass it, with its id so Save writes back to it
273
+ <ReportDesigner id="sales-summary" layout={savedLayout} store={store}
274
+ style={{ height: '100vh' }} />
275
+ ```
276
+
277
+ `layout` and `id` are optional. Leave both out for a new report, and Save asks
278
+ for a name the first time.
279
+
280
+ `layout` is only where the designer *starts*, like an input's `defaultValue`.
281
+ From then on the designer owns it, so edits, selection and undo history
282
+ survive your component re-rendering. `onChange` is called after every edit,
283
+ undo and redo. It receives the designer's own object, so clone it before
284
+ storing it. To open a different report, change `id` (or the component's
285
+ `key`). `store` works as described under *Designing inside your own app*.
286
+ `createDesigner` also takes the same `onChange` option.
287
+
163
288
  ## Designing inside your own app
164
289
 
165
290
  The command above is the usual way in, and it is a whole application. If you