report-studio 0.0.1 → 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.
- package/LICENSE +21 -0
- package/README.md +363 -4
- package/dist/designer-qy59eEux.js +3416 -0
- package/dist/designer.js +2 -0
- package/dist/index.js +2 -4
- package/dist/react-designer.js +41 -0
- package/dist/react.js +58 -2
- package/dist/viewer-xa17tyMJ.js +1721 -0
- package/package.json +65 -18
- package/src/asset/images/icon.png +0 -0
- package/src/asset/images/logo.png +0 -0
- package/src/cli/index.js +282 -0
- package/src/cli/serve.js +135 -0
- package/src/designer/blank.js +53 -0
- package/src/designer/canvas.js +518 -0
- package/src/designer/designer.js +2054 -0
- package/src/designer/dialog.js +708 -0
- package/src/designer/fields.js +633 -0
- package/src/designer/geometry.js +154 -0
- package/src/designer/guides.js +370 -0
- package/src/designer/history.js +113 -0
- package/src/designer/icons.js +123 -0
- package/src/designer/index.html +28 -0
- package/src/designer/main.js +39 -0
- package/src/designer/menu.js +126 -0
- package/src/designer/panel.js +498 -0
- package/src/designer/preview.js +95 -0
- package/src/designer/rulers.js +231 -0
- package/src/designer/sample-data.js +411 -0
- package/src/designer/select.js +699 -0
- package/src/designer/structure.js +685 -0
- package/src/designer/styles.css +1654 -0
- package/src/designer/toast.js +62 -0
- package/src/designer/tokens.js +293 -0
- package/src/engine/csv.js +350 -0
- package/src/engine/group.js +367 -0
- package/src/engine/index.js +35 -0
- package/src/engine/measure.js +391 -0
- package/src/engine/paginate.js +865 -0
- package/src/engine/regions.js +175 -0
- package/src/engine/resolve.js +208 -0
- package/src/engine/search.js +129 -0
- package/src/engine/tables.js +87 -0
- package/src/engine/text-metrics.js +206 -0
- package/src/engine/validate.js +403 -0
- package/src/index.html +79 -0
- package/src/index.js +51 -0
- package/src/preview/chrome.css +505 -0
- package/src/preview/chrome.js +147 -0
- package/src/preview/index.html +28 -0
- package/src/preview/main.js +66 -0
- package/src/preview/styles.css +16 -0
- package/src/preview/viewer.js +763 -0
- package/src/react/designer.js +87 -0
- package/src/react/index.js +117 -0
- package/src/render/items.js +518 -0
- package/src/render/render.js +98 -0
- package/src/render/report.css +232 -0
- package/src/server/routes.js +331 -0
- package/src/shared/brand.css +29 -0
- package/src/shared/dropdown.css +136 -0
- package/src/shared/dropdown.js +166 -0
- package/src/shared/modal.css +125 -0
- package/src/shared/prefix.js +13 -0
- package/src/shared/store.js +145 -0
- package/src/shared/theme.css +72 -0
- package/src/shared/window.js +138 -0
- package/src/vite/index.js +53 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* report-studio/react/designer - the designer as a React component.
|
|
3
|
+
*
|
|
4
|
+
* The same kind of wrapper as the viewer's: one element, and createDesigner
|
|
5
|
+
* mounted into it in an effect.
|
|
6
|
+
*
|
|
7
|
+
* The designer owns the layout while it is open. Every edit, undo and redo is
|
|
8
|
+
* made to its own copy, so the `layout` prop is where it *starts* - like an
|
|
9
|
+
* input's defaultValue - and `onChange` is how the host hears where it has got
|
|
10
|
+
* to. Remounting on every change would throw away the selection, the history
|
|
11
|
+
* and whatever the user was typing. To open a different report, change `id`
|
|
12
|
+
* (or the component's `key`), which is a different report and a fresh designer.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
createElement, forwardRef, useEffect, useImperativeHandle, useRef
|
|
17
|
+
} from 'react';
|
|
18
|
+
import { createDesigner } from '../designer/designer.js';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The report designer.
|
|
23
|
+
*
|
|
24
|
+
* Import `report-studio/designer.css` once, and give the component a height.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} props
|
|
27
|
+
* @param {object} [props.layout] the report to start from; absent starts a blank one
|
|
28
|
+
* @param {string} [props.id] the report's filename stem. Changing it opens a
|
|
29
|
+
* fresh designer on whatever `layout` is then
|
|
30
|
+
* @param {object} [props.store] where Open and Save read and write - see the
|
|
31
|
+
* README; the dev server's routes when absent
|
|
32
|
+
* @param {boolean} [props.guardUnload=true] ask before a tab with unsaved
|
|
33
|
+
* changes closes. Read once, when the designer mounts
|
|
34
|
+
* @param {(layout: object) => void} [props.onChange] the layout after every
|
|
35
|
+
* edit. The designer's own object: clone it before keeping it
|
|
36
|
+
* @param {string} [props.className]
|
|
37
|
+
* @param {object} [props.style]
|
|
38
|
+
* @param {object} ref receives the designer's handle: layout, redraw,
|
|
39
|
+
* togglePreview, select and the rest createDesigner returns
|
|
40
|
+
*/
|
|
41
|
+
export const ReportDesigner = forwardRef(function ReportDesigner(
|
|
42
|
+
{ layout, id = null, store, guardUnload = true, onChange, className, style }, ref
|
|
43
|
+
) {
|
|
44
|
+
const element = useRef(null);
|
|
45
|
+
const designer = useRef(null);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The latest of the props read at mount, so a host passing a new arrow
|
|
49
|
+
* function every render - which is most of them - gets its current callback
|
|
50
|
+
* called, without the designer being torn down to pick it up.
|
|
51
|
+
*/
|
|
52
|
+
const latest = useRef({ layout, store, guardUnload, onChange });
|
|
53
|
+
latest.current = { layout, store, guardUnload, onChange };
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!element.current) return undefined;
|
|
57
|
+
|
|
58
|
+
const mounted = createDesigner({
|
|
59
|
+
mount: element.current,
|
|
60
|
+
layout: latest.current.layout,
|
|
61
|
+
id,
|
|
62
|
+
store: latest.current.store,
|
|
63
|
+
guardUnload: latest.current.guardUnload,
|
|
64
|
+
onChange: (next) => latest.current.onChange?.(next)
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
designer.current = mounted;
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
mounted.destroy();
|
|
71
|
+
if (designer.current === mounted) designer.current = null;
|
|
72
|
+
};
|
|
73
|
+
}, [id]);
|
|
74
|
+
|
|
75
|
+
/** forwards to whichever designer is mounted, like the viewer's ref */
|
|
76
|
+
useImperativeHandle(ref, () => new Proxy({}, {
|
|
77
|
+
get(_, name) {
|
|
78
|
+
const current = designer.current;
|
|
79
|
+
if (!current) return undefined;
|
|
80
|
+
|
|
81
|
+
const value = current[name];
|
|
82
|
+
return typeof value === 'function' ? value.bind(current) : value;
|
|
83
|
+
}
|
|
84
|
+
}), []);
|
|
85
|
+
|
|
86
|
+
return createElement('div', { ref: element, className, style });
|
|
87
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* report-studio/react - the viewer as a React component.
|
|
3
|
+
*
|
|
4
|
+
* A wrapper and nothing more. The viewer is plain DOM and builds everything
|
|
5
|
+
* inside one element, so the component renders that element and hands it to
|
|
6
|
+
* createViewer in an effect - the same two steps a plain-JS host takes. None of
|
|
7
|
+
* the engine or the viewer knows React is here, which is what keeps the rest of
|
|
8
|
+
* the package usable without it (see framework-free.test.js).
|
|
9
|
+
*
|
|
10
|
+
* Written with createElement rather than JSX, so the package ships as it is
|
|
11
|
+
* built and asks no JSX transform of the host.
|
|
12
|
+
*
|
|
13
|
+
* The designer is a separate entry, `report-studio/react/designer`, for the
|
|
14
|
+
* reason the core package gives: most applications ship reports, not the tool
|
|
15
|
+
* that drew them.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
createElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef
|
|
20
|
+
} from 'react';
|
|
21
|
+
import { buildPages } from '../engine/index.js';
|
|
22
|
+
import { createViewer } from '../preview/viewer.js';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/** the viewer's methods, forwarded from the ref to whichever viewer is mounted */
|
|
26
|
+
const VIEWER_METHODS = [
|
|
27
|
+
'show', 'next', 'prev', 'find', 'print', 'downloadCSV',
|
|
28
|
+
'openExport', 'closeExport', 'confirmExport',
|
|
29
|
+
'setZoom', 'zoomIn', 'zoomOut', 'fitWidth'
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The report viewer: paging, zoom, search, print and CSV.
|
|
35
|
+
*
|
|
36
|
+
* Give it a layout and data, or pages already built with buildPages. New data
|
|
37
|
+
* builds new pages and remounts the viewer inside the same element, keeping the
|
|
38
|
+
* page and the zoom the reader was on - a report refreshed under someone should
|
|
39
|
+
* not throw them back to page one at 100%.
|
|
40
|
+
*
|
|
41
|
+
* A layout or data the engine cannot use throws while rendering, as a ReportError,
|
|
42
|
+
* so an error boundary around the component is where a host shows it.
|
|
43
|
+
*
|
|
44
|
+
* Import `report-studio/viewer.css` once, and give the component a height: the
|
|
45
|
+
* viewer fills its element and scrolls inside it.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} props
|
|
48
|
+
* @param {object} [props.layout] a layout the designer saved
|
|
49
|
+
* @param {object} [props.data] the data for it, keyed by dataset name
|
|
50
|
+
* @param {object} [props.paginated] a buildPages result, in place of layout and data
|
|
51
|
+
* @param {string} [props.title] shown in the viewer's toolbar
|
|
52
|
+
* @param {string} [props.className]
|
|
53
|
+
* @param {object} [props.style]
|
|
54
|
+
* @param {object} ref receives the viewer's controls: show, next, prev, find,
|
|
55
|
+
* print, downloadCSV, setZoom, zoomIn, zoomOut, fitWidth, and page, pageCount
|
|
56
|
+
* and zoom
|
|
57
|
+
*/
|
|
58
|
+
export const ReportViewer = forwardRef(function ReportViewer(
|
|
59
|
+
{ layout, data, paginated, title, className, style }, ref
|
|
60
|
+
) {
|
|
61
|
+
const element = useRef(null);
|
|
62
|
+
const viewer = useRef(null);
|
|
63
|
+
|
|
64
|
+
/** where the reader was, carried across a remount */
|
|
65
|
+
const place = useRef(null);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Built during render rather than in the effect, so a layout the engine
|
|
69
|
+
* refuses throws where an error boundary can catch it. Memoised on the
|
|
70
|
+
* objects themselves: a host that passes the same layout and data gets the
|
|
71
|
+
* same pages, and nothing is rebuilt.
|
|
72
|
+
*/
|
|
73
|
+
const pages = useMemo(
|
|
74
|
+
() => paginated ?? (layout ? buildPages(layout, data ?? {}) : null),
|
|
75
|
+
[paginated, layout, data]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!pages || !element.current) return undefined;
|
|
80
|
+
|
|
81
|
+
const mounted = createViewer({ mount: element.current, paginated: pages, title });
|
|
82
|
+
viewer.current = mounted;
|
|
83
|
+
|
|
84
|
+
const was = place.current;
|
|
85
|
+
if (was) {
|
|
86
|
+
mounted.setZoom(was.zoom);
|
|
87
|
+
mounted.show(Math.min(was.page, mounted.pageCount) - 1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return () => {
|
|
91
|
+
place.current = { page: mounted.page, zoom: mounted.zoom };
|
|
92
|
+
mounted.destroy();
|
|
93
|
+
if (viewer.current === mounted) viewer.current = null;
|
|
94
|
+
};
|
|
95
|
+
}, [pages, title]);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* One object for the life of the component, forwarding to whichever viewer
|
|
99
|
+
* is mounted now - so a host that kept the ref across a data refresh is not
|
|
100
|
+
* left holding a destroyed viewer.
|
|
101
|
+
*/
|
|
102
|
+
useImperativeHandle(ref, () => {
|
|
103
|
+
const handle = {
|
|
104
|
+
get page() { return viewer.current?.page ?? 0; },
|
|
105
|
+
get pageCount() { return viewer.current?.pageCount ?? 0; },
|
|
106
|
+
get zoom() { return viewer.current?.zoom ?? 1; }
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
for (const name of VIEWER_METHODS) {
|
|
110
|
+
handle[name] = (...args) => viewer.current?.[name]?.(...args);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return handle;
|
|
114
|
+
}, []);
|
|
115
|
+
|
|
116
|
+
return createElement('div', { ref: element, className, style });
|
|
117
|
+
});
|