@paprize/react 0.0.5 → 0.0.7
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 +1 -1
- package/dist/paprize-react.d.ts +88 -32
- package/dist/paprize-react.js +185 -197
- package/dist/paprize-react.js.map +1 -1
- package/dist/paprize-react.umd.cjs +1 -1
- package/dist/paprize-react.umd.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
Design your report using the full power of JavaScript and CSS, mark the report section by paprize components and then paprize pagination engine will transforming it into a beautiful, professional, print-ready pages.
|
|
4
4
|
|
|
5
|
-

|
package/dist/paprize-react.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import { ConfigAttribute } from '@paprize/core';
|
|
2
1
|
import { Context } from 'react';
|
|
3
2
|
import { JSX } from 'react/jsx-runtime';
|
|
4
|
-
import {
|
|
5
|
-
import { PageMargin } from '@paprize/core';
|
|
6
|
-
import { PageOrientation } from '@paprize/core';
|
|
7
|
-
import { PaginationConfig } from '@paprize/core';
|
|
3
|
+
import { LayoutOptions } from '@paprize/core';
|
|
8
4
|
import { PaginationCycleCompleted } from '@paprize/core';
|
|
9
5
|
import { PaginationPlugin } from '@paprize/core';
|
|
10
6
|
import { ReactNode } from 'react';
|
|
11
7
|
import { SectionContext } from '@paprize/core';
|
|
12
|
-
|
|
13
|
-
export declare const jsonData: () => Promise<unknown>;
|
|
8
|
+
import { SectionOptions } from '@paprize/core';
|
|
14
9
|
|
|
15
10
|
export declare function Layout({ children, ...attributes }: LayoutProps): JSX.Element;
|
|
16
11
|
|
|
17
|
-
export declare interface LayoutProps extends
|
|
12
|
+
export declare interface LayoutProps extends LayoutOptions {
|
|
18
13
|
children: React.ReactNode;
|
|
19
14
|
}
|
|
20
15
|
|
|
@@ -25,7 +20,7 @@ export declare function PageContent({ children }: {
|
|
|
25
20
|
}): JSX.Element;
|
|
26
21
|
|
|
27
22
|
export declare function pageContextToPageInfo(pc: {
|
|
28
|
-
|
|
23
|
+
pageIndex: number;
|
|
29
24
|
totalPages: number;
|
|
30
25
|
}): PageInfo;
|
|
31
26
|
|
|
@@ -37,8 +32,17 @@ export declare function PageHeader({ children }: {
|
|
|
37
32
|
children: ReactNode;
|
|
38
33
|
}): JSX.Element;
|
|
39
34
|
|
|
35
|
+
/**
|
|
36
|
+
* {@inheritDoc @paprize/core!PageContext}
|
|
37
|
+
*/
|
|
40
38
|
export declare interface PageInfo {
|
|
39
|
+
/**
|
|
40
|
+
* {@inheritDoc @paprize/core!PageContext.pageIndex}
|
|
41
|
+
*/
|
|
41
42
|
pageIndex: number;
|
|
43
|
+
/**
|
|
44
|
+
* {@inheritDoc @paprize/core!PageContext.totalPages}
|
|
45
|
+
*/
|
|
42
46
|
totalPages: number;
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -46,20 +50,18 @@ export declare function PageOverlay({ children }: {
|
|
|
46
50
|
children: ReactNode;
|
|
47
51
|
}): JSX.Element;
|
|
48
52
|
|
|
49
|
-
export { PaginationConfig }
|
|
50
|
-
|
|
51
53
|
export declare function paginationCycleToReportInfo(rc: PaginationCycleCompleted): ReportInfo;
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
/**
|
|
56
|
+
* {@inheritDoc @paprize/core!PaginationCycleCompleted}
|
|
57
|
+
*/
|
|
55
58
|
export declare interface ReportInfo {
|
|
59
|
+
/**
|
|
60
|
+
* {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}
|
|
61
|
+
*/
|
|
56
62
|
sections: SectionInfo[];
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
/**
|
|
60
|
-
* ReportPreview is a wrapper component that applies styles to its children, mimicking the appearance of the Chrome Print Preview screen.
|
|
61
|
-
* Use this component to render reports or documents with a print-friendly layout and consistent visual formatting in client side application.
|
|
62
|
-
*/
|
|
63
65
|
export declare function ReportPreview({ children }: {
|
|
64
66
|
children: ReactNode;
|
|
65
67
|
}): JSX.Element;
|
|
@@ -70,7 +72,7 @@ export declare interface ReportRootProps {
|
|
|
70
72
|
children: ReactNode;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
export declare function Section({ children, id,
|
|
75
|
+
export declare function Section({ children, id, ...options }: SectionProps): JSX.Element;
|
|
74
76
|
|
|
75
77
|
export declare function sectionContextToSectionInfo(sc: SectionContext): SectionInfo;
|
|
76
78
|
|
|
@@ -89,39 +91,93 @@ export declare function SectionHeader({ children }: {
|
|
|
89
91
|
children: React.ReactNode;
|
|
90
92
|
}): JSX.Element;
|
|
91
93
|
|
|
94
|
+
/**
|
|
95
|
+
* {@inheritDoc @paprize/core!SectionContext}
|
|
96
|
+
*/
|
|
92
97
|
export declare interface SectionInfo {
|
|
98
|
+
/**
|
|
99
|
+
* {@inheritDoc @paprize/core!SectionContext.sectionId}
|
|
100
|
+
*/
|
|
93
101
|
sectionId: string;
|
|
102
|
+
/**
|
|
103
|
+
* {@inheritDoc @paprize/core!SectionContext.sectionIndex}
|
|
104
|
+
*/
|
|
94
105
|
sectionIndex: number;
|
|
106
|
+
/**
|
|
107
|
+
* {@inheritDoc @paprize/core!SectionContext.isPaginated}
|
|
108
|
+
*/
|
|
95
109
|
isPaginated: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* {@inheritDoc @paprize/core!SectionContext.isSuspended}
|
|
112
|
+
*/
|
|
96
113
|
isSuspended: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* {@inheritDoc @paprize/core!SectionContext.pages}
|
|
116
|
+
*/
|
|
97
117
|
pages: PageInfo[];
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Configuration options for a section.
|
|
122
|
+
* @inlineType SectionOptions
|
|
123
|
+
*/
|
|
124
|
+
export declare interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {
|
|
101
125
|
children: ReactNode;
|
|
126
|
+
/**
|
|
127
|
+
* Unique id of the section within the report. If not set, a random id will be used.
|
|
128
|
+
*/
|
|
102
129
|
id?: string;
|
|
103
|
-
dimension: PageDimension;
|
|
104
|
-
orientation?: PageOrientation;
|
|
105
|
-
margin?: PageMargin;
|
|
106
|
-
config?: Partial<PaginationConfig>;
|
|
107
130
|
}
|
|
108
131
|
|
|
109
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Controls the section suspension.
|
|
134
|
+
* @inline
|
|
135
|
+
*/
|
|
136
|
+
export declare interface SectionSuspension {
|
|
137
|
+
/**
|
|
138
|
+
* Releases the suspension. The pagination engine will paginate this section immediately.
|
|
139
|
+
*/
|
|
140
|
+
release: () => void;
|
|
141
|
+
/**
|
|
142
|
+
* Marks the suspension as pending again if it was previously resolved.
|
|
143
|
+
* During the next pagination cycle (for example, if pagination is retriggered
|
|
144
|
+
* by changes to the page content), this section will not be paginated
|
|
145
|
+
* until `release` is called again.
|
|
146
|
+
*/
|
|
147
|
+
reset: () => void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* {@inheritDoc @paprize/core!ReportBuilder.getJsonData}
|
|
152
|
+
*/
|
|
153
|
+
export declare function useJsonData<DataModel>(defaultValue?: DataModel): DataModel | null;
|
|
110
154
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
/**
|
|
156
|
+
* React hook that returns information about the current page.
|
|
157
|
+
*/
|
|
158
|
+
export declare const usePageInfo: () => PageInfo;
|
|
115
159
|
|
|
160
|
+
/**
|
|
161
|
+
* React hook that returns information about the report.
|
|
162
|
+
*/
|
|
116
163
|
export declare function useReportInfo(): ReportInfo;
|
|
117
164
|
|
|
165
|
+
/**
|
|
166
|
+
* React hook that returns information about the current section.
|
|
167
|
+
*/
|
|
118
168
|
export declare const useSectionInfo: () => SectionInfo;
|
|
119
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Suspends pagination for this section.
|
|
172
|
+
* @param promise The suspension is tied to this promise. Once the promise is resolved,
|
|
173
|
+
* the suspension is released and the pagination engine will paginate this section.
|
|
174
|
+
*/
|
|
120
175
|
export declare function useSectionSuspension(promise: Promise<void> | Promise<unknown>): void;
|
|
121
176
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Suspends pagination for this section. You need to call the `release` method
|
|
179
|
+
* of the returned value; otherwise, the pagination engine will never paginate this section.
|
|
180
|
+
*/
|
|
181
|
+
export declare function useSectionSuspension(): SectionSuspension;
|
|
126
182
|
|
|
127
183
|
export { }
|
package/dist/paprize-react.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { jsx as r, Fragment as
|
|
2
|
-
import { previewClassName as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { createPortal as
|
|
5
|
-
function
|
|
6
|
-
return /* @__PURE__ */ r("div", { className:
|
|
1
|
+
import { jsx as r, Fragment as p, jsxs as R } from "react/jsx-runtime";
|
|
2
|
+
import { previewClassName as _, ReportBuilder as A, reportStyles as c, pageClassName as M, pageMargin as D, adjustPageSize as J, logger as V, sectionClassName as q, pageBreakAttributeName as G, layoutOptionsToAttributes as K } from "@paprize/core";
|
|
3
|
+
import { createContext as I, useContext as g, useMemo as a, useEffect as d, useRef as u, Children as Q, isValidElement as U, useState as W, useSyncExternalStore as b } from "react";
|
|
4
|
+
import { createPortal as X } from "react-dom";
|
|
5
|
+
function le({ children: e }) {
|
|
6
|
+
return /* @__PURE__ */ r("div", { className: _, children: e });
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
const e = g(
|
|
8
|
+
const F = I(null);
|
|
9
|
+
function m() {
|
|
10
|
+
const e = g(F);
|
|
11
11
|
if (!e)
|
|
12
12
|
throw new Error(
|
|
13
13
|
"ReportRoot is missing. Please wrap your component tree with ReportRoot component."
|
|
14
14
|
);
|
|
15
15
|
return e;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const t =
|
|
19
|
-
return
|
|
20
|
-
t.
|
|
21
|
-
}, [t]), /* @__PURE__ */ r(
|
|
17
|
+
function de({ children: e }) {
|
|
18
|
+
const t = a(() => new A(), []);
|
|
19
|
+
return d(() => {
|
|
20
|
+
t.schedulePagination();
|
|
21
|
+
}, [t]), /* @__PURE__ */ r(F, { value: t, children: e });
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const t =
|
|
25
|
-
return
|
|
23
|
+
function B({ children: e }) {
|
|
24
|
+
const t = m(), o = u(!1);
|
|
25
|
+
return d(() => {
|
|
26
26
|
const n = t.monitor.addEventListener(
|
|
27
27
|
"paginationCycleCompleted",
|
|
28
28
|
() => {
|
|
@@ -30,63 +30,63 @@ function N({ children: e }) {
|
|
|
30
30
|
}
|
|
31
31
|
);
|
|
32
32
|
return () => n();
|
|
33
|
-
}, [t.monitor]),
|
|
34
|
-
o.current && t.
|
|
35
|
-
}, [e, t]), /* @__PURE__ */ r(
|
|
33
|
+
}, [t.monitor]), d(() => {
|
|
34
|
+
o.current && t.schedulePagination();
|
|
35
|
+
}, [e, t]), /* @__PURE__ */ r(p, { children: e });
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return /* @__PURE__ */ r(
|
|
37
|
+
function H({ children: e }) {
|
|
38
|
+
return /* @__PURE__ */ r(p, { children: e });
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
return /* @__PURE__ */ r(
|
|
40
|
+
function k({ children: e }) {
|
|
41
|
+
return /* @__PURE__ */ r(p, { children: e });
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
return /* @__PURE__ */ r(
|
|
43
|
+
function N({ children: e }) {
|
|
44
|
+
return /* @__PURE__ */ r(p, { children: e });
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
return /* @__PURE__ */ r(
|
|
46
|
+
function z({ children: e }) {
|
|
47
|
+
return /* @__PURE__ */ r(p, { children: e });
|
|
48
48
|
}
|
|
49
49
|
function L({ children: e }) {
|
|
50
|
-
return /* @__PURE__ */ r(
|
|
50
|
+
return /* @__PURE__ */ r(p, { children: e });
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
D,
|
|
52
|
+
const w = [
|
|
53
|
+
B,
|
|
55
54
|
k,
|
|
55
|
+
H,
|
|
56
56
|
L,
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
z,
|
|
58
|
+
N
|
|
59
59
|
];
|
|
60
|
-
function
|
|
60
|
+
function Y(e) {
|
|
61
61
|
let t = null;
|
|
62
62
|
const o = {};
|
|
63
|
-
if (
|
|
64
|
-
if (!
|
|
63
|
+
if (Q.forEach(e, (n) => {
|
|
64
|
+
if (!U(n))
|
|
65
65
|
throw new Error(
|
|
66
66
|
`Invalid React element found in children: ${n}`,
|
|
67
67
|
{
|
|
68
68
|
cause: { child: n }
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
const s =
|
|
71
|
+
const s = w.find((i) => i === n.type);
|
|
72
72
|
if (!s)
|
|
73
73
|
throw Error(
|
|
74
|
-
`Component "${n.type}" is not valid as a child for Section, Expected one of: ${
|
|
74
|
+
`Component "${n.type}" is not valid as a child for Section, Expected one of: ${w.map((i) => i.name).join(",")}`
|
|
75
75
|
);
|
|
76
76
|
switch (s) {
|
|
77
|
-
case
|
|
77
|
+
case z:
|
|
78
78
|
o.sectionHeader = n;
|
|
79
79
|
break;
|
|
80
|
-
case
|
|
80
|
+
case N:
|
|
81
81
|
o.sectionFooter = n;
|
|
82
82
|
break;
|
|
83
|
-
case
|
|
83
|
+
case B:
|
|
84
84
|
t = n;
|
|
85
85
|
break;
|
|
86
|
-
case
|
|
86
|
+
case k:
|
|
87
87
|
o.header = n;
|
|
88
88
|
break;
|
|
89
|
-
case
|
|
89
|
+
case H:
|
|
90
90
|
o.footer = n;
|
|
91
91
|
break;
|
|
92
92
|
case L:
|
|
@@ -97,48 +97,48 @@ function Z(e) {
|
|
|
97
97
|
throw Error("PageContent component is a required child for Section");
|
|
98
98
|
return { ...o, content: t };
|
|
99
99
|
}
|
|
100
|
-
const
|
|
100
|
+
const h = I(""), T = I({
|
|
101
101
|
pageIndex: 0,
|
|
102
102
|
totalPages: 0
|
|
103
103
|
});
|
|
104
|
-
function
|
|
104
|
+
function E({
|
|
105
105
|
elements: e,
|
|
106
|
-
|
|
106
|
+
size: t,
|
|
107
107
|
margin: o,
|
|
108
108
|
pageIndex: n,
|
|
109
109
|
totalPages: s,
|
|
110
|
-
ref:
|
|
111
|
-
sectionHeaderRef:
|
|
112
|
-
sectionFooterRef:
|
|
113
|
-
pageHeaderRef:
|
|
110
|
+
ref: i,
|
|
111
|
+
sectionHeaderRef: x,
|
|
112
|
+
sectionFooterRef: S,
|
|
113
|
+
pageHeaderRef: P,
|
|
114
114
|
pageFooterRef: y,
|
|
115
|
-
contentRef:
|
|
115
|
+
contentRef: v
|
|
116
116
|
}) {
|
|
117
|
-
const
|
|
117
|
+
const f = g(h), C = a(
|
|
118
118
|
() => ({ pageIndex: n, totalPages: s }),
|
|
119
119
|
[n, s]
|
|
120
120
|
);
|
|
121
|
-
return /* @__PURE__ */ r(
|
|
121
|
+
return /* @__PURE__ */ r(T, { value: C, children: /* @__PURE__ */ R(
|
|
122
122
|
"div",
|
|
123
123
|
{
|
|
124
|
-
id: `${
|
|
125
|
-
className:
|
|
126
|
-
ref:
|
|
127
|
-
style:
|
|
124
|
+
id: `${f}-${n}`,
|
|
125
|
+
className: M,
|
|
126
|
+
ref: i,
|
|
127
|
+
style: c.page(t, o ?? D.None),
|
|
128
128
|
children: [
|
|
129
|
-
e.sectionHeader && n === 0 && /* @__PURE__ */ r("div", { style:
|
|
130
|
-
e.header && /* @__PURE__ */ r("div", { style:
|
|
131
|
-
/* @__PURE__ */ r("div", { style:
|
|
132
|
-
e.overlay && /* @__PURE__ */ r("div", { style:
|
|
129
|
+
e.sectionHeader && n === 0 && /* @__PURE__ */ r("div", { style: c.component, ref: x, children: e.sectionHeader }),
|
|
130
|
+
e.header && /* @__PURE__ */ r("div", { style: c.component, ref: P, children: e.header }),
|
|
131
|
+
/* @__PURE__ */ r("div", { style: c.pageContent, ref: v, children: e.content }),
|
|
132
|
+
e.overlay && /* @__PURE__ */ r("div", { style: c.overlay, children: e.overlay }),
|
|
133
133
|
(e.footer || e.sectionFooter) && /* @__PURE__ */ R(
|
|
134
134
|
"div",
|
|
135
135
|
{
|
|
136
|
-
style: { ...
|
|
136
|
+
style: { ...c.component, marginTop: "auto" },
|
|
137
137
|
children: [
|
|
138
138
|
e.footer && /* @__PURE__ */ r(
|
|
139
139
|
"div",
|
|
140
140
|
{
|
|
141
|
-
style:
|
|
141
|
+
style: c.component,
|
|
142
142
|
ref: y,
|
|
143
143
|
children: e.footer
|
|
144
144
|
}
|
|
@@ -146,8 +146,8 @@ function b({
|
|
|
146
146
|
e.sectionFooter && n === s - 1 && /* @__PURE__ */ r(
|
|
147
147
|
"div",
|
|
148
148
|
{
|
|
149
|
-
style:
|
|
150
|
-
ref:
|
|
149
|
+
style: c.component,
|
|
150
|
+
ref: S,
|
|
151
151
|
children: e.sectionFooter
|
|
152
152
|
}
|
|
153
153
|
)
|
|
@@ -158,7 +158,7 @@ function b({
|
|
|
158
158
|
}
|
|
159
159
|
) });
|
|
160
160
|
}
|
|
161
|
-
const $ =
|
|
161
|
+
const $ = I({
|
|
162
162
|
addPlugin: () => {
|
|
163
163
|
throw new Error("addPlugin must be used within a Section");
|
|
164
164
|
},
|
|
@@ -166,14 +166,14 @@ const $ = h({
|
|
|
166
166
|
throw new Error("addSuspense must be used within a Section");
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
|
-
function
|
|
170
|
-
const t =
|
|
169
|
+
function Z(e) {
|
|
170
|
+
const t = a(
|
|
171
171
|
() => ({
|
|
172
172
|
plugins: e ?? [],
|
|
173
173
|
suspense: []
|
|
174
174
|
}),
|
|
175
175
|
[e]
|
|
176
|
-
), o =
|
|
176
|
+
), o = a(
|
|
177
177
|
() => ({
|
|
178
178
|
addPlugin: (n) => {
|
|
179
179
|
t.plugins.push(n);
|
|
@@ -189,44 +189,46 @@ function ee(e) {
|
|
|
189
189
|
controllerValue: o
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
n?.plugins
|
|
200
|
-
), d = w(), m = c(null), y = c(null), P = c(null), v = c(null), C = c(null), I = c(null), [J, M] = X(
|
|
192
|
+
function ee({ elements: e, options: t }) {
|
|
193
|
+
const o = g(h), { controllerState: n, controllerValue: s } = Z(
|
|
194
|
+
t?.plugins
|
|
195
|
+
), i = m(), x = u(null), S = u(null), P = u(null), y = u(null), v = u(null), f = u(null), C = a(
|
|
196
|
+
() => J(t.size, t.orientation),
|
|
197
|
+
[t.orientation, t.size]
|
|
198
|
+
), [j, O] = W(
|
|
201
199
|
null
|
|
202
200
|
);
|
|
203
|
-
return
|
|
204
|
-
if (
|
|
205
|
-
return
|
|
201
|
+
return d(() => {
|
|
202
|
+
if (f.current)
|
|
203
|
+
return i.tryAddSection(
|
|
206
204
|
{
|
|
207
|
-
...
|
|
208
|
-
id:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
plugins: a.plugins,
|
|
212
|
-
suspense: a.suspense
|
|
205
|
+
...t,
|
|
206
|
+
id: o,
|
|
207
|
+
plugins: n.plugins,
|
|
208
|
+
suspense: n.suspense
|
|
213
209
|
},
|
|
214
210
|
{
|
|
215
|
-
pageContent:
|
|
216
|
-
sectionHeader:
|
|
211
|
+
pageContent: f.current,
|
|
212
|
+
sectionHeader: S.current,
|
|
217
213
|
sectionFooter: P.current,
|
|
218
|
-
pageFooter:
|
|
219
|
-
pageHeader:
|
|
214
|
+
pageFooter: v.current,
|
|
215
|
+
pageHeader: y.current
|
|
220
216
|
},
|
|
221
|
-
(
|
|
222
|
-
|
|
217
|
+
(l) => {
|
|
218
|
+
O(l);
|
|
223
219
|
}
|
|
224
|
-
), () => {
|
|
225
|
-
|
|
220
|
+
).catch((l) => V.error(l)), () => {
|
|
221
|
+
i.removeSection(o);
|
|
226
222
|
};
|
|
227
|
-
}, [
|
|
228
|
-
|
|
229
|
-
|
|
223
|
+
}, [
|
|
224
|
+
n.plugins,
|
|
225
|
+
n.suspense,
|
|
226
|
+
t,
|
|
227
|
+
i,
|
|
228
|
+
o
|
|
229
|
+
]), /* @__PURE__ */ R($, { value: s, children: [
|
|
230
|
+
j?.map((l) => /* @__PURE__ */ r(
|
|
231
|
+
E,
|
|
230
232
|
{
|
|
231
233
|
elements: {
|
|
232
234
|
...e,
|
|
@@ -235,140 +237,128 @@ function te({
|
|
|
235
237
|
{
|
|
236
238
|
style: { display: "contents" },
|
|
237
239
|
dangerouslySetInnerHTML: {
|
|
238
|
-
__html:
|
|
240
|
+
__html: l.pageContentHtml
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
)
|
|
242
244
|
},
|
|
243
|
-
|
|
244
|
-
margin:
|
|
245
|
-
pageIndex:
|
|
246
|
-
totalPages:
|
|
245
|
+
size: C,
|
|
246
|
+
margin: t.margin,
|
|
247
|
+
pageIndex: l.pageIndex,
|
|
248
|
+
totalPages: l.totalPages
|
|
247
249
|
},
|
|
248
|
-
|
|
250
|
+
l.pageIndex
|
|
249
251
|
)),
|
|
250
|
-
|
|
251
|
-
/* @__PURE__ */ r("div", { style:
|
|
252
|
-
|
|
252
|
+
X(
|
|
253
|
+
/* @__PURE__ */ r("div", { style: c.outOfScreen, children: /* @__PURE__ */ r(
|
|
254
|
+
E,
|
|
253
255
|
{
|
|
254
256
|
elements: e,
|
|
255
|
-
|
|
256
|
-
margin:
|
|
257
|
+
size: C,
|
|
258
|
+
margin: t.margin,
|
|
257
259
|
pageIndex: 0,
|
|
258
260
|
totalPages: 1,
|
|
259
|
-
ref:
|
|
260
|
-
sectionHeaderRef:
|
|
261
|
+
ref: x,
|
|
262
|
+
sectionHeaderRef: S,
|
|
261
263
|
sectionFooterRef: P,
|
|
262
|
-
pageHeaderRef:
|
|
263
|
-
pageFooterRef:
|
|
264
|
-
contentRef:
|
|
264
|
+
pageHeaderRef: y,
|
|
265
|
+
pageFooterRef: v,
|
|
266
|
+
contentRef: f
|
|
265
267
|
}
|
|
266
268
|
) }),
|
|
267
269
|
document.body
|
|
268
270
|
)
|
|
269
271
|
] });
|
|
270
272
|
}
|
|
271
|
-
let
|
|
272
|
-
function
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
config: a
|
|
279
|
-
}) {
|
|
280
|
-
const l = u(() => t ?? `__000${ne++}`, [t]), d = u(() => Z(e), [e]), m = u(
|
|
281
|
-
() => q(o, n),
|
|
273
|
+
let te = 1;
|
|
274
|
+
function pe({ children: e, id: t, ...o }) {
|
|
275
|
+
const n = a(() => t ?? `__000${te++}`, [t]), s = a(() => Y(e), [e]), i = a(
|
|
276
|
+
() => ({
|
|
277
|
+
...o,
|
|
278
|
+
id: n
|
|
279
|
+
}),
|
|
282
280
|
[o, n]
|
|
283
281
|
);
|
|
284
282
|
return /* @__PURE__ */ r(
|
|
285
283
|
"section",
|
|
286
284
|
{
|
|
287
|
-
className:
|
|
288
|
-
id:
|
|
289
|
-
style:
|
|
290
|
-
children: /* @__PURE__ */ r(
|
|
291
|
-
te,
|
|
292
|
-
{
|
|
293
|
-
elements: d,
|
|
294
|
-
dimension: m,
|
|
295
|
-
margin: s,
|
|
296
|
-
config: a
|
|
297
|
-
}
|
|
298
|
-
) })
|
|
285
|
+
className: q,
|
|
286
|
+
id: n,
|
|
287
|
+
style: c.section(n),
|
|
288
|
+
children: /* @__PURE__ */ r(h, { value: n, children: /* @__PURE__ */ r(ee, { elements: s, options: i }) })
|
|
299
289
|
}
|
|
300
290
|
);
|
|
301
291
|
}
|
|
302
|
-
function
|
|
303
|
-
return /* @__PURE__ */ r("span", { [
|
|
292
|
+
function ge() {
|
|
293
|
+
return /* @__PURE__ */ r("span", { [G]: "true" });
|
|
304
294
|
}
|
|
305
|
-
function
|
|
295
|
+
function fe({ children: e, ...t }) {
|
|
306
296
|
return /* @__PURE__ */ r(
|
|
307
297
|
"div",
|
|
308
298
|
{
|
|
309
299
|
style: { display: "contents" },
|
|
310
|
-
...
|
|
300
|
+
...K(t),
|
|
311
301
|
children: e
|
|
312
302
|
}
|
|
313
303
|
);
|
|
314
304
|
}
|
|
315
|
-
const
|
|
316
|
-
const e = g(
|
|
305
|
+
const me = () => {
|
|
306
|
+
const e = g(T);
|
|
317
307
|
return {
|
|
318
308
|
pageIndex: e.pageIndex,
|
|
319
309
|
totalPages: e.totalPages
|
|
320
310
|
};
|
|
321
|
-
},
|
|
322
|
-
const e = g(
|
|
311
|
+
}, Se = () => {
|
|
312
|
+
const e = g(h), t = m(), o = u({
|
|
323
313
|
pages: [],
|
|
324
314
|
isPaginated: !1,
|
|
325
315
|
isSuspended: !1,
|
|
326
|
-
|
|
316
|
+
sectionIndex: -1,
|
|
327
317
|
sectionId: e
|
|
328
|
-
}), n =
|
|
318
|
+
}), n = b(
|
|
329
319
|
(s) => t.monitor.addEventListener(
|
|
330
320
|
"sectionCompleted",
|
|
331
|
-
(
|
|
332
|
-
|
|
321
|
+
(i) => {
|
|
322
|
+
i.sectionId === e && (o.current = i, s());
|
|
333
323
|
}
|
|
334
324
|
),
|
|
335
325
|
() => o.current
|
|
336
326
|
);
|
|
337
327
|
return {
|
|
338
328
|
sectionId: e,
|
|
339
|
-
sectionIndex: n.
|
|
329
|
+
sectionIndex: n.sectionIndex,
|
|
340
330
|
isSuspended: n.isSuspended,
|
|
341
331
|
isPaginated: n.isPaginated,
|
|
342
332
|
pages: n.pages.map((s) => ({
|
|
343
|
-
pageIndex: s.
|
|
333
|
+
pageIndex: s.pageIndex,
|
|
344
334
|
totalPages: s.totalPages
|
|
345
335
|
}))
|
|
346
336
|
};
|
|
347
337
|
};
|
|
348
|
-
function
|
|
338
|
+
function ne(e) {
|
|
349
339
|
return {
|
|
350
|
-
pageIndex: e.
|
|
340
|
+
pageIndex: e.pageIndex,
|
|
351
341
|
totalPages: e.totalPages
|
|
352
342
|
};
|
|
353
343
|
}
|
|
354
|
-
function
|
|
344
|
+
function oe(e) {
|
|
355
345
|
return {
|
|
356
346
|
sectionId: e.sectionId,
|
|
357
|
-
sectionIndex: e.
|
|
347
|
+
sectionIndex: e.sectionIndex,
|
|
358
348
|
isPaginated: e.isPaginated,
|
|
359
349
|
isSuspended: e.isSuspended,
|
|
360
|
-
pages: e.pages.map(
|
|
350
|
+
pages: e.pages.map(ne)
|
|
361
351
|
};
|
|
362
352
|
}
|
|
363
|
-
function
|
|
353
|
+
function re(e) {
|
|
364
354
|
return {
|
|
365
|
-
sections: e.sections.map(
|
|
355
|
+
sections: e.sections.map(oe)
|
|
366
356
|
};
|
|
367
357
|
}
|
|
368
|
-
function
|
|
369
|
-
const e =
|
|
358
|
+
function Pe() {
|
|
359
|
+
const e = m(), t = u({
|
|
370
360
|
sections: []
|
|
371
|
-
}), o =
|
|
361
|
+
}), o = b(
|
|
372
362
|
(n) => e.monitor.addEventListener(
|
|
373
363
|
"paginationCycleCompleted",
|
|
374
364
|
(s) => {
|
|
@@ -377,11 +367,11 @@ function Ce() {
|
|
|
377
367
|
),
|
|
378
368
|
() => t.current
|
|
379
369
|
);
|
|
380
|
-
return
|
|
370
|
+
return re(o);
|
|
381
371
|
}
|
|
382
|
-
function
|
|
383
|
-
const t =
|
|
384
|
-
return
|
|
372
|
+
function se(e) {
|
|
373
|
+
const t = u(null), { addSuspense: o } = g($);
|
|
374
|
+
return d(() => {
|
|
385
375
|
if (t.current)
|
|
386
376
|
return;
|
|
387
377
|
const n = e ?? new Promise((s) => {
|
|
@@ -389,7 +379,7 @@ function ae(e) {
|
|
|
389
379
|
});
|
|
390
380
|
t.current ||= () => {
|
|
391
381
|
}, o(n);
|
|
392
|
-
}, [o, e]),
|
|
382
|
+
}, [o, e]), a(
|
|
393
383
|
() => ({
|
|
394
384
|
reset: () => {
|
|
395
385
|
t.current || o(
|
|
@@ -405,38 +395,36 @@ function ae(e) {
|
|
|
405
395
|
[o]
|
|
406
396
|
);
|
|
407
397
|
}
|
|
408
|
-
function
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return ae(ce().catch(() => e));
|
|
398
|
+
function ye(e) {
|
|
399
|
+
const t = m(), o = a(
|
|
400
|
+
() => ({
|
|
401
|
+
current: null
|
|
402
|
+
}),
|
|
403
|
+
[]
|
|
404
|
+
), n = a(
|
|
405
|
+
() => t.getJsonData(e),
|
|
406
|
+
[e, t]
|
|
407
|
+
);
|
|
408
|
+
return se(n), d(() => {
|
|
409
|
+
n.then((s) => o.current = s);
|
|
410
|
+
}, [n, o]), o.current ?? e ?? null;
|
|
422
411
|
}
|
|
423
412
|
export {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
413
|
+
fe as Layout,
|
|
414
|
+
ge as PageBreak,
|
|
415
|
+
B as PageContent,
|
|
416
|
+
H as PageFooter,
|
|
417
|
+
k as PageHeader,
|
|
429
418
|
L as PageOverlay,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
Pe as
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
ae as useSectionSuspension
|
|
419
|
+
le as ReportPreview,
|
|
420
|
+
de as ReportRoot,
|
|
421
|
+
pe as Section,
|
|
422
|
+
N as SectionFooter,
|
|
423
|
+
z as SectionHeader,
|
|
424
|
+
ye as useJsonData,
|
|
425
|
+
me as usePageInfo,
|
|
426
|
+
Pe as useReportInfo,
|
|
427
|
+
Se as useSectionInfo,
|
|
428
|
+
se as useSectionSuspension
|
|
441
429
|
};
|
|
442
430
|
//# sourceMappingURL=paprize-react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paprize-react.js","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core/src';\n\n/**\n * ReportPreview is a wrapper component that applies styles to its children, mimicking the appearance of the Chrome Print Preview screen.\n * Use this component to render reports or documents with a print-friendly layout and consistent visual formatting in client side application.\n */\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core/src';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core/src';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePaginate();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePaginate();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageDimension,\n type PageMargin,\n} from '@paprize/core/src';\n\nexport interface PageProps {\n elements: PageElements;\n dimension: PageDimension;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n dimension,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(dimension, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core/src';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core/src';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n reportStyles,\n type PageContext,\n type PageDimension,\n type PageMargin,\n type PaginationConfig,\n} from '@paprize/core/src';\nimport { useContext, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n dimension: PageDimension;\n margin: PageMargin | undefined;\n config?: Partial<PaginationConfig>;\n}\n\nexport function SectionLayout({\n elements,\n dimension,\n margin,\n config,\n}: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n config?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder.tryAddSection(\n {\n ...config,\n id: sectionId,\n dimension: dimension,\n margin: margin,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n );\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [config, controllerState, dimension, margin, reportBuilder, sectionId]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.index}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n dimension={dimension}\n margin={margin}\n pageIndex={pageContext.index}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n dimension={dimension}\n margin={margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n adjustDimension,\n reportStyles,\n sectionClassName,\n type PageDimension,\n type PageMargin,\n type PageOrientation,\n type PaginationConfig,\n} from '@paprize/core/src';\nimport { SectionLayout } from '../internal/SectionLayout';\n\nexport interface SectionProps {\n children: ReactNode;\n id?: string;\n dimension: PageDimension;\n orientation?: PageOrientation;\n margin?: PageMargin;\n config?: Partial<PaginationConfig>;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({\n children,\n id,\n dimension,\n orientation = 'portrait',\n margin,\n config,\n}: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n\n const adjustedDimension = useMemo(\n () => adjustDimension(dimension, orientation),\n [dimension, orientation]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout\n elements={elements}\n dimension={adjustedDimension}\n margin={margin}\n config={config}\n />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core/src';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { configToAttributeMap, type ConfigAttribute } from '@paprize/core/src';\n\nexport interface LayoutProps extends ConfigAttribute {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...configToAttributeMap(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\n\nexport const usePageInfo = () => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core/src';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n index: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.index,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.index,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type {\n PaginationCycleCompleted,\n SectionContext,\n} from '@paprize/core/src';\n\nexport interface SectionInfo {\n sectionId: string;\n sectionIndex: number;\n isPaginated: boolean;\n isSuspended: boolean;\n pages: PageInfo[];\n}\n\nexport interface PageInfo {\n pageIndex: number;\n totalPages: number;\n}\n\nexport interface ReportInfo {\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n index: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.index,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.index,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core/src';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\nexport function useSectionSuspension(): {\n release: () => void;\n reset: () => void;\n};\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { paprize_readJsonDataFile } from '@paprize/core/src';\nimport { useSectionSuspension } from './useSectionSuspension';\n\nfunction lazy<T>(factory: () => Promise<T>): () => Promise<T> {\n let promise: Promise<T> | null = null;\n\n return () => {\n if (!promise) {\n promise = factory();\n }\n return promise;\n };\n}\n\n// the function is not available in browser, and in puppeteer it is injected before anything else but we\n// still need to delay the call\nexport const jsonData = lazy(async () => {\n if (!(paprize_readJsonDataFile in window)) {\n throw new Error(\n 'The function paprize_readJsonDataFile is not available in the current environment.'\n );\n }\n\n const strData = await window[paprize_readJsonDataFile]?.();\n return strData ? (JSON.parse(strData) as unknown) : null;\n});\n\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | undefined {\n return useSectionSuspension(jsonData().catch(() => defaultValue)) as\n | DataModel\n | undefined;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","dimension","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","config","controllerState","controllerValue","pageRef","pageContexts","setPageContexts","useState","pages","pageContext","createPortal","sectionIdCounter","Section","id","orientation","adjustedDimension","adjustDimension","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","configToAttributeMap","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","lazy","factory","jsonData","paprize_readJsonDataFile","strData","useJsonData","defaultValue"],"mappings":";;;;AAOO,SAASA,GAAc,EAAE,UAAAC,KAAqC;AACjE,SAAO,gBAAAC,EAAC,OAAA,EAAI,WAAWC,GAAmB,UAAAF,EAAA,CAAS;AACvD;ACNO,MAAMG,IAAuBC,EAAoC,IAAI;AAErE,SAASC,IAAmB;AAC/B,QAAMC,IAAUC,EAAWJ,CAAoB;AAC/C,MAAI,CAACG;AACD,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAIR,SAAOA;AACX;ACNO,SAASE,GAAW,EAAE,UAAAR,KAA6B;AACtD,QAAMS,IAAgBC,EAAQ,MAAM,IAAIC,EAAA,GAAiB,CAAA,CAAE;AAE3D,SAAAC,EAAU,MAAM;AACZ,IAAAH,EAAc,iBAAA;AAAA,EAClB,GAAG,CAACA,CAAa,CAAC,GAGd,gBAAAR,EAACE,GAAA,EAAqB,OAAOM,GACxB,UAAAT,EAAA,CACL;AAER;ACjBO,SAASa,EAAY,EAAE,UAAAb,KAAqC;AAC/D,QAAMS,IAAgBJ,EAAA,GAChBS,IAAwBC,EAAO,EAAK;AAE1C,SAAAH,EAAU,MAAM;AACZ,UAAMI,IAAcP,EAAc,QAAQ;AAAA,MACtC;AAAA,MACA,MAAM;AACF,QAAAK,EAAsB,UAAU;AAAA,MACpC;AAAA,IAAA;AAGJ,WAAO,MAAME,EAAA;AAAA,EACjB,GAAG,CAACP,EAAc,OAAO,CAAC,GAK1BG,EA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lF,EAA0B,IAAI,GAC1C,EAAE,aAAAmF,EAAA,IAAgB3F,EAAW4C,CAAwB;AAE3D,SAAAvC,EAAU,MAAM;AACZ,QAAIqF,EAAU;AACV;AAGJ,UAAME,IACFH,KACA,IAAI,QAAc,CAACI,MAAY;AAC3B,MAAAH,EAAU,UAAUG;AAAA,IACxB,CAAC;AACL,IAAAH,EAAU,YAAY,MAAM;AAAA,IAAC,GAE7BC,EAAYC,CAAmB;AAAA,EACnC,GAAG,CAACD,GAAaF,CAAO,CAAC,GAElBtF;AAAA,IACH,OAAO;AAAA,MACH,OAAO,MAAM;AACT,QAAIuF,EAAU,WAEdC;AAAA,UACI,IAAI,QAAc,CAACE,MAAY;AAC3B,YAAAH,EAAU,UAAUG;AAAA,UACxB,CAAC;AAAA,QAAA;AAAA,MAET;AAAA,MACA,SAAS,MAAM;AACX,QAAAH,EAAU,UAAA,GACVA,EAAU,UAAU;AAAA,MACxB;AAAA,IAAA;AAAA,IAEJ,CAACC,CAAW;AAAA,EAAA;AAEpB;AC9CA,SAASG,GAAQC,GAA6C;AAC1D,MAAIN,IAA6B;AAEjC,SAAO,OACEA,MACDA,IAAUM,EAAA,IAEPN;AAEf;AAIO,MAAMO,KAAWF,GAAK,YAAY;AACrC,MAAI,EAAEG,KAA4B;AAC9B,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAIR,QAAMC,IAAU,MAAM,OAAOD,CAAwB,IAAA;AACrD,SAAOC,IAAW,KAAK,MAAMA,CAAO,IAAgB;AACxD,CAAC;AAEM,SAASC,GACZC,GACqB;AACrB,SAAOZ,GAAqBQ,GAAA,EAAW,MAAM,MAAMI,CAAY,CAAC;AAGpE;"}
|
|
1
|
+
{"version":3,"file":"paprize-react.js","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core/src';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core/src';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core/src';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core/src';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core/src';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core/src';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core/src';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core/src';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core/src';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import {\n layoutOptionsToAttributes,\n type LayoutOptions,\n} from '@paprize/core/src';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core/src';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type {\n PaginationCycleCompleted,\n SectionContext,\n} from '@paprize/core/src';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core/src';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","pages","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","useJsonData","defaultValue","value","v"],"mappings":";;;;AAGO,SAASA,GAAc,EAAE,UAAAC,KAAqC;AACjE,SAAO,gBAAAC,EAAC,OAAA,EAAI,WAAWC,GAAmB,UAAAF,EAAA,CAAS;AACvD;ACFO,MAAMG,IAAuBC,EAAoC,IAAI;AAErE,SAASC,IAAmB;AAC/B,QAAMC,IAAUC,EAAWJ,CAAoB;AAC/C,MAAI,CAACG;AACD,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAIR,SAAOA;AACX;ACNO,SAASE,GAAW,EAAE,UAAAR,KAA6B;AACtD,QAAMS,IAAgBC,EAAQ,MAA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AAS;AAAA,IAAA;AAAA,IAEb,CAAA;AAAA,EAAC,GAGCwF,IAAUxF;AAAA,IACZ,MAAMD,EAAc,YAAY+F,CAAY;AAAA,IAC5C,CAACA,GAAc/F,CAAa;AAAA,EAAA;AAGhC,SAAAwF,GAAqBC,CAAO,GAE5BtF,EAAU,MAAM;AACZ,IAAAsF,EAAQ,KAAK,CAACQ,MAAOD,EAAM,UAAUC,CAAE;AAAA,EAC3C,GAAG,CAACR,GAASO,CAAK,CAAC,GAEZA,EAAM,WAAWD,KAAgB;AAC5C;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react/jsx-runtime"),require("@paprize/core"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@paprize/core","react","react-dom"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i["paprize-react"]={},i.jsxRuntime,i.PaprizeCore,i.React,i.ReactDOM))})(this,(function(i,r,a,o,k){"use strict";function T({children:e}){return r.jsx("div",{className:a.previewClassName,children:e})}const x=o.createContext(null);function l(){const e=o.useContext(x);if(!e)throw new Error("ReportRoot is missing. Please wrap your component tree with ReportRoot component.");return e}function N({children:e}){const n=o.useMemo(()=>new a.ReportBuilder,[]);return o.useEffect(()=>{n.schedulePagination()},[n]),r.jsx(x,{value:n,children:e})}function v({children:e}){const n=l(),s=o.useRef(!1);return o.useEffect(()=>{const t=n.monitor.addEventListener("paginationCycleCompleted",()=>{s.current=!0});return()=>t()},[n.monitor]),o.useEffect(()=>{s.current&&n.schedulePagination()},[e,n]),r.jsx(r.Fragment,{children:e})}function I({children:e}){return r.jsx(r.Fragment,{children:e})}function h({children:e}){return r.jsx(r.Fragment,{children:e})}function m({children:e}){return r.jsx(r.Fragment,{children:e})}function w({children:e}){return r.jsx(r.Fragment,{children:e})}function E({children:e}){return r.jsx(r.Fragment,{children:e})}const M=[v,h,I,E,w,m];function L(e){let n=null;const s={};if(o.Children.forEach(e,t=>{if(!o.isValidElement(t))throw new Error(`Invalid React element found in children: ${t}`,{cause:{child:t}});const u=M.find(c=>c===t.type);if(!u)throw Error(`Component "${t.type}" is not valid as a child for Section, Expected one of: ${M.map(c=>c.name).join(",")}`);switch(u){case w:s.sectionHeader=t;break;case m:s.sectionFooter=t;break;case v:n=t;break;case h:s.header=t;break;case I:s.footer=t;break;case E:s.overlay=t;break}}),!n)throw Error("PageContent component is a required child for Section");return{...s,content:n}}const p=o.createContext(""),H=o.createContext({pageIndex:0,totalPages:0});function b({elements:e,size:n,margin:s,pageIndex:t,totalPages:u,ref:c,sectionHeaderRef:F,sectionFooterRef:g,pageHeaderRef:S,pageFooterRef:y,contentRef:P}){const f=o.useContext(p),C=o.useMemo(()=>({pageIndex:t,totalPages:u}),[t,u]);return r.jsx(H,{value:C,children:r.jsxs("div",{id:`${f}-${t}`,className:a.pageClassName,ref:c,style:a.reportStyles.page(n,s??a.pageMargin.None),children:[e.sectionHeader&&t===0&&r.jsx("div",{style:a.reportStyles.component,ref:F,children:e.sectionHeader}),e.header&&r.jsx("div",{style:a.reportStyles.component,ref:S,children:e.header}),r.jsx("div",{style:a.reportStyles.pageContent,ref:P,children:e.content}),e.overlay&&r.jsx("div",{style:a.reportStyles.overlay,children:e.overlay}),(e.footer||e.sectionFooter)&&r.jsxs("div",{style:{...a.reportStyles.component,marginTop:"auto"},children:[e.footer&&r.jsx("div",{style:a.reportStyles.component,ref:y,children:e.footer}),e.sectionFooter&&t===u-1&&r.jsx("div",{style:a.reportStyles.component,ref:g,children:e.sectionFooter})]})]})})}const B=o.createContext({addPlugin:()=>{throw new Error("addPlugin must be used within a Section")},addSuspense:()=>{throw new Error("addSuspense must be used within a Section")}});function O(e){const n=o.useMemo(()=>({plugins:e??[],suspense:[]}),[e]),s=o.useMemo(()=>({addPlugin:t=>{n.plugins.push(t)},addSuspense:t=>{n.suspense.push(t)}}),[n]);return{controllerState:n,controllerValue:s}}function R({elements:e,options:n}){const s=o.useContext(p),{controllerState:t,controllerValue:u}=O(n?.plugins),c=l(),F=o.useRef(null),g=o.useRef(null),S=o.useRef(null),y=o.useRef(null),P=o.useRef(null),f=o.useRef(null),C=o.useMemo(()=>a.adjustPageSize(n.size,n.orientation),[n.orientation,n.size]),[U,W]=o.useState(null);return o.useEffect(()=>{if(f.current)return c.tryAddSection({...n,id:s,plugins:t.plugins,suspense:t.suspense},{pageContent:f.current,sectionHeader:g.current,sectionFooter:S.current,pageFooter:P.current,pageHeader:y.current},d=>{W(d)}).catch(d=>a.logger.error(d)),()=>{c.removeSection(s)}},[t.plugins,t.suspense,n,c,s]),r.jsxs(B,{value:u,children:[U?.map(d=>r.jsx(b,{elements:{...e,content:r.jsx("div",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:d.pageContentHtml}})},size:C,margin:n.margin,pageIndex:d.pageIndex,totalPages:d.totalPages},d.pageIndex)),k.createPortal(r.jsx("div",{style:a.reportStyles.outOfScreen,children:r.jsx(b,{elements:e,size:C,margin:n.margin,pageIndex:0,totalPages:1,ref:F,sectionHeaderRef:g,sectionFooterRef:S,pageHeaderRef:y,pageFooterRef:P,contentRef:f})}),document.body)]})}let $=1;function q({children:e,id:n,...s}){const t=o.useMemo(()=>n??`__000${$++}`,[n]),u=o.useMemo(()=>L(e),[e]),c=o.useMemo(()=>({...s,id:t}),[s,t]);return r.jsx("section",{className:a.sectionClassName,id:t,style:a.reportStyles.section(t),children:r.jsx(p,{value:t,children:r.jsx(R,{elements:u,options:c})})})}function D(){return r.jsx("span",{[a.pageBreakAttributeName]:"true"})}function _({children:e,...n}){return r.jsx("div",{style:{display:"contents"},...a.layoutOptionsToAttributes(n),children:e})}const A=()=>{const e=o.useContext(H);return{pageIndex:e.pageIndex,totalPages:e.totalPages}},J=()=>{const e=o.useContext(p),n=l(),s=o.useRef({pages:[],isPaginated:!1,isSuspended:!1,sectionIndex:-1,sectionId:e}),t=o.useSyncExternalStore(u=>n.monitor.addEventListener("sectionCompleted",c=>{c.sectionId===e&&(s.current=c,u())}),()=>s.current);return{sectionId:e,sectionIndex:t.sectionIndex,isSuspended:t.isSuspended,isPaginated:t.isPaginated,pages:t.pages.map(u=>({pageIndex:u.pageIndex,totalPages:u.totalPages}))}};function j(e){return{pageIndex:e.pageIndex,totalPages:e.totalPages}}function V(e){return{sectionId:e.sectionId,sectionIndex:e.sectionIndex,isPaginated:e.isPaginated,isSuspended:e.isSuspended,pages:e.pages.map(j)}}function G(e){return{sections:e.sections.map(V)}}function K(){const e=l(),n=o.useRef({sections:[]}),s=o.useSyncExternalStore(t=>e.monitor.addEventListener("paginationCycleCompleted",u=>{n.current=u,t()}),()=>n.current);return G(s)}function z(e){const n=o.useRef(null),{addSuspense:s}=o.useContext(B);return o.useEffect(()=>{if(n.current)return;const t=e??new Promise(u=>{n.current=u});n.current||=()=>{},s(t)},[s,e]),o.useMemo(()=>({reset:()=>{n.current||s(new Promise(t=>{n.current=t}))},release:()=>{n.current?.(),n.current=null}}),[s])}function Q(e){const n=l(),s=o.useMemo(()=>({current:null}),[]),t=o.useMemo(()=>n.getJsonData(e),[e,n]);return z(t),o.useEffect(()=>{t.then(u=>s.current=u)},[t,s]),s.current??e??null}i.Layout=_,i.PageBreak=D,i.PageContent=v,i.PageFooter=I,i.PageHeader=h,i.PageOverlay=E,i.ReportPreview=T,i.ReportRoot=N,i.Section=q,i.SectionFooter=m,i.SectionHeader=w,i.useJsonData=Q,i.usePageInfo=A,i.useReportInfo=K,i.useSectionInfo=J,i.useSectionSuspension=z,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=paprize-react.umd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paprize-react.umd.cjs","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core/src';\n\n/**\n * ReportPreview is a wrapper component that applies styles to its children, mimicking the appearance of the Chrome Print Preview screen.\n * Use this component to render reports or documents with a print-friendly layout and consistent visual formatting in client side application.\n */\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core/src';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core/src';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePaginate();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePaginate();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageDimension,\n type PageMargin,\n} from '@paprize/core/src';\n\nexport interface PageProps {\n elements: PageElements;\n dimension: PageDimension;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n dimension,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(dimension, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core/src';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core/src';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n reportStyles,\n type PageContext,\n type PageDimension,\n type PageMargin,\n type PaginationConfig,\n} from '@paprize/core/src';\nimport { useContext, useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n dimension: PageDimension;\n margin: PageMargin | undefined;\n config?: Partial<PaginationConfig>;\n}\n\nexport function SectionLayout({\n elements,\n dimension,\n margin,\n config,\n}: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n config?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder.tryAddSection(\n {\n ...config,\n id: sectionId,\n dimension: dimension,\n margin: margin,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n );\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [config, controllerState, dimension, margin, reportBuilder, sectionId]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.index}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n dimension={dimension}\n margin={margin}\n pageIndex={pageContext.index}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n dimension={dimension}\n margin={margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n adjustDimension,\n reportStyles,\n sectionClassName,\n type PageDimension,\n type PageMargin,\n type PageOrientation,\n type PaginationConfig,\n} from '@paprize/core/src';\nimport { SectionLayout } from '../internal/SectionLayout';\n\nexport interface SectionProps {\n children: ReactNode;\n id?: string;\n dimension: PageDimension;\n orientation?: PageOrientation;\n margin?: PageMargin;\n config?: Partial<PaginationConfig>;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({\n children,\n id,\n dimension,\n orientation = 'portrait',\n margin,\n config,\n}: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n\n const adjustedDimension = useMemo(\n () => adjustDimension(dimension, orientation),\n [dimension, orientation]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout\n elements={elements}\n dimension={adjustedDimension}\n margin={margin}\n config={config}\n />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core/src';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import { configToAttributeMap, type ConfigAttribute } from '@paprize/core/src';\n\nexport interface LayoutProps extends ConfigAttribute {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...configToAttributeMap(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\n\nexport const usePageInfo = () => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core/src';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n index: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.index,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.index,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type {\n PaginationCycleCompleted,\n SectionContext,\n} from '@paprize/core/src';\n\nexport interface SectionInfo {\n sectionId: string;\n sectionIndex: number;\n isPaginated: boolean;\n isSuspended: boolean;\n pages: PageInfo[];\n}\n\nexport interface PageInfo {\n pageIndex: number;\n totalPages: number;\n}\n\nexport interface ReportInfo {\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n index: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.index,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.index,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core/src';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\nexport function useSectionSuspension(): {\n release: () => void;\n reset: () => void;\n};\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { paprize_readJsonDataFile } from '@paprize/core/src';\nimport { useSectionSuspension } from './useSectionSuspension';\n\nfunction lazy<T>(factory: () => Promise<T>): () => Promise<T> {\n let promise: Promise<T> | null = null;\n\n return () => {\n if (!promise) {\n promise = factory();\n }\n return promise;\n };\n}\n\n// the function is not available in browser, and in puppeteer it is injected before anything else but we\n// still need to delay the call\nexport const jsonData = lazy(async () => {\n if (!(paprize_readJsonDataFile in window)) {\n throw new Error(\n 'The function paprize_readJsonDataFile is not available in the current environment.'\n );\n }\n\n const strData = await window[paprize_readJsonDataFile]?.();\n return strData ? (JSON.parse(strData) as unknown) : null;\n});\n\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | undefined {\n return useSectionSuspension(jsonData().catch(() => defaultValue)) as\n | DataModel\n | undefined;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","dimension","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","config","controllerState","controllerValue","pageRef","pageContexts","setPageContexts","useState","pages","pageContext","createPortal","sectionIdCounter","Section","id","orientation","adjustedDimension","adjustDimension","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","configToAttributeMap","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","lazy","factory","jsonData","paprize_readJsonDataFile","strData","useJsonData","defaultValue"],"mappings":"mbAOO,SAASA,EAAc,CAAE,SAAAC,GAAqC,CACjE,OAAOC,EAAAA,IAAC,MAAA,CAAI,UAAWC,EAAAA,iBAAmB,SAAAF,CAAA,CAAS,CACvD,CCNO,MAAMG,EAAuBC,EAAAA,cAAoC,IAAI,EAErE,SAASC,GAAmB,CAC/B,MAAMC,EAAUC,EAAAA,WAAWJ,CAAoB,EAC/C,GAAI,CAACG,EACD,MAAM,IAAI,MACN,mFAAA,EAIR,OAAOA,CACX,CCNO,SAASE,EAAW,CAAE,SAAAR,GAA6B,CACtD,MAAMS,EAAgBC,EAAAA,QAAQ,IAAM,IAAIC,EAAAA,cAAiB,CAAA,CAAE,EAE3DC,OAAAA,EAAAA,UAAU,IAAM,CACZH,EAAc,iBAAA,CAClB,EAAG,CAACA,CAAa,CAAC,EAGdR,EAAAA,IAACE,EAAA,CAAqB,MAAOM,EACxB,SAAAT,CAAA,CACL,CAER,CCjBO,SAASa,EAAY,CAAE,SAAAb,GAAqC,CAC/D,MAAMS,EAAgBJ,EAAA,EAChBS,EAAwBC,EAAAA,OAAO,EAAK,EAE1CH,OAAAA,EAAAA,UAAU,IAAM,CACZ,MAAMI,EAAcP,EAAc,QAAQ,iBACtC,2BACA,IAAM,CACFK,EAAsB,QAAU,EACpC,CAAA,EAGJ,MAAO,IAAME,EAAA,CACjB,EAAG,CAACP,EAAc,OAAO,CAAC,EAK1BG,EAAAA,UAAU,IAAM,CACRE,EAAsB,SACtBL,EAAc,iBAAA,CAEtB,EAAG,CAACT,EAAUS,CAAa,CAAC,oBAElB,SAAAT,EAAS,CACvB,CC5BO,SAASiB,EAAW,CAAE,SAAAjB,GAA2C,CACpE,yBAAU,SAAAA,EAAS,CACvB,CCAO,SAASkB,EAAW,CAAE,SAAAl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AAaF,CAAO,CAAC,EAElBtF,EAAAA,QACH,KAAO,CACH,MAAO,IAAM,CACLuF,EAAU,SAEdC,EACI,IAAI,QAAeE,GAAY,CAC3BH,EAAU,QAAUG,CACxB,CAAC,CAAA,CAET,EACA,QAAS,IAAM,CACXH,EAAU,UAAA,EACVA,EAAU,QAAU,IACxB,CAAA,GAEJ,CAACC,CAAW,CAAA,CAEpB,CC9CA,SAASG,EAAQC,EAA6C,CAC1D,IAAIN,EAA6B,KAEjC,MAAO,KACEA,IACDA,EAAUM,EAAA,GAEPN,EAEf,CAIO,MAAMO,EAAWF,EAAK,SAAY,CACrC,GAAI,EAAEG,EAAAA,4BAA4B,QAC9B,MAAM,IAAI,MACN,oFAAA,EAIR,MAAMC,EAAU,MAAM,OAAOD,EAAAA,wBAAwB,IAAA,EACrD,OAAOC,EAAW,KAAK,MAAMA,CAAO,EAAgB,IACxD,CAAC,EAEM,SAASC,EACZC,EACqB,CACrB,OAAOZ,EAAqBQ,EAAA,EAAW,MAAM,IAAMI,CAAY,CAAC,CAGpE"}
|
|
1
|
+
{"version":3,"file":"paprize-react.umd.cjs","sources":["../src/components/ReportPreview.tsx","../src/internal/useReportBuilder.ts","../src/components/ReportRoot.tsx","../src/components/PageContent.tsx","../src/components/PageFooter.tsx","../src/components/PageHeader.tsx","../src/components/SectionFooter.tsx","../src/components/SectionHeader.tsx","../src/components/PageOverlay.tsx","../src/internal/parseSectionChildren.ts","../src/internal/SectionIdContext.ts","../src/internal/PageInfoContext.ts","../src/components/Page.tsx","../src/internal/SectionControllerContext.ts","../src/internal/useSectionControllerState.tsx","../src/internal/SectionLayout.tsx","../src/components/Section.tsx","../src/components/PageBreak.tsx","../src/components/Layout.tsx","../src/components/usePageInfo.ts","../src/components/useSectionInfo.ts","../src/internal/eventHelper.ts","../src/components/useReportInfo.ts","../src/components/useSectionSuspension.ts","../src/components/useJsonData.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { previewClassName } from '@paprize/core/src';\n\nexport function ReportPreview({ children }: { children: ReactNode }) {\n return <div className={previewClassName}>{children}</div>;\n}\n","import type { ReportBuilder } from '@paprize/core/src';\nimport { createContext, useContext } from 'react';\n\nexport const ReportBuilderContext = createContext<ReportBuilder | null>(null);\n\nexport function useReportBuilder() {\n const context = useContext(ReportBuilderContext);\n if (!context) {\n throw new Error(\n 'ReportRoot is missing. Please wrap your component tree with ReportRoot component.'\n );\n }\n\n return context;\n}\n","import { useEffect, useMemo, type ReactNode } from 'react';\nimport { ReportBuilder } from '@paprize/core/src';\nimport { ReportBuilderContext } from '../internal/useReportBuilder';\n\nexport interface ReportRootProps {\n children: ReactNode;\n}\n\nexport function ReportRoot({ children }: ReportRootProps) {\n const reportBuilder = useMemo(() => new ReportBuilder(), []);\n\n useEffect(() => {\n reportBuilder.schedulePagination();\n }, [reportBuilder]);\n\n return (\n <ReportBuilderContext value={reportBuilder}>\n {children}\n </ReportBuilderContext>\n );\n}\n","import { useEffect, useRef, type ReactNode } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\n\nexport function PageContent({ children }: { children: ReactNode }) {\n const reportBuilder = useReportBuilder();\n const isFirstCycleCompleted = useRef(false);\n\n useEffect(() => {\n const unsubscribe = reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n () => {\n isFirstCycleCompleted.current = true;\n }\n );\n\n return () => unsubscribe();\n }, [reportBuilder.monitor]);\n\n // If the children change after the first pagination cycle, we need to re-paginate\n // this can happen if the content is dynamic or loaded asynchronously\n // if we don't do this, the new content will be ignored in the pagination\n useEffect(() => {\n if (isFirstCycleCompleted.current) {\n reportBuilder.schedulePagination();\n }\n }, [children, reportBuilder]);\n\n return <>{children}</>;\n}\n","export function PageFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageHeader({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionFooter({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","export function SectionHeader({ children }: { children: React.ReactNode }) {\n return <>{children}</>;\n}\n","import type { ReactNode } from 'react';\n\nexport function PageOverlay({ children }: { children: ReactNode }) {\n return <>{children}</>;\n}\n","import {\n Children,\n isValidElement,\n type FC,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { PageContent } from '../components/PageContent';\nimport { PageFooter } from '../components/PageFooter';\nimport { PageHeader } from '../components/PageHeader';\nimport { SectionFooter } from '../components/SectionFooter';\nimport { SectionHeader } from '../components/SectionHeader';\nimport { PageOverlay } from '../components/PageOverlay';\n\nconst validChildren: FC<{ children: ReactNode }>[] = [\n PageContent,\n PageHeader,\n PageFooter,\n PageOverlay,\n SectionHeader,\n SectionFooter,\n];\n\nexport interface PageElements {\n content: ReactElement;\n header?: ReactElement;\n footer?: ReactElement;\n overlay?: ReactElement;\n sectionHeader?: ReactElement;\n sectionFooter?: ReactElement;\n}\n\nfunction parseSectionChildren(children: ReactNode): PageElements {\n let content: ReactElement | null = null;\n const pageElements: Partial<PageElements> = {};\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n throw new Error(\n `Invalid React element found in children: ${child}`,\n {\n cause: { child },\n }\n );\n }\n\n const component = validChildren.find((x) => x === child.type);\n if (!component) {\n throw Error(\n `Component \"${child.type}\" is not valid as a child for Section, Expected one of: ${validChildren\n .map((x) => x.name)\n .join(',')}`\n );\n }\n\n switch (component) {\n case SectionHeader:\n pageElements.sectionHeader = child;\n break;\n\n case SectionFooter:\n pageElements.sectionFooter = child;\n break;\n\n case PageContent:\n content = child;\n break;\n\n case PageHeader:\n pageElements.header = child;\n break;\n\n case PageFooter:\n pageElements.footer = child;\n break;\n\n case PageOverlay:\n pageElements.overlay = child;\n break;\n }\n });\n\n if (!content) {\n throw Error('PageContent component is a required child for Section');\n }\n\n return { ...pageElements, content: content };\n}\n\nexport default parseSectionChildren;\n","import { createContext } from 'react';\n\nexport const SectionIdContext = createContext<string>('');\n","import { createContext } from 'react';\n\nexport const PageInfoContext = createContext<{\n pageIndex: number;\n totalPages: number;\n}>({\n pageIndex: 0,\n totalPages: 0,\n});\n","import { useContext, useMemo, type Ref } from 'react';\nimport { type PageElements } from '../internal/parseSectionChildren';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n pageClassName,\n pageMargin,\n reportStyles,\n type PageSize,\n type PageMargin,\n} from '@paprize/core/src';\n\nexport interface PageProps {\n elements: PageElements;\n size: PageSize;\n margin?: PageMargin;\n pageIndex: number;\n totalPages: number;\n ref?: Ref<HTMLDivElement>;\n sectionHeaderRef?: Ref<HTMLDivElement>;\n sectionFooterRef?: Ref<HTMLDivElement>;\n pageHeaderRef?: Ref<HTMLDivElement>;\n pageFooterRef?: Ref<HTMLDivElement>;\n contentRef?: Ref<HTMLDivElement>;\n}\n\nexport function Page({\n elements,\n size,\n margin,\n pageIndex,\n totalPages,\n ref,\n sectionHeaderRef,\n sectionFooterRef,\n pageHeaderRef,\n pageFooterRef,\n contentRef,\n}: PageProps) {\n const sectionId = useContext(SectionIdContext);\n const contextValue = useMemo(\n () => ({ pageIndex, totalPages }),\n [pageIndex, totalPages]\n );\n\n return (\n <PageInfoContext value={contextValue}>\n <div\n id={`${sectionId}-${pageIndex}`}\n className={pageClassName}\n ref={ref}\n style={reportStyles.page(size, margin ?? pageMargin.None)}\n >\n {elements.sectionHeader && pageIndex === 0 && (\n <div style={reportStyles.component} ref={sectionHeaderRef}>\n {elements.sectionHeader}\n </div>\n )}\n {elements.header && (\n <div style={reportStyles.component} ref={pageHeaderRef}>\n {elements.header}\n </div>\n )}\n\n <div style={reportStyles.pageContent} ref={contentRef}>\n {elements.content}\n </div>\n\n {elements.overlay && (\n <div style={reportStyles.overlay}>{elements.overlay}</div>\n )}\n\n {(elements.footer || elements.sectionFooter) && (\n <div\n style={{ ...reportStyles.component, marginTop: 'auto' }}\n >\n {elements.footer && (\n <div\n style={reportStyles.component}\n ref={pageFooterRef}\n >\n {elements.footer}\n </div>\n )}\n {elements.sectionFooter &&\n pageIndex === totalPages - 1 && (\n <div\n style={reportStyles.component}\n ref={sectionFooterRef}\n >\n {elements.sectionFooter}\n </div>\n )}\n </div>\n )}\n </div>\n </PageInfoContext>\n );\n}\n","import type { PaginationPlugin } from '@paprize/core/src';\nimport { createContext } from 'react';\n\nexport interface SectionController {\n addPlugin: (plugin: PaginationPlugin) => void;\n addSuspense: (suspense: Promise<void>) => void;\n}\n\nexport const SectionControllerContext = createContext<SectionController>({\n addPlugin: () => {\n throw new Error('addPlugin must be used within a Section');\n },\n addSuspense: () => {\n throw new Error('addSuspense must be used within a Section');\n },\n});\n","import { useMemo } from 'react';\nimport { type SectionController } from './SectionControllerContext';\nimport type { PaginationPlugin } from '@paprize/core/src';\n\nexport function useSectionControllerState(plugins?: PaginationPlugin[]) {\n const state = useMemo(\n () => ({\n plugins: plugins ?? ([] as PaginationPlugin[]),\n suspense: [] as Promise<void>[],\n }),\n [plugins]\n );\n\n const sectionController: SectionController = useMemo(\n () => ({\n addPlugin: (plugin: PaginationPlugin) => {\n state.plugins.push(plugin);\n },\n addSuspense: (suspense: Promise<void>) => {\n state.suspense.push(suspense);\n },\n }),\n [state]\n );\n\n return {\n controllerState: state,\n controllerValue: sectionController,\n };\n}\n","import {\n adjustPageSize,\n logger,\n reportStyles,\n type PageContext,\n type SectionOptions,\n} from '@paprize/core/src';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { Page } from '../components/Page';\nimport { useReportBuilder } from './useReportBuilder';\nimport { SectionIdContext } from './SectionIdContext';\nimport type { PageElements } from './parseSectionChildren';\nimport { useSectionControllerState } from './useSectionControllerState';\nimport { SectionControllerContext } from './SectionControllerContext';\n\nexport interface SectionLayoutProps {\n elements: PageElements;\n options: SectionOptions;\n}\n\nexport function SectionLayout({ elements, options }: SectionLayoutProps) {\n const sectionId = useContext(SectionIdContext);\n const { controllerState, controllerValue } = useSectionControllerState(\n options?.plugins\n );\n const reportBuilder = useReportBuilder();\n const pageRef = useRef<HTMLDivElement>(null);\n const sectionHeaderRef = useRef<HTMLDivElement>(null);\n const sectionFooterRef = useRef<HTMLDivElement>(null);\n const pageHeaderRef = useRef<HTMLDivElement>(null);\n const pageFooterRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const realizedSize = useMemo(\n () => adjustPageSize(options.size, options.orientation),\n [options.orientation, options.size]\n );\n const [pageContexts, setPageContexts] = useState<PageContext[] | null>(\n null\n );\n\n useEffect(() => {\n if (!contentRef.current) {\n return;\n }\n\n reportBuilder\n .tryAddSection(\n {\n ...options,\n id: sectionId,\n plugins: controllerState.plugins,\n suspense: controllerState.suspense,\n },\n {\n pageContent: contentRef.current,\n sectionHeader: sectionHeaderRef.current,\n sectionFooter: sectionFooterRef.current,\n pageFooter: pageFooterRef.current,\n pageHeader: pageHeaderRef.current,\n },\n (pages) => {\n setPageContexts(pages);\n }\n )\n .catch((e) => logger.error(e));\n\n return () => {\n reportBuilder.removeSection(sectionId);\n };\n }, [\n controllerState.plugins,\n controllerState.suspense,\n options,\n reportBuilder,\n sectionId,\n ]);\n\n return (\n <SectionControllerContext value={controllerValue}>\n {pageContexts?.map((pageContext) => (\n <Page\n key={pageContext.pageIndex}\n elements={{\n ...elements,\n content: (\n <div\n style={{ display: 'contents' }}\n dangerouslySetInnerHTML={{\n __html: pageContext.pageContentHtml,\n }}\n />\n ),\n }}\n size={realizedSize}\n margin={options.margin}\n pageIndex={pageContext.pageIndex}\n totalPages={pageContext.totalPages}\n />\n ))}\n\n {createPortal(\n <div style={reportStyles.outOfScreen}>\n <Page\n elements={elements}\n size={realizedSize}\n margin={options.margin}\n pageIndex={0}\n totalPages={1}\n ref={pageRef}\n sectionHeaderRef={sectionHeaderRef}\n sectionFooterRef={sectionFooterRef}\n pageHeaderRef={pageHeaderRef}\n pageFooterRef={pageFooterRef}\n contentRef={contentRef}\n />\n </div>,\n document.body\n )}\n </SectionControllerContext>\n );\n}\n","import { useMemo, type ReactNode } from 'react';\nimport parseSectionChildren from '../internal/parseSectionChildren';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport {\n reportStyles,\n sectionClassName,\n type SectionOptions,\n} from '@paprize/core/src';\nimport { SectionLayout } from '../internal/SectionLayout';\n\n/**\n * Configuration options for a section.\n * @inlineType SectionOptions\n */\nexport interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {\n children: ReactNode;\n /**\n * Unique id of the section within the report. If not set, a random id will be used.\n */\n id?: string;\n}\n\nlet sectionIdCounter = 1;\n\nexport function Section({ children, id, ...options }: SectionProps) {\n const sectionId = useMemo(() => id ?? `__000${sectionIdCounter++}`, [id]);\n const elements = useMemo(() => parseSectionChildren(children), [children]);\n const sectionOptions = useMemo(\n () => ({\n ...options,\n id: sectionId,\n }),\n [options, sectionId]\n );\n\n return (\n <section\n className={sectionClassName}\n id={sectionId}\n style={reportStyles.section(sectionId)}\n >\n <SectionIdContext value={sectionId}>\n <SectionLayout elements={elements} options={sectionOptions} />\n </SectionIdContext>\n </section>\n );\n}\n","import { pageBreakAttributeName } from '@paprize/core/src';\n\nexport function PageBreak() {\n return <span {...{ [pageBreakAttributeName]: 'true' }} />;\n}\n","import {\n layoutOptionsToAttributes,\n type LayoutOptions,\n} from '@paprize/core/src';\n\nexport interface LayoutProps extends LayoutOptions {\n children: React.ReactNode;\n}\n\nexport function Layout({ children, ...attributes }: LayoutProps) {\n return (\n <div\n style={{ display: 'contents' }}\n {...layoutOptionsToAttributes(attributes)}\n >\n {children}\n </div>\n );\n}\n","import { useContext } from 'react';\nimport { PageInfoContext } from '../internal/PageInfoContext';\nimport type { PageInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current page.\n */\nexport const usePageInfo = (): PageInfo => {\n const pageContext = useContext(PageInfoContext);\n\n return {\n pageIndex: pageContext.pageIndex,\n totalPages: pageContext.totalPages,\n };\n};\n","import { useContext, useRef, useSyncExternalStore } from 'react';\nimport type { SectionContext } from '@paprize/core/src';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { SectionIdContext } from '../internal/SectionIdContext';\nimport type { SectionInfo } from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the current section.\n */\nexport const useSectionInfo = (): SectionInfo => {\n const sectionId = useContext(SectionIdContext);\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<SectionContext>({\n pages: [],\n isPaginated: false,\n isSuspended: false,\n sectionIndex: -1,\n sectionId: sectionId,\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'sectionCompleted',\n (sc) => {\n if (sc.sectionId !== sectionId) return;\n stateRef.current = sc;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return {\n sectionId: sectionId,\n sectionIndex: state.sectionIndex,\n isSuspended: state.isSuspended,\n isPaginated: state.isPaginated,\n pages: state.pages.map((p) => ({\n pageIndex: p.pageIndex,\n totalPages: p.totalPages,\n })),\n };\n};\n","import type {\n PaginationCycleCompleted,\n SectionContext,\n} from '@paprize/core/src';\n\n/**\n * {@inheritDoc @paprize/core!PageContext}\n */\nexport interface PageInfo {\n /**\n * {@inheritDoc @paprize/core!PageContext.pageIndex}\n */\n pageIndex: number;\n /**\n * {@inheritDoc @paprize/core!PageContext.totalPages}\n */\n totalPages: number;\n}\n\n/**\n * {@inheritDoc @paprize/core!SectionContext}\n */\nexport interface SectionInfo {\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionId}\n */\n sectionId: string;\n /**\n * {@inheritDoc @paprize/core!SectionContext.sectionIndex}\n */\n sectionIndex: number;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isPaginated}\n */\n isPaginated: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.isSuspended}\n */\n isSuspended: boolean;\n /**\n * {@inheritDoc @paprize/core!SectionContext.pages}\n */\n pages: PageInfo[];\n}\n\n/**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted}\n */\n\nexport interface ReportInfo {\n /**\n * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}\n */\n sections: SectionInfo[];\n}\n\nexport function pageContextToPageInfo(pc: {\n pageIndex: number;\n totalPages: number;\n}): PageInfo {\n return {\n pageIndex: pc.pageIndex,\n totalPages: pc.totalPages,\n };\n}\n\nexport function sectionContextToSectionInfo(sc: SectionContext): SectionInfo {\n return {\n sectionId: sc.sectionId,\n sectionIndex: sc.sectionIndex,\n isPaginated: sc.isPaginated,\n isSuspended: sc.isSuspended,\n pages: sc.pages.map(pageContextToPageInfo),\n };\n}\n\nexport function paginationCycleToReportInfo(\n rc: PaginationCycleCompleted\n): ReportInfo {\n return {\n sections: rc.sections.map(sectionContextToSectionInfo),\n };\n}\n","import { useRef, useSyncExternalStore } from 'react';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport type { PaginationCycleCompleted } from '@paprize/core/src';\nimport {\n paginationCycleToReportInfo,\n type ReportInfo,\n} from '../internal/eventHelper';\n\n/**\n * React hook that returns information about the report.\n */\nexport function useReportInfo(): ReportInfo {\n const reportBuilder = useReportBuilder();\n const stateRef = useRef<PaginationCycleCompleted>({\n sections: [],\n });\n\n const state = useSyncExternalStore(\n (callback) => {\n return reportBuilder.monitor.addEventListener(\n 'paginationCycleCompleted',\n (pg) => {\n stateRef.current = pg;\n callback();\n }\n );\n },\n () => stateRef.current\n );\n\n return paginationCycleToReportInfo(state);\n}\n","import { useContext, useEffect, useMemo, useRef } from 'react';\nimport { SectionControllerContext } from '../internal/SectionControllerContext';\n\n/**\n * Controls the section suspension.\n * @inline\n */\nexport interface SectionSuspension {\n /**\n * Releases the suspension. The pagination engine will paginate this section immediately.\n */\n release: () => void;\n\n /**\n * Marks the suspension as pending again if it was previously resolved.\n * During the next pagination cycle (for example, if pagination is retriggered\n * by changes to the page content), this section will not be paginated\n * until `release` is called again.\n */\n reset: () => void;\n}\n\n/**\n * Suspends pagination for this section.\n * @param promise The suspension is tied to this promise. Once the promise is resolved,\n * the suspension is released and the pagination engine will paginate this section.\n */\nexport function useSectionSuspension(\n promise: Promise<void> | Promise<unknown>\n): void;\n/**\n * Suspends pagination for this section. You need to call the `release` method\n * of the returned value; otherwise, the pagination engine will never paginate this section.\n */\nexport function useSectionSuspension(): SectionSuspension;\nexport function useSectionSuspension(\n promise?: Promise<void> | Promise<unknown>\n) {\n const resolveFn = useRef<() => void | null>(null);\n const { addSuspense } = useContext(SectionControllerContext);\n\n useEffect(() => {\n if (resolveFn.current) {\n return;\n }\n\n const pr =\n promise ??\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n });\n resolveFn.current ||= () => {};\n\n addSuspense(pr as Promise<void>);\n }, [addSuspense, promise]);\n\n return useMemo(\n () => ({\n reset: () => {\n if (resolveFn.current) return;\n\n addSuspense(\n new Promise<void>((resolve) => {\n resolveFn.current = resolve;\n })\n );\n },\n release: () => {\n resolveFn.current?.();\n resolveFn.current = null;\n },\n }),\n [addSuspense]\n );\n}\n","import { useSectionSuspension } from './useSectionSuspension';\nimport { useReportBuilder } from '../internal/useReportBuilder';\nimport { useEffect, useMemo } from 'react';\n\n/**\n * {@inheritDoc @paprize/core!ReportBuilder.getJsonData}\n */\nexport function useJsonData<DataModel>(\n defaultValue?: DataModel\n): DataModel | null {\n const reportBuilder = useReportBuilder();\n const value = useMemo(\n () => ({\n current: null as DataModel | null,\n }),\n []\n );\n\n const promise = useMemo(\n () => reportBuilder.getJsonData(defaultValue),\n [defaultValue, reportBuilder]\n );\n\n useSectionSuspension(promise);\n\n useEffect(() => {\n promise.then((v) => (value.current = v));\n }, [promise, value]);\n\n return value.current ?? defaultValue ?? null;\n}\n"],"names":["ReportPreview","children","jsx","previewClassName","ReportBuilderContext","createContext","useReportBuilder","context","useContext","ReportRoot","reportBuilder","useMemo","ReportBuilder","useEffect","PageContent","isFirstCycleCompleted","useRef","unsubscribe","PageFooter","PageHeader","SectionFooter","SectionHeader","PageOverlay","validChildren","parseSectionChildren","content","pageElements","Children","child","isValidElement","component","x","SectionIdContext","PageInfoContext","Page","elements","size","margin","pageIndex","totalPages","ref","sectionHeaderRef","sectionFooterRef","pageHeaderRef","pageFooterRef","contentRef","sectionId","contextValue","jsxs","pageClassName","reportStyles","pageMargin","SectionControllerContext","useSectionControllerState","plugins","state","sectionController","plugin","suspense","SectionLayout","options","controllerState","controllerValue","pageRef","realizedSize","adjustPageSize","pageContexts","setPageContexts","useState","pages","e","logger","pageContext","createPortal","sectionIdCounter","Section","id","sectionOptions","sectionClassName","PageBreak","pageBreakAttributeName","Layout","attributes","layoutOptionsToAttributes","usePageInfo","useSectionInfo","stateRef","useSyncExternalStore","callback","sc","p","pageContextToPageInfo","pc","sectionContextToSectionInfo","paginationCycleToReportInfo","rc","useReportInfo","pg","useSectionSuspension","promise","resolveFn","addSuspense","pr","resolve","useJsonData","defaultValue","value","v"],"mappings":"mbAGO,SAASA,EAAc,CAAE,SAAAC,GAAqC,CACjE,OAAOC,EAAAA,IAAC,MAAA,CAAI,UAAWC,EAAAA,iBAAmB,SAAAF,CAAA,CAAS,CACvD,CCFO,MAAMG,EAAuBC,EAAAA,cAAoC,IAAI,EAErE,SAASC,GAAmB,CAC/B,MAAMC,EAAUC,EAAAA,WAAWJ,CAAoB,EAC/C,GAAI,CAACG,EACD,MAAM,IAAI,MACN,mFAAA,EAIR,OAAOA,CACX,CCNO,SAASE,EAAW,CAAE,SAAAR,GAA6B,CACtD,MAAMS,EAAgBC,EAAAA,QAAQ,IAAM,IAAIC,EAAAA,cAAiB,CAAA,CAAE,EAE3DC,OAAAA,EAAAA,UAAU,IAAM,CACZH,EAAc,mBAAA,CAClB,EAAG,CAACA,CAAa,CAAC,EAGdR,EAAAA,IAACE,EAAA,CAAqB,MAAOM,EACxB,SAAAT,CAAA,CACL,CAER,CCjBO,SAASa,EAAY,CAAE,SAAAb,GAAqC,CAC/D,MAAMS,EAAgBJ,EAAA,EAChBS,EAAwBC,EAAAA,OAAO,EAAK,EAE1CH,OAAAA,EAAAA,UAAU,IAAM,CACZ,MAAMI,EAAcP,EAAc,QAAQ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