report-studio 1.1.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.
package/README.md CHANGED
@@ -1,14 +1,22 @@
1
1
  # Report Studio
2
2
 
3
- Design paginated reports in the browser, then render them inside your own app.
3
+ **Design paginated reports visually. Zero runtime dependencies. Works in plain
4
+ JS or React.**
4
5
 
5
- You draw the report once in a visual designer — headers, footers, groups,
6
- tables, text — and it is saved as a plain JSON file. At runtime your app feeds
7
- that layout its own data and gets back a page-by-page report viewer, with
8
- navigation, zoom, search, print and CSV export.
6
+ ![Adding a text box in the designer, saving, and running the report](https://raw.githubusercontent.com/Shafickbinameer/report-studio/main/.github/demo.gif)
9
7
 
10
- No framework, no runtime dependencies. The renderer is plain DOM, so it works
11
- in any project: plain JS, or React through the included components.
8
+ You draw the report once in a visual designer — headers, footers, groups,
9
+ tables, text, images — and it is saved as a plain JSON file. At runtime your
10
+ app feeds that layout its own data and gets back a page-by-page report viewer,
11
+ with navigation, zoom, search, print and CSV export.
12
+
13
+ * **Zero runtime dependencies.** The renderer is plain DOM. No server to run,
14
+ no framework required.
15
+ * **Layouts are plain JSON.** Commit them, diff them, load them with `fetch`.
16
+ * **React components included**, for both the viewer and the designer.
17
+ * **Vite plugin.** One line in `vite.config.js` and your existing dev server
18
+ hosts the designer's save routes.
19
+ * **TypeScript types included.**
12
20
 
13
21
  ## Installation
14
22
 
@@ -63,6 +71,24 @@ file; it passes its own data to `buildPages`.
63
71
  The designer is a design-time tool. It reads and writes files inside `--dir`
64
72
  and nowhere else — keep it on localhost and do not run it in production.
65
73
 
74
+ ### Already using Vite?
75
+
76
+ Skip the separate command. The plugin mounts the same read-and-write routes in
77
+ the dev server you already run:
78
+
79
+ ```js
80
+ import { defineConfig } from 'vite';
81
+ import { reportStudio } from 'report-studio/vite';
82
+
83
+ export default defineConfig({
84
+ plugins: [reportStudio({ dir: 'reports' })]
85
+ });
86
+ ```
87
+
88
+ Dev only, deliberately: it writes files, and mounting that in front of a
89
+ production build would be a hole rather than a feature. The CLI stays the
90
+ default because it works in any project, Vite or not.
91
+
66
92
  ## Preview setup
67
93
 
68
94
  Two files: an HTML page with one empty element, and a module that fills it.
@@ -340,23 +366,21 @@ file yet: that is an ordinary state, not a failure.
340
366
  `destroy()`. `openDesignerWindow(options)` opens the same designer in a window
341
367
  of its own, for the same reason `openViewerWindow` does.
342
368
 
343
- ## Reports in a project that already runs Vite
369
+ ## TypeScript
344
370
 
345
- The CLI is the primary way in because it works for any project. If yours is
346
- already a Vite one, the same read-and-write routes can be mounted in the dev
347
- server you have:
371
+ Type declarations ship with the package, for every entry point. Nothing to
372
+ install. The layout file has types of its own, so a layout loaded from JSON can
373
+ be checked:
348
374
 
349
- ```js
350
- import { defineConfig } from 'vite';
351
- import { reportStudio } from 'report-studio/vite';
375
+ ```ts
376
+ import { buildPages, createViewer, type Layout } from 'report-studio';
352
377
 
353
- export default defineConfig({
354
- plugins: [reportStudio({ dir: 'reports' })]
355
- });
378
+ const layout: Layout = await fetch('./reports/sales-summary.json')
379
+ .then(r => r.json());
356
380
  ```
357
381
 
358
- Dev only, deliberately: it writes files, and mounting that in front of a
359
- production build would be a hole rather than a feature.
382
+ `Layout`, `ReportItem`, `PaginatedReport`, `ViewerHandle`, `ReportStore`,
383
+ `DesignerHandle` and the component props are all exported as types.
360
384
 
361
385
  ## Licence
362
386
 
package/package.json CHANGED
@@ -1,25 +1,35 @@
1
1
  {
2
2
  "name": "report-studio",
3
- "version": "1.1.0",
4
- "description": "Design and preview paginated reports in the browser. Zero runtime dependencies; optional React components.",
3
+ "version": "1.2.0",
4
+ "description": "Visual report designer and paginated report viewer for the browser. Zero runtime dependencies; plain JS, React components and a Vite plugin.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Shafickbinameer/report-studio.git"
8
8
  },
9
9
  "keywords": [
10
10
  "report",
11
+ "report-designer",
12
+ "report-builder",
13
+ "report-viewer",
11
14
  "designer",
15
+ "paginated",
12
16
  "pagination",
13
17
  "pdf",
14
18
  "print",
15
19
  "layout",
16
- "react"
20
+ "viewer",
21
+ "zero-dependency",
22
+ "react",
23
+ "vite-plugin",
24
+ "typescript"
17
25
  ],
18
26
  "author": "Mohammed Shafick <shafickbinameer@gmail.com>",
19
27
  "license": "MIT",
20
28
  "type": "module",
29
+ "types": "./types/index.d.ts",
21
30
  "files": [
22
31
  "dist",
32
+ "types",
23
33
  "src/asset",
24
34
  "src/cli",
25
35
  "src/designer",
@@ -34,11 +44,26 @@
34
44
  "src/index.js"
35
45
  ],
36
46
  "exports": {
37
- ".": "./dist/index.js",
38
- "./designer": "./dist/designer.js",
39
- "./react": "./dist/react.js",
40
- "./react/designer": "./dist/react-designer.js",
41
- "./vite": "./src/vite/index.js",
47
+ ".": {
48
+ "types": "./types/index.d.ts",
49
+ "default": "./dist/index.js"
50
+ },
51
+ "./designer": {
52
+ "types": "./types/designer.d.ts",
53
+ "default": "./dist/designer.js"
54
+ },
55
+ "./react": {
56
+ "types": "./types/react.d.ts",
57
+ "default": "./dist/react.js"
58
+ },
59
+ "./react/designer": {
60
+ "types": "./types/react-designer.d.ts",
61
+ "default": "./dist/react-designer.js"
62
+ },
63
+ "./vite": {
64
+ "types": "./types/vite.d.ts",
65
+ "default": "./src/vite/index.js"
66
+ },
42
67
  "./report.css": "./src/render/report.css",
43
68
  "./viewer.css": "./src/preview/styles.css",
44
69
  "./designer.css": "./src/designer/styles.css",
@@ -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;
@@ -0,0 +1,204 @@
1
+ /**
2
+ * report-studio - the engine and the viewer.
3
+ */
4
+
5
+ import type {
6
+ Band, BandType, Layout, PaginatedReport, Page, ReportData, TableItem, TextStyle
7
+ } from './layout.js';
8
+
9
+ export type * from './layout.js';
10
+
11
+
12
+ /* ---------------------------------------------------------------- engine */
13
+
14
+ /**
15
+ * Turns a layout file plus your data into a page list.
16
+ * @throws {ReportError} when the layout or data cannot be used
17
+ */
18
+ export function buildPages(layout: Layout, data: ReportData): PaginatedReport;
19
+
20
+ /** stage 1 of buildPages: fills in placeholders from the data */
21
+ export function resolve(layout: Layout, data: ReportData): Layout;
22
+ /** stage 2: splits the grouped table's rows into groups */
23
+ export function group(resolved: Layout, data: ReportData): Layout;
24
+ /** stage 3: measures text and table rows */
25
+ export function measure(grouped: Layout): Layout;
26
+ /** stage 4: breaks the measured report into pages */
27
+ export function paginate(measured: Layout): PaginatedReport;
28
+
29
+ /**
30
+ * Everything wrong with a layout, as readable messages.
31
+ * @returns an empty array when the layout is usable
32
+ */
33
+ export function validateLayout(layout: unknown): string[];
34
+
35
+ /** thrown for a layout or data the engine cannot work with */
36
+ export class ReportError extends Error {
37
+ constructor(message: string, issues?: string[]);
38
+ name: 'ReportError';
39
+ issues: string[];
40
+ }
41
+
42
+ export interface SearchOptions {
43
+ caseSensitive?: boolean;
44
+ }
45
+
46
+ export interface SearchMatch {
47
+ pageNO: number;
48
+ bandType: BandType;
49
+ itemId: string;
50
+ /** the table column it was found in; null for a text item */
51
+ field: string | null;
52
+ text: string;
53
+ start: number;
54
+ end: number;
55
+ }
56
+
57
+ /** every occurrence of `query` in a built report, in page order */
58
+ export function search(pages: Page[], query: string, options?: SearchOptions): SearchMatch[];
59
+
60
+ /** the distinct page numbers a query appears on, in order */
61
+ export function searchPages(pages: Page[], query: string, options?: SearchOptions): number[];
62
+
63
+ export interface PageRegionsOptions {
64
+ bands: Partial<Record<BandType, Band>>;
65
+ contentHeight: number;
66
+ isFirstPage: boolean;
67
+ isLastPage: boolean;
68
+ }
69
+
70
+ export function pageRegions(options: PageRegionsOptions): Record<string, unknown>;
71
+ export function bandZoneHeight(band: Band | null, contentHeight: number): number;
72
+ export function resolveHeight(
73
+ value: number | string | undefined,
74
+ contentHeight: number,
75
+ fallback?: number | string
76
+ ): number;
77
+ export const DEFAULT_BAND_HEIGHTS: Readonly<Record<string, string>>;
78
+
79
+ export interface CSVOptions {
80
+ /** the id of the table to write; the first when absent */
81
+ table?: string;
82
+ /** default `','`; use `';'` where Excel expects it */
83
+ delimiter?: string;
84
+ /** default `'\r\n'` */
85
+ newline?: string;
86
+ /** emit the column labels as the first row; default true */
87
+ header?: boolean;
88
+ /** prepend the group key on a grouped table; default true */
89
+ groupColumn?: boolean;
90
+ /** default `'Group'` */
91
+ groupLabel?: string;
92
+ /** stop cells starting `=`, `+`, `-` or `@` running as formulas; default true */
93
+ neutraliseFormulas?: boolean;
94
+ }
95
+
96
+ export type ReportCSVOptions = Pick<CSVOptions, 'delimiter' | 'newline' | 'neutraliseFormulas'>;
97
+
98
+ /** one table's rows as CSV text; empty when there is no such table */
99
+ export function toCSV(pages: Page[], options?: CSVOptions): string;
100
+
101
+ /** the whole report as CSV, one row per line in the order it is read */
102
+ export function toReportCSV(pages: Page[], options?: ReportCSVOptions): string;
103
+
104
+ /** a download filename from the report's name */
105
+ export function reportFilename(paginated: { name?: string }, extension?: string): string;
106
+
107
+ /** the tables a built report holds, in the order they first appear */
108
+ export function reportTables(pages: Page[]): Array<{ id: string; columns: string[] }>;
109
+
110
+ /** every table item in a layout, in the order they are drawn */
111
+ export function tablesOf(layout: Layout): TableItem[];
112
+
113
+ /** the dataset a table reads: its own, or the layout's */
114
+ export function datasetOf(table: TableItem, layout: Layout): string | null;
115
+
116
+ /** the grouped table and its field, or null when nothing is grouped */
117
+ export function groupingOf(layout: Layout): { table: TableItem; by: string } | null;
118
+
119
+ /** width of one line of text, in pixels */
120
+ export function measureText(text: string, style?: TextStyle): number;
121
+
122
+ /** greedy word wrap to `width` pixels */
123
+ export function wrapLines(text: string, width: number, style?: TextStyle): string[];
124
+
125
+ /** rendered height of wrapped text, in pixels */
126
+ export function textHeight(text: string, width: number, style?: TextStyle): number;
127
+
128
+ /** CSS line-height multiplier the report draws text at */
129
+ export const LINE_HEIGHT_RATIO: number;
130
+
131
+
132
+ /* ---------------------------------------------------------------- render */
133
+
134
+ /** a built report as HTML markup, with no viewer around it */
135
+ export function render(paginated: PaginatedReport): string;
136
+
137
+
138
+ /* ---------------------------------------------------------------- viewer */
139
+
140
+ export interface ViewerOptions {
141
+ /** the element to take over, or a selector for it */
142
+ mount: Element | string;
143
+ /** a buildPages result */
144
+ paginated: PaginatedReport;
145
+ /** shown in the viewer's toolbar */
146
+ title?: string;
147
+ }
148
+
149
+ export interface ViewerHandle {
150
+ /** go to a page, 0-based */
151
+ show(index: number): void;
152
+ next(): void;
153
+ prev(): void;
154
+ find(query: string): void;
155
+ print(): void;
156
+ /** false when the report has nothing to write */
157
+ downloadCSV(): boolean;
158
+ openExport(): void;
159
+ closeExport(): void;
160
+ confirmExport(): void;
161
+ setZoom(zoom: number): void;
162
+ zoomIn(): void;
163
+ zoomOut(): void;
164
+ fitWidth(): void;
165
+ destroy(): void;
166
+ /** the current page, 1-based */
167
+ readonly page: number;
168
+ readonly pageCount: number;
169
+ readonly zoom: number;
170
+ readonly exportOpen: boolean;
171
+ }
172
+
173
+ export interface WindowOptions {
174
+ width?: number;
175
+ height?: number;
176
+ /** passed to window.open as given */
177
+ features?: string;
178
+ }
179
+
180
+ /** mounts the report viewer into an element */
181
+ export function createViewer(options: ViewerOptions): ViewerHandle;
182
+
183
+ /**
184
+ * Opens the viewer in a window of its own. Call it from a click or a keypress.
185
+ * @returns null when the browser blocked the window
186
+ */
187
+ export function openViewerWindow(
188
+ options: Omit<ViewerOptions, 'mount'> & WindowOptions
189
+ ): (ViewerHandle & { window: Window }) | null;
190
+
191
+ export interface OpenedWindow {
192
+ window: Window;
193
+ document: Document;
194
+ mount: Element;
195
+ close(): void;
196
+ }
197
+
198
+ /**
199
+ * Opens a blank window carrying this page's stylesheets, ready to mount into.
200
+ * @returns null when the browser blocked the window
201
+ */
202
+ export function openWindow(
203
+ options?: WindowOptions & { title?: string; opener?: Window }
204
+ ): OpenedWindow | null;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The layout file the designer saves, and the page list buildPages makes of it.
3
+ *
4
+ * Hand-written to match src/engine/validate.js. Every object also accepts
5
+ * properties not named here, because the designer adds its own (guides, for
6
+ * one) and a layout from a newer version should still type-check.
7
+ */
8
+
9
+ export type BandType =
10
+ | 'reportHeader'
11
+ | 'pageHeader'
12
+ | 'groupHeader'
13
+ | 'detail'
14
+ | 'groupFooter'
15
+ | 'pageFooter'
16
+ | 'reportFooter';
17
+
18
+ export type ItemType = 'text' | 'table' | 'line' | 'box' | 'image';
19
+
20
+ export type Align = 'left' | 'center' | 'right';
21
+
22
+ export type LineStyle = 'solid' | 'dashed' | 'dotted' | 'double';
23
+
24
+ /** a table's grid and a box's border may also be turned off */
25
+ export type RuleStyle = LineStyle | 'none';
26
+
27
+ export type ImageFit = 'contain' | 'cover' | 'fill';
28
+
29
+ export interface Margin {
30
+ top: number;
31
+ right: number;
32
+ bottom: number;
33
+ left: number;
34
+ }
35
+
36
+ /** sizes in CSS pixels; A4 at 96dpi is 794 x 1123 */
37
+ export interface PageSetup {
38
+ width: number;
39
+ height: number;
40
+ margin: Margin;
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ export interface TextStyle {
45
+ fontFamily?: string;
46
+ fontSize?: number;
47
+ fontWeight?: string;
48
+ fontStyle?: string;
49
+ color?: string;
50
+ align?: Align;
51
+ background?: string | null;
52
+ border?: string | null;
53
+ padding?: number;
54
+ [key: string]: unknown;
55
+ }
56
+
57
+ interface ItemBase {
58
+ id: string;
59
+ x?: number;
60
+ y?: number;
61
+ w?: number;
62
+ h?: number;
63
+ [key: string]: unknown;
64
+ }
65
+
66
+ export interface TextItem extends ItemBase {
67
+ type: 'text';
68
+ /** literal text and `{placeholders}`, such as `Total: {sum(amount)}` */
69
+ value: string;
70
+ style?: TextStyle;
71
+ }
72
+
73
+ export interface TableColumn {
74
+ /** the row property this column shows */
75
+ field: string;
76
+ label?: string;
77
+ width?: number;
78
+ align?: Align;
79
+ [key: string]: unknown;
80
+ }
81
+
82
+ export interface TableStyle extends TextStyle {
83
+ borderStyle?: RuleStyle;
84
+ borderWidth?: number;
85
+ borderColor?: string;
86
+ headerColor?: string;
87
+ headerBackground?: string;
88
+ }
89
+
90
+ export interface TableItem extends ItemBase {
91
+ type: 'table';
92
+ columns: TableColumn[];
93
+ rowHeight: number;
94
+ headerHeight?: number;
95
+ showHeader?: boolean;
96
+ /** the dataset this table reads rows from; the layout's when absent */
97
+ dataset?: string | null;
98
+ /** group this table's rows by a field. One table per report may */
99
+ groupBy?: string | null;
100
+ /** false keeps each cell to one line with an ellipsis */
101
+ wrap?: boolean;
102
+ style?: TableStyle;
103
+ }
104
+
105
+ export interface LineItem extends ItemBase {
106
+ type: 'line';
107
+ orientation?: 'horizontal' | 'vertical';
108
+ style?: {
109
+ thickness?: number;
110
+ lineStyle?: LineStyle;
111
+ color?: string;
112
+ [key: string]: unknown;
113
+ };
114
+ }
115
+
116
+ export interface BoxItem extends ItemBase {
117
+ type: 'box';
118
+ style?: {
119
+ borderStyle?: RuleStyle;
120
+ borderWidth?: number;
121
+ borderColor?: string;
122
+ radius?: number;
123
+ background?: string | null;
124
+ [key: string]: unknown;
125
+ };
126
+ }
127
+
128
+ export interface ImageItem extends ItemBase {
129
+ type: 'image';
130
+ /** a picture stored in the layout: a URL or a `data:` URI */
131
+ src?: string | null;
132
+ /** a data path, such as `company.logo`, whose value is the picture's URL */
133
+ field?: string | null;
134
+ fit?: ImageFit;
135
+ alt?: string;
136
+ }
137
+
138
+ export type ReportItem = TextItem | TableItem | LineItem | BoxItem | ImageItem;
139
+
140
+ export interface Band {
141
+ type: BandType;
142
+ /** pixels, or a percentage of the printable height such as `'10%'` */
143
+ height?: number | string;
144
+ items: ReportItem[];
145
+ [key: string]: unknown;
146
+ }
147
+
148
+ /** what the designer saves as `<name>.json` */
149
+ export interface Layout {
150
+ version?: number;
151
+ name?: string;
152
+ page: PageSetup;
153
+ /** the dataset tables read from when they name none of their own */
154
+ dataset?: string | null;
155
+ /** group the first table's rows by this field */
156
+ groupBy?: string | null;
157
+ bands: Band[];
158
+ [key: string]: unknown;
159
+ }
160
+
161
+ /**
162
+ * The host application's data, keyed by dataset name: arrays of rows for
163
+ * tables, and objects or values for text placeholders.
164
+ */
165
+ export type ReportData = Record<string, unknown>;
166
+
167
+ /** one page of a built report */
168
+ export interface Page {
169
+ /** 1-based */
170
+ pageNO: number;
171
+ bands: Array<Band & Record<string, unknown>>;
172
+ regions: Record<string, unknown>;
173
+ [key: string]: unknown;
174
+ }
175
+
176
+ /** what buildPages returns: the layout, with every page laid out */
177
+ export interface PaginatedReport extends Layout {
178
+ pages: Page[];
179
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * report-studio/react/designer - the designer as a React component.
3
+ */
4
+
5
+ import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
6
+ import type { Layout } from './layout.js';
7
+ import type { DesignerHandle, ReportStore } from './designer.js';
8
+
9
+ export type * from './layout.js';
10
+ export type { DesignerHandle, ReportStore } from './designer.js';
11
+
12
+
13
+ export interface ReportDesignerProps {
14
+ /** where the designer starts, like an input's defaultValue */
15
+ layout?: Layout;
16
+ /** the report's filename stem. Changing it opens a fresh designer */
17
+ id?: string | null;
18
+ store?: ReportStore;
19
+ /** confirm before a tab with unsaved changes closes; default true */
20
+ guardUnload?: boolean;
21
+ /** the layout after every edit. The designer's own object: clone it */
22
+ onChange?: (layout: Layout) => void;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ }
26
+
27
+ export const ReportDesigner: ForwardRefExoticComponent<
28
+ ReportDesignerProps & RefAttributes<DesignerHandle>
29
+ >;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * report-studio/react - the viewer as a React component.
3
+ */
4
+
5
+ import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
6
+ import type { Layout, PaginatedReport, ReportData } from './layout.js';
7
+ import type { ViewerHandle } from './index.js';
8
+
9
+ export type * from './layout.js';
10
+
11
+
12
+ export interface ReportViewerProps {
13
+ /** a layout the designer saved */
14
+ layout?: Layout;
15
+ /** the data for it, keyed by dataset name. Keep it stable between renders */
16
+ data?: ReportData;
17
+ /** a buildPages result, in place of layout and data */
18
+ paginated?: PaginatedReport;
19
+ title?: string;
20
+ className?: string;
21
+ /** give the viewer a height; it fills it and scrolls inside */
22
+ style?: CSSProperties;
23
+ }
24
+
25
+ /** what a ref on ReportViewer receives */
26
+ export type ReportViewerHandle = Omit<ViewerHandle, 'destroy' | 'exportOpen'>;
27
+
28
+ export const ReportViewer: ForwardRefExoticComponent<
29
+ ReportViewerProps & RefAttributes<ReportViewerHandle>
30
+ >;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * report-studio/vite - mounts the designer's file routes in a Vite dev server.
3
+ */
4
+
5
+ import type { Plugin } from 'vite';
6
+
7
+
8
+ export interface ReportStudioPluginOptions {
9
+ /** where report files live, relative to the project; default `'reports'` */
10
+ dir?: string;
11
+ /** the URL the routes are served under */
12
+ prefix?: string;
13
+ }
14
+
15
+ /** dev only: the routes write files, so they are never mounted for a build */
16
+ export function reportStudio(options?: ReportStudioPluginOptions): Plugin;
17
+
18
+ export default reportStudio;