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.
- package/LICENSE +21 -21
- package/README.md +171 -22
- package/dist/designer-qy59eEux.js +3416 -0
- package/dist/designer.js +2 -3209
- package/dist/index.js +2 -2
- package/dist/react-designer.js +41 -0
- package/dist/react.js +60 -0
- package/dist/{viewer-D-c0lKzQ.js → viewer-xa17tyMJ.js} +682 -537
- package/package.json +105 -66
- package/src/cli/serve.js +135 -135
- package/src/designer/designer.js +2054 -1900
- package/src/designer/dialog.js +708 -708
- package/src/designer/fields.js +51 -2
- package/src/designer/icons.js +5 -0
- package/src/designer/index.html +28 -28
- package/src/designer/main.js +39 -39
- package/src/designer/menu.js +2 -2
- package/src/designer/panel.js +21 -1
- package/src/designer/sample-data.js +180 -9
- package/src/designer/structure.js +87 -6
- package/src/designer/styles.css +1654 -1616
- package/src/designer/tokens.js +9 -0
- package/src/engine/csv.js +350 -315
- package/src/engine/group.js +128 -65
- package/src/engine/index.js +35 -34
- package/src/engine/measure.js +13 -12
- package/src/engine/paginate.js +8 -4
- package/src/engine/resolve.js +37 -0
- package/src/engine/tables.js +87 -0
- package/src/engine/validate.js +97 -22
- package/src/index.html +79 -79
- package/src/index.js +51 -50
- package/src/preview/chrome.css +505 -505
- package/src/preview/chrome.js +147 -147
- package/src/preview/index.html +28 -28
- package/src/preview/viewer.js +763 -745
- package/src/react/designer.js +87 -0
- package/src/react/index.js +117 -0
- package/src/render/items.js +94 -1
- package/src/render/report.css +30 -0
- package/src/server/routes.js +331 -331
- package/src/shared/brand.css +29 -29
- package/src/shared/dropdown.css +136 -136
- package/src/shared/modal.css +125 -125
- package/src/shared/store.js +145 -145
- package/src/shared/theme.css +72 -72
- package/src/shared/window.js +138 -138
- package/types/designer.d.ts +85 -0
- package/types/index.d.ts +204 -0
- package/types/layout.d.ts +179 -0
- package/types/react-designer.d.ts +29 -0
- package/types/react.d.ts +30 -0
- package/types/vite.d.ts +18 -0
package/package.json
CHANGED
|
@@ -1,66 +1,105 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "report-studio",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/Shafickbinameer/report-studio.git"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"report",
|
|
11
|
-
"designer",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "report-studio",
|
|
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
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Shafickbinameer/report-studio.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"report",
|
|
11
|
+
"report-designer",
|
|
12
|
+
"report-builder",
|
|
13
|
+
"report-viewer",
|
|
14
|
+
"designer",
|
|
15
|
+
"paginated",
|
|
16
|
+
"pagination",
|
|
17
|
+
"pdf",
|
|
18
|
+
"print",
|
|
19
|
+
"layout",
|
|
20
|
+
"viewer",
|
|
21
|
+
"zero-dependency",
|
|
22
|
+
"react",
|
|
23
|
+
"vite-plugin",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"author": "Mohammed Shafick <shafickbinameer@gmail.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"types": "./types/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"types",
|
|
33
|
+
"src/asset",
|
|
34
|
+
"src/cli",
|
|
35
|
+
"src/designer",
|
|
36
|
+
"src/engine",
|
|
37
|
+
"src/preview",
|
|
38
|
+
"src/react",
|
|
39
|
+
"src/render",
|
|
40
|
+
"src/server",
|
|
41
|
+
"src/shared",
|
|
42
|
+
"src/vite",
|
|
43
|
+
"src/index.html",
|
|
44
|
+
"src/index.js"
|
|
45
|
+
],
|
|
46
|
+
"exports": {
|
|
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
|
+
},
|
|
67
|
+
"./report.css": "./src/render/report.css",
|
|
68
|
+
"./viewer.css": "./src/preview/styles.css",
|
|
69
|
+
"./designer.css": "./src/designer/styles.css",
|
|
70
|
+
"./package.json": "./package.json"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"dev": "vite",
|
|
74
|
+
"design": "node src/cli/index.js design --dir reports",
|
|
75
|
+
"build": "vite build",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"test:watch": "vitest",
|
|
78
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
79
|
+
},
|
|
80
|
+
"bugs": {
|
|
81
|
+
"url": "https://report-studio-docs.vercel.app/report.html"
|
|
82
|
+
},
|
|
83
|
+
"homepage": "https://report-studio-docs.vercel.app",
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"react": ">=18"
|
|
86
|
+
},
|
|
87
|
+
"peerDependenciesMeta": {
|
|
88
|
+
"react": {
|
|
89
|
+
"optional": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"jsdom": "^29.1.1",
|
|
94
|
+
"react": "^19.3.0",
|
|
95
|
+
"react-dom": "^19.3.0",
|
|
96
|
+
"vite": "^8.1.5",
|
|
97
|
+
"vitest": "^4.1.11"
|
|
98
|
+
},
|
|
99
|
+
"bin": {
|
|
100
|
+
"report-studio": "./src/cli/index.js"
|
|
101
|
+
},
|
|
102
|
+
"engines": {
|
|
103
|
+
"node": ">=18.3"
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/cli/serve.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* serve.js starts the designer on a local http server.
|
|
3
|
-
*
|
|
4
|
-
* This is the primary way into the designer, and the reason it is a CLI rather
|
|
5
|
-
* than only a Vite plugin: it depends on nothing in the host project, so a
|
|
6
|
-
* plain-JS site, a webpack app, or a folder with no build tooling at all can
|
|
7
|
-
* run `npx report-studio design` and get the same thing.
|
|
8
|
-
*
|
|
9
|
-
* Node's own http server takes the same `(req, res, next)` middleware shape
|
|
10
|
-
* Vite's does, so the routes are shared verbatim - only the mounting differs.
|
|
11
|
-
* Everything here is dev tooling; none of it ships to a browser.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { createServer } from 'node:http';
|
|
15
|
-
import { readFile } from 'node:fs/promises';
|
|
16
|
-
import { resolve, extname, join, sep } from 'node:path';
|
|
17
|
-
import { fileURLToPath } from 'node:url';
|
|
18
|
-
import { createReportRoutes, DEFAULT_PREFIX } from '../server/routes.js';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const TYPES = {
|
|
22
|
-
'.html': 'text/html; charset=utf-8',
|
|
23
|
-
'.js': 'text/javascript; charset=utf-8',
|
|
24
|
-
'.css': 'text/css; charset=utf-8',
|
|
25
|
-
'.json': 'application/json; charset=utf-8',
|
|
26
|
-
'.svg': 'image/svg+xml',
|
|
27
|
-
/* the tab icon, and anything else the pages point at in src/asset */
|
|
28
|
-
'.png': 'image/png',
|
|
29
|
-
'.ico': 'image/x-icon'
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** where the designer's own files are, relative to this module */
|
|
33
|
-
const HERE = fileURLToPath(new URL('.', import.meta.url));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Starts the server.
|
|
38
|
-
*
|
|
39
|
-
* @param {object} options
|
|
40
|
-
* @param {string} options.dir the report directory
|
|
41
|
-
* @param {number} [options.port]
|
|
42
|
-
* @param {string} [options.host]
|
|
43
|
-
* @param {string} [options.root] the directory the designer's files are served from
|
|
44
|
-
* @returns {Promise<{url: string, port: number, close: () => Promise<void>}>}
|
|
45
|
-
*/
|
|
46
|
-
export function serve({
|
|
47
|
-
dir,
|
|
48
|
-
port = 5177,
|
|
49
|
-
host = '127.0.0.1',
|
|
50
|
-
root = resolve(HERE, '..')
|
|
51
|
-
} = {}) {
|
|
52
|
-
const reports = createReportRoutes({ dir, prefix: DEFAULT_PREFIX });
|
|
53
|
-
const base = resolve(root);
|
|
54
|
-
|
|
55
|
-
const server = createServer((req, res) => {
|
|
56
|
-
reports(req, res, () => {
|
|
57
|
-
serveStatic(req, res, base)
|
|
58
|
-
.catch(() => plain(res, 500, 'internal error'));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return new Promise((ok, fail) => {
|
|
63
|
-
server.on('error', fail);
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Bound to the loopback address by default. This serves a write
|
|
67
|
-
* endpoint, so it should not be reachable from the network unless
|
|
68
|
-
* somebody deliberately asks for that.
|
|
69
|
-
*/
|
|
70
|
-
server.listen(port, host, () => {
|
|
71
|
-
const actual = server.address().port;
|
|
72
|
-
|
|
73
|
-
ok({
|
|
74
|
-
port: actual,
|
|
75
|
-
url: `http://${host}:${actual}/designer/`,
|
|
76
|
-
close: () => new Promise(done => server.close(done))
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
async function serveStatic(req, res, base) {
|
|
84
|
-
const url = decodeSafely((req.url || '/').split('?')[0]);
|
|
85
|
-
const path = filePath(url, base);
|
|
86
|
-
|
|
87
|
-
if (!path) return plain(res, 403, 'forbidden');
|
|
88
|
-
|
|
89
|
-
let body;
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
body = await readFile(path);
|
|
93
|
-
} catch {
|
|
94
|
-
return plain(res, 404, 'not found');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
res.statusCode = 200;
|
|
98
|
-
res.setHeader('Content-Type', TYPES[extname(path)] ?? 'application/octet-stream');
|
|
99
|
-
/** dev tooling: never let a stale designer sit in the browser cache */
|
|
100
|
-
res.setHeader('Cache-Control', 'no-store');
|
|
101
|
-
res.end(body);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The file a URL maps to, or null when it escapes the served directory.
|
|
107
|
-
*
|
|
108
|
-
* The same discipline as the report routes: resolve, then confirm the result is
|
|
109
|
-
* still underneath. A static server that can be walked out of with `..` gives
|
|
110
|
-
* away every file the process can read.
|
|
111
|
-
*/
|
|
112
|
-
function filePath(url, base) {
|
|
113
|
-
const clean = url.endsWith('/') ? `${url}index.html` : url;
|
|
114
|
-
const path = resolve(join(base, clean));
|
|
115
|
-
|
|
116
|
-
if (path !== base && !path.startsWith(base + sep)) return null;
|
|
117
|
-
|
|
118
|
-
return path;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
function decodeSafely(text) {
|
|
123
|
-
try {
|
|
124
|
-
return decodeURIComponent(text);
|
|
125
|
-
} catch {
|
|
126
|
-
return text;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function plain(res, status, text) {
|
|
132
|
-
res.statusCode = status;
|
|
133
|
-
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
134
|
-
res.end(text);
|
|
135
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* serve.js starts the designer on a local http server.
|
|
3
|
+
*
|
|
4
|
+
* This is the primary way into the designer, and the reason it is a CLI rather
|
|
5
|
+
* than only a Vite plugin: it depends on nothing in the host project, so a
|
|
6
|
+
* plain-JS site, a webpack app, or a folder with no build tooling at all can
|
|
7
|
+
* run `npx report-studio design` and get the same thing.
|
|
8
|
+
*
|
|
9
|
+
* Node's own http server takes the same `(req, res, next)` middleware shape
|
|
10
|
+
* Vite's does, so the routes are shared verbatim - only the mounting differs.
|
|
11
|
+
* Everything here is dev tooling; none of it ships to a browser.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createServer } from 'node:http';
|
|
15
|
+
import { readFile } from 'node:fs/promises';
|
|
16
|
+
import { resolve, extname, join, sep } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { createReportRoutes, DEFAULT_PREFIX } from '../server/routes.js';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const TYPES = {
|
|
22
|
+
'.html': 'text/html; charset=utf-8',
|
|
23
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
24
|
+
'.css': 'text/css; charset=utf-8',
|
|
25
|
+
'.json': 'application/json; charset=utf-8',
|
|
26
|
+
'.svg': 'image/svg+xml',
|
|
27
|
+
/* the tab icon, and anything else the pages point at in src/asset */
|
|
28
|
+
'.png': 'image/png',
|
|
29
|
+
'.ico': 'image/x-icon'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** where the designer's own files are, relative to this module */
|
|
33
|
+
const HERE = fileURLToPath(new URL('.', import.meta.url));
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Starts the server.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} options
|
|
40
|
+
* @param {string} options.dir the report directory
|
|
41
|
+
* @param {number} [options.port]
|
|
42
|
+
* @param {string} [options.host]
|
|
43
|
+
* @param {string} [options.root] the directory the designer's files are served from
|
|
44
|
+
* @returns {Promise<{url: string, port: number, close: () => Promise<void>}>}
|
|
45
|
+
*/
|
|
46
|
+
export function serve({
|
|
47
|
+
dir,
|
|
48
|
+
port = 5177,
|
|
49
|
+
host = '127.0.0.1',
|
|
50
|
+
root = resolve(HERE, '..')
|
|
51
|
+
} = {}) {
|
|
52
|
+
const reports = createReportRoutes({ dir, prefix: DEFAULT_PREFIX });
|
|
53
|
+
const base = resolve(root);
|
|
54
|
+
|
|
55
|
+
const server = createServer((req, res) => {
|
|
56
|
+
reports(req, res, () => {
|
|
57
|
+
serveStatic(req, res, base)
|
|
58
|
+
.catch(() => plain(res, 500, 'internal error'));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return new Promise((ok, fail) => {
|
|
63
|
+
server.on('error', fail);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Bound to the loopback address by default. This serves a write
|
|
67
|
+
* endpoint, so it should not be reachable from the network unless
|
|
68
|
+
* somebody deliberately asks for that.
|
|
69
|
+
*/
|
|
70
|
+
server.listen(port, host, () => {
|
|
71
|
+
const actual = server.address().port;
|
|
72
|
+
|
|
73
|
+
ok({
|
|
74
|
+
port: actual,
|
|
75
|
+
url: `http://${host}:${actual}/designer/`,
|
|
76
|
+
close: () => new Promise(done => server.close(done))
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async function serveStatic(req, res, base) {
|
|
84
|
+
const url = decodeSafely((req.url || '/').split('?')[0]);
|
|
85
|
+
const path = filePath(url, base);
|
|
86
|
+
|
|
87
|
+
if (!path) return plain(res, 403, 'forbidden');
|
|
88
|
+
|
|
89
|
+
let body;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
body = await readFile(path);
|
|
93
|
+
} catch {
|
|
94
|
+
return plain(res, 404, 'not found');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
res.statusCode = 200;
|
|
98
|
+
res.setHeader('Content-Type', TYPES[extname(path)] ?? 'application/octet-stream');
|
|
99
|
+
/** dev tooling: never let a stale designer sit in the browser cache */
|
|
100
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
101
|
+
res.end(body);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The file a URL maps to, or null when it escapes the served directory.
|
|
107
|
+
*
|
|
108
|
+
* The same discipline as the report routes: resolve, then confirm the result is
|
|
109
|
+
* still underneath. A static server that can be walked out of with `..` gives
|
|
110
|
+
* away every file the process can read.
|
|
111
|
+
*/
|
|
112
|
+
function filePath(url, base) {
|
|
113
|
+
const clean = url.endsWith('/') ? `${url}index.html` : url;
|
|
114
|
+
const path = resolve(join(base, clean));
|
|
115
|
+
|
|
116
|
+
if (path !== base && !path.startsWith(base + sep)) return null;
|
|
117
|
+
|
|
118
|
+
return path;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
function decodeSafely(text) {
|
|
123
|
+
try {
|
|
124
|
+
return decodeURIComponent(text);
|
|
125
|
+
} catch {
|
|
126
|
+
return text;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
function plain(res, status, text) {
|
|
132
|
+
res.statusCode = status;
|
|
133
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
134
|
+
res.end(text);
|
|
135
|
+
}
|