@paprize/react 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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
- ![Components](https://raw.githubusercontent.com/PejmanNik/paprize/refs/heads/bootstrap/packages/website/static/img/components.svg)
5
+ ![Components](https://raw.githubusercontent.com/PejmanNik/paprize/refs/heads/main/packages/website/static/img/components.svg)
@@ -1,20 +1,17 @@
1
- import { ConfigAttribute } from '@paprize/core';
2
1
  import { Context } from 'react';
3
2
  import { JSX } from 'react/jsx-runtime';
4
- import { PageDimension } from '@paprize/core';
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';
8
+ import { SectionOptions } from '@paprize/core';
12
9
 
13
10
  export declare const jsonData: () => Promise<unknown>;
14
11
 
15
12
  export declare function Layout({ children, ...attributes }: LayoutProps): JSX.Element;
16
13
 
17
- export declare interface LayoutProps extends ConfigAttribute {
14
+ export declare interface LayoutProps extends LayoutOptions {
18
15
  children: React.ReactNode;
19
16
  }
20
17
 
@@ -25,7 +22,7 @@ export declare function PageContent({ children }: {
25
22
  }): JSX.Element;
26
23
 
27
24
  export declare function pageContextToPageInfo(pc: {
28
- index: number;
25
+ pageIndex: number;
29
26
  totalPages: number;
30
27
  }): PageInfo;
31
28
 
@@ -37,8 +34,17 @@ export declare function PageHeader({ children }: {
37
34
  children: ReactNode;
38
35
  }): JSX.Element;
39
36
 
37
+ /**
38
+ * {@inheritDoc @paprize/core!PageContext}
39
+ */
40
40
  export declare interface PageInfo {
41
+ /**
42
+ * {@inheritDoc @paprize/core!PageContext.pageIndex}
43
+ */
41
44
  pageIndex: number;
45
+ /**
46
+ * {@inheritDoc @paprize/core!PageContext.totalPages}
47
+ */
42
48
  totalPages: number;
43
49
  }
44
50
 
@@ -46,20 +52,18 @@ export declare function PageOverlay({ children }: {
46
52
  children: ReactNode;
47
53
  }): JSX.Element;
48
54
 
49
- export { PaginationConfig }
50
-
51
55
  export declare function paginationCycleToReportInfo(rc: PaginationCycleCompleted): ReportInfo;
52
56
 
53
- export { PaginationPlugin }
54
-
57
+ /**
58
+ * {@inheritDoc @paprize/core!PaginationCycleCompleted}
59
+ */
55
60
  export declare interface ReportInfo {
61
+ /**
62
+ * {@inheritDoc @paprize/core!PaginationCycleCompleted.sections}
63
+ */
56
64
  sections: SectionInfo[];
57
65
  }
58
66
 
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
67
  export declare function ReportPreview({ children }: {
64
68
  children: ReactNode;
65
69
  }): JSX.Element;
@@ -70,7 +74,7 @@ export declare interface ReportRootProps {
70
74
  children: ReactNode;
71
75
  }
72
76
 
73
- export declare function Section({ children, id, dimension, orientation, margin, config, }: SectionProps): JSX.Element;
77
+ export declare function Section({ children, id, ...options }: SectionProps): JSX.Element;
74
78
 
75
79
  export declare function sectionContextToSectionInfo(sc: SectionContext): SectionInfo;
76
80
 
@@ -89,39 +93,90 @@ export declare function SectionHeader({ children }: {
89
93
  children: React.ReactNode;
90
94
  }): JSX.Element;
91
95
 
96
+ /**
97
+ * {@inheritDoc @paprize/core!SectionContext}
98
+ */
92
99
  export declare interface SectionInfo {
100
+ /**
101
+ * {@inheritDoc @paprize/core!SectionContext.sectionId}
102
+ */
93
103
  sectionId: string;
104
+ /**
105
+ * {@inheritDoc @paprize/core!SectionContext.sectionIndex}
106
+ */
94
107
  sectionIndex: number;
108
+ /**
109
+ * {@inheritDoc @paprize/core!SectionContext.isPaginated}
110
+ */
95
111
  isPaginated: boolean;
112
+ /**
113
+ * {@inheritDoc @paprize/core!SectionContext.isSuspended}
114
+ */
96
115
  isSuspended: boolean;
116
+ /**
117
+ * {@inheritDoc @paprize/core!SectionContext.pages}
118
+ */
97
119
  pages: PageInfo[];
98
120
  }
99
121
 
100
- export declare interface SectionProps {
122
+ /**
123
+ * Configuration options for a section.
124
+ * @inlineType SectionOptions
125
+ */
126
+ export declare interface SectionProps extends Omit<SectionOptions, 'id' | 'suspense'> {
101
127
  children: ReactNode;
128
+ /**
129
+ * Unique id of the section within the report. If not set, a random id will be used.
130
+ */
102
131
  id?: string;
103
- dimension: PageDimension;
104
- orientation?: PageOrientation;
105
- margin?: PageMargin;
106
- config?: Partial<PaginationConfig>;
132
+ }
133
+
134
+ /**
135
+ * Controls the section suspension.
136
+ * @inline
137
+ */
138
+ export declare interface SectionSuspension {
139
+ /**
140
+ * Releases the suspension. The pagination engine will paginate this section immediately.
141
+ */
142
+ release: () => void;
143
+ /**
144
+ * Marks the suspension as pending again if it was previously resolved.
145
+ * During the next pagination cycle (for example, if pagination is retriggered
146
+ * by changes to the page content), this section will not be paginated
147
+ * until `release` is called again.
148
+ */
149
+ reset: () => void;
107
150
  }
108
151
 
109
152
  export declare function useJsonData<DataModel>(defaultValue?: DataModel): DataModel | undefined;
110
153
 
111
- export declare const usePageInfo: () => {
112
- pageIndex: number;
113
- totalPages: number;
114
- };
154
+ /**
155
+ * React hook that returns information about the current page.
156
+ */
157
+ export declare const usePageInfo: () => PageInfo;
115
158
 
159
+ /**
160
+ * React hook that returns information about the report.
161
+ */
116
162
  export declare function useReportInfo(): ReportInfo;
117
163
 
164
+ /**
165
+ * React hook that returns information about the current section.
166
+ */
118
167
  export declare const useSectionInfo: () => SectionInfo;
119
168
 
169
+ /**
170
+ * Suspends pagination for this section.
171
+ * @param promise The suspension is tied to this promise. Once the promise is resolved,
172
+ * the suspension is released and the pagination engine will paginate this section.
173
+ */
120
174
  export declare function useSectionSuspension(promise: Promise<void> | Promise<unknown>): void;
121
175
 
122
- export declare function useSectionSuspension(): {
123
- release: () => void;
124
- reset: () => void;
125
- };
176
+ /**
177
+ * Suspends pagination for this section. You need to call the `release` method
178
+ * of the returned value; otherwise, the pagination engine will never paginate this section.
179
+ */
180
+ export declare function useSectionSuspension(): SectionSuspension;
126
181
 
127
182
  export { }
@@ -1,153 +1,153 @@
1
- import { jsx as r, Fragment as f, jsxs as R } from "react/jsx-runtime";
2
- import { previewClassName as V, ReportBuilder as z, reportStyles as i, pageClassName as A, pageMargin as O, adjustDimension as q, sectionClassName as G, pageBreakAttributeName as K, configToAttributeMap as Q, paprize_readJsonDataFile as E } from "@paprize/core";
3
- import { createContext as h, useContext as g, useMemo as u, useEffect as S, useRef as c, Children as U, isValidElement as W, useState as X, useSyncExternalStore as H } from "react";
4
- import { createPortal as Y } from "react-dom";
5
- function fe({ children: e }) {
6
- return /* @__PURE__ */ r("div", { className: V, children: e });
1
+ import { jsx as r, Fragment as d, jsxs as x } from "react/jsx-runtime";
2
+ import { previewClassName as O, ReportBuilder as J, reportStyles as a, pageClassName as V, pageMargin as A, adjustPageSize as M, sectionClassName as q, pageBreakAttributeName as G, layoutOptionsToAttributes as K, paprize_readJsonDataFile as R } from "@paprize/core";
3
+ import { createContext as C, useContext as p, useMemo as u, useEffect as g, useRef as c, Children as Q, isValidElement as U, useState as W, useSyncExternalStore as b } from "react";
4
+ import { createPortal as X } from "react-dom";
5
+ function pe({ children: e }) {
6
+ return /* @__PURE__ */ r("div", { className: O, children: e });
7
7
  }
8
- const B = h(null);
9
- function w() {
10
- const e = g(B);
8
+ const H = C(null);
9
+ function h() {
10
+ const e = p(H);
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 ge({ children: e }) {
18
- const t = u(() => new z(), []);
19
- return S(() => {
20
- t.schedulePaginate();
21
- }, [t]), /* @__PURE__ */ r(B, { value: t, children: e });
17
+ function fe({ children: e }) {
18
+ const n = u(() => new J(), []);
19
+ return g(() => {
20
+ n.schedulePagination();
21
+ }, [n]), /* @__PURE__ */ r(H, { value: n, children: e });
22
22
  }
23
- function N({ children: e }) {
24
- const t = w(), o = c(!1);
25
- return S(() => {
26
- const n = t.monitor.addEventListener(
23
+ function z({ children: e }) {
24
+ const n = h(), o = c(!1);
25
+ return g(() => {
26
+ const t = n.monitor.addEventListener(
27
27
  "paginationCycleCompleted",
28
28
  () => {
29
29
  o.current = !0;
30
30
  }
31
31
  );
32
- return () => n();
33
- }, [t.monitor]), S(() => {
34
- o.current && t.schedulePaginate();
35
- }, [e, t]), /* @__PURE__ */ r(f, { children: e });
32
+ return () => t();
33
+ }, [n.monitor]), g(() => {
34
+ o.current && n.schedulePagination();
35
+ }, [e, n]), /* @__PURE__ */ r(d, { children: e });
36
36
  }
37
- function k({ children: e }) {
38
- return /* @__PURE__ */ r(f, { children: e });
37
+ function B({ children: e }) {
38
+ return /* @__PURE__ */ r(d, { children: e });
39
39
  }
40
- function D({ children: e }) {
41
- return /* @__PURE__ */ r(f, { children: e });
40
+ function N({ children: e }) {
41
+ return /* @__PURE__ */ r(d, { children: e });
42
42
  }
43
- function T({ children: e }) {
44
- return /* @__PURE__ */ r(f, { children: e });
43
+ function k({ children: e }) {
44
+ return /* @__PURE__ */ r(d, { children: e });
45
45
  }
46
- function j({ children: e }) {
47
- return /* @__PURE__ */ r(f, { children: e });
46
+ function T({ children: e }) {
47
+ return /* @__PURE__ */ r(d, { children: e });
48
48
  }
49
49
  function L({ children: e }) {
50
- return /* @__PURE__ */ r(f, { children: e });
50
+ return /* @__PURE__ */ r(d, { children: e });
51
51
  }
52
- const F = [
52
+ const E = [
53
+ z,
53
54
  N,
54
- D,
55
- k,
55
+ B,
56
56
  L,
57
- j,
58
- T
57
+ T,
58
+ k
59
59
  ];
60
- function Z(e) {
61
- let t = null;
60
+ function Y(e) {
61
+ let n = null;
62
62
  const o = {};
63
- if (U.forEach(e, (n) => {
64
- if (!W(n))
63
+ if (Q.forEach(e, (t) => {
64
+ if (!U(t))
65
65
  throw new Error(
66
- `Invalid React element found in children: ${n}`,
66
+ `Invalid React element found in children: ${t}`,
67
67
  {
68
- cause: { child: n }
68
+ cause: { child: t }
69
69
  }
70
70
  );
71
- const s = F.find((a) => a === n.type);
71
+ const s = E.find((i) => i === t.type);
72
72
  if (!s)
73
73
  throw Error(
74
- `Component "${n.type}" is not valid as a child for Section, Expected one of: ${F.map((a) => a.name).join(",")}`
74
+ `Component "${t.type}" is not valid as a child for Section, Expected one of: ${E.map((i) => i.name).join(",")}`
75
75
  );
76
76
  switch (s) {
77
- case j:
78
- o.sectionHeader = n;
79
- break;
80
77
  case T:
81
- o.sectionFooter = n;
78
+ o.sectionHeader = t;
82
79
  break;
83
- case N:
84
- t = n;
80
+ case k:
81
+ o.sectionFooter = t;
85
82
  break;
86
- case D:
87
- o.header = n;
83
+ case z:
84
+ n = t;
88
85
  break;
89
- case k:
90
- o.footer = n;
86
+ case N:
87
+ o.header = t;
88
+ break;
89
+ case B:
90
+ o.footer = t;
91
91
  break;
92
92
  case L:
93
- o.overlay = n;
93
+ o.overlay = t;
94
94
  break;
95
95
  }
96
- }), !t)
96
+ }), !n)
97
97
  throw Error("PageContent component is a required child for Section");
98
- return { ...o, content: t };
98
+ return { ...o, content: n };
99
99
  }
100
- const x = h(""), _ = h({
100
+ const I = C(""), _ = C({
101
101
  pageIndex: 0,
102
102
  totalPages: 0
103
103
  });
104
- function b({
104
+ function F({
105
105
  elements: e,
106
- dimension: t,
106
+ size: n,
107
107
  margin: o,
108
- pageIndex: n,
108
+ pageIndex: t,
109
109
  totalPages: s,
110
- ref: a,
111
- sectionHeaderRef: l,
112
- sectionFooterRef: d,
113
- pageHeaderRef: m,
110
+ ref: i,
111
+ sectionHeaderRef: w,
112
+ sectionFooterRef: m,
113
+ pageHeaderRef: S,
114
114
  pageFooterRef: y,
115
115
  contentRef: P
116
116
  }) {
117
- const v = g(x), C = u(
118
- () => ({ pageIndex: n, totalPages: s }),
119
- [n, s]
117
+ const f = p(I), v = u(
118
+ () => ({ pageIndex: t, totalPages: s }),
119
+ [t, s]
120
120
  );
121
- return /* @__PURE__ */ r(_, { value: C, children: /* @__PURE__ */ R(
121
+ return /* @__PURE__ */ r(_, { value: v, children: /* @__PURE__ */ x(
122
122
  "div",
123
123
  {
124
- id: `${v}-${n}`,
125
- className: A,
126
- ref: a,
127
- style: i.page(t, o ?? O.None),
124
+ id: `${f}-${t}`,
125
+ className: V,
126
+ ref: i,
127
+ style: a.page(n, o ?? A.None),
128
128
  children: [
129
- e.sectionHeader && n === 0 && /* @__PURE__ */ r("div", { style: i.component, ref: l, children: e.sectionHeader }),
130
- e.header && /* @__PURE__ */ r("div", { style: i.component, ref: m, children: e.header }),
131
- /* @__PURE__ */ r("div", { style: i.pageContent, ref: P, children: e.content }),
132
- e.overlay && /* @__PURE__ */ r("div", { style: i.overlay, children: e.overlay }),
133
- (e.footer || e.sectionFooter) && /* @__PURE__ */ R(
129
+ e.sectionHeader && t === 0 && /* @__PURE__ */ r("div", { style: a.component, ref: w, children: e.sectionHeader }),
130
+ e.header && /* @__PURE__ */ r("div", { style: a.component, ref: S, children: e.header }),
131
+ /* @__PURE__ */ r("div", { style: a.pageContent, ref: P, children: e.content }),
132
+ e.overlay && /* @__PURE__ */ r("div", { style: a.overlay, children: e.overlay }),
133
+ (e.footer || e.sectionFooter) && /* @__PURE__ */ x(
134
134
  "div",
135
135
  {
136
- style: { ...i.component, marginTop: "auto" },
136
+ style: { ...a.component, marginTop: "auto" },
137
137
  children: [
138
138
  e.footer && /* @__PURE__ */ r(
139
139
  "div",
140
140
  {
141
- style: i.component,
141
+ style: a.component,
142
142
  ref: y,
143
143
  children: e.footer
144
144
  }
145
145
  ),
146
- e.sectionFooter && n === s - 1 && /* @__PURE__ */ r(
146
+ e.sectionFooter && t === s - 1 && /* @__PURE__ */ r(
147
147
  "div",
148
148
  {
149
- style: i.component,
150
- ref: d,
149
+ style: a.component,
150
+ ref: m,
151
151
  children: e.sectionFooter
152
152
  }
153
153
  )
@@ -158,7 +158,7 @@ function b({
158
158
  }
159
159
  ) });
160
160
  }
161
- const $ = h({
161
+ const $ = C({
162
162
  addPlugin: () => {
163
163
  throw new Error("addPlugin must be used within a Section");
164
164
  },
@@ -166,8 +166,8 @@ const $ = h({
166
166
  throw new Error("addSuspense must be used within a Section");
167
167
  }
168
168
  });
169
- function ee(e) {
170
- const t = u(
169
+ function Z(e) {
170
+ const n = u(
171
171
  () => ({
172
172
  plugins: e ?? [],
173
173
  suspense: []
@@ -175,58 +175,60 @@ function ee(e) {
175
175
  [e]
176
176
  ), o = u(
177
177
  () => ({
178
- addPlugin: (n) => {
179
- t.plugins.push(n);
178
+ addPlugin: (t) => {
179
+ n.plugins.push(t);
180
180
  },
181
- addSuspense: (n) => {
182
- t.suspense.push(n);
181
+ addSuspense: (t) => {
182
+ n.suspense.push(t);
183
183
  }
184
184
  }),
185
- [t]
185
+ [n]
186
186
  );
187
187
  return {
188
- controllerState: t,
188
+ controllerState: n,
189
189
  controllerValue: o
190
190
  };
191
191
  }
192
- function te({
193
- elements: e,
194
- dimension: t,
195
- margin: o,
196
- config: n
197
- }) {
198
- const s = g(x), { controllerState: a, controllerValue: l } = ee(
192
+ function ee({ elements: e, options: n }) {
193
+ const o = p(I), { controllerState: t, controllerValue: s } = Z(
199
194
  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(
195
+ ), i = h(), w = c(null), m = c(null), S = c(null), y = c(null), P = c(null), f = c(null), v = u(
196
+ () => M(n.size, n.orientation),
197
+ [n.orientation, n.size]
198
+ ), [j, D] = W(
201
199
  null
202
200
  );
203
- return S(() => {
204
- if (I.current)
205
- return d.tryAddSection(
201
+ return g(() => {
202
+ if (f.current)
203
+ return i.tryAddSection(
206
204
  {
207
205
  ...n,
208
- id: s,
209
- dimension: t,
210
- margin: o,
211
- plugins: a.plugins,
212
- suspense: a.suspense
206
+ id: o,
207
+ plugins: t.plugins,
208
+ suspense: t.suspense
213
209
  },
214
210
  {
215
- pageContent: I.current,
216
- sectionHeader: y.current,
217
- sectionFooter: P.current,
218
- pageFooter: C.current,
219
- pageHeader: v.current
211
+ pageContent: f.current,
212
+ sectionHeader: m.current,
213
+ sectionFooter: S.current,
214
+ pageFooter: P.current,
215
+ pageHeader: y.current
220
216
  },
221
- (p) => {
222
- M(p);
217
+ (l) => {
218
+ D(l);
223
219
  }
224
220
  ), () => {
225
- d.removeSection(s);
221
+ i.removeSection(o);
226
222
  };
227
- }, [n, a, t, o, d, s]), /* @__PURE__ */ R($, { value: l, children: [
228
- J?.map((p) => /* @__PURE__ */ r(
229
- b,
223
+ }, [
224
+ t.plugins,
225
+ t.suspense,
226
+ n,
227
+ i,
228
+ o
229
+ ]), /* @__PURE__ */ x($, { value: s, children: [
230
+ j?.map((l) => /* @__PURE__ */ r(
231
+ F,
230
232
  {
231
233
  elements: {
232
234
  ...e,
@@ -235,33 +237,33 @@ function te({
235
237
  {
236
238
  style: { display: "contents" },
237
239
  dangerouslySetInnerHTML: {
238
- __html: p.pageContentHtml
240
+ __html: l.pageContentHtml
239
241
  }
240
242
  }
241
243
  )
242
244
  },
243
- dimension: t,
244
- margin: o,
245
- pageIndex: p.index,
246
- totalPages: p.totalPages
245
+ size: v,
246
+ margin: n.margin,
247
+ pageIndex: l.pageIndex,
248
+ totalPages: l.totalPages
247
249
  },
248
- p.index
250
+ l.pageIndex
249
251
  )),
250
- Y(
251
- /* @__PURE__ */ r("div", { style: i.outOfScreen, children: /* @__PURE__ */ r(
252
- b,
252
+ X(
253
+ /* @__PURE__ */ r("div", { style: a.outOfScreen, children: /* @__PURE__ */ r(
254
+ F,
253
255
  {
254
256
  elements: e,
255
- dimension: t,
256
- margin: o,
257
+ size: v,
258
+ margin: n.margin,
257
259
  pageIndex: 0,
258
260
  totalPages: 1,
259
- ref: m,
260
- sectionHeaderRef: y,
261
- sectionFooterRef: P,
262
- pageHeaderRef: v,
263
- pageFooterRef: C,
264
- contentRef: I
261
+ ref: w,
262
+ sectionHeaderRef: m,
263
+ sectionFooterRef: S,
264
+ pageHeaderRef: y,
265
+ pageFooterRef: P,
266
+ contentRef: f
265
267
  }
266
268
  ) }),
267
269
  document.body
@@ -269,174 +271,162 @@ function te({
269
271
  ] });
270
272
  }
271
273
  let ne = 1;
272
- function me({
273
- children: e,
274
- id: t,
275
- dimension: o,
276
- orientation: n = "portrait",
277
- margin: s,
278
- config: a
279
- }) {
280
- const l = u(() => t ?? `__000${ne++}`, [t]), d = u(() => Z(e), [e]), m = u(
281
- () => q(o, n),
282
- [o, n]
274
+ function ge({ children: e, id: n, ...o }) {
275
+ const t = u(() => n ?? `__000${ne++}`, [n]), s = u(() => Y(e), [e]), i = u(
276
+ () => ({
277
+ ...o,
278
+ id: t
279
+ }),
280
+ [o, t]
283
281
  );
284
282
  return /* @__PURE__ */ r(
285
283
  "section",
286
284
  {
287
- className: G,
288
- id: l,
289
- style: i.section(l),
290
- children: /* @__PURE__ */ r(x, { value: l, 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: t,
287
+ style: a.section(t),
288
+ children: /* @__PURE__ */ r(I, { value: t, children: /* @__PURE__ */ r(ee, { elements: s, options: i }) })
299
289
  }
300
290
  );
301
291
  }
302
- function Se() {
303
- return /* @__PURE__ */ r("span", { [K]: "true" });
292
+ function me() {
293
+ return /* @__PURE__ */ r("span", { [G]: "true" });
304
294
  }
305
- function ye({ children: e, ...t }) {
295
+ function Se({ children: e, ...n }) {
306
296
  return /* @__PURE__ */ r(
307
297
  "div",
308
298
  {
309
299
  style: { display: "contents" },
310
- ...Q(t),
300
+ ...K(n),
311
301
  children: e
312
302
  }
313
303
  );
314
304
  }
315
- const Pe = () => {
316
- const e = g(_);
305
+ const ye = () => {
306
+ const e = p(_);
317
307
  return {
318
308
  pageIndex: e.pageIndex,
319
309
  totalPages: e.totalPages
320
310
  };
321
- }, ve = () => {
322
- const e = g(x), t = w(), o = c({
311
+ }, Pe = () => {
312
+ const e = p(I), n = h(), o = c({
323
313
  pages: [],
324
314
  isPaginated: !1,
325
315
  isSuspended: !1,
326
- index: -1,
316
+ sectionIndex: -1,
327
317
  sectionId: e
328
- }), n = H(
329
- (s) => t.monitor.addEventListener(
318
+ }), t = b(
319
+ (s) => n.monitor.addEventListener(
330
320
  "sectionCompleted",
331
- (a) => {
332
- a.sectionId === e && (o.current = a, s());
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.index,
340
- isSuspended: n.isSuspended,
341
- isPaginated: n.isPaginated,
342
- pages: n.pages.map((s) => ({
343
- pageIndex: s.index,
329
+ sectionIndex: t.sectionIndex,
330
+ isSuspended: t.isSuspended,
331
+ isPaginated: t.isPaginated,
332
+ pages: t.pages.map((s) => ({
333
+ pageIndex: s.pageIndex,
344
334
  totalPages: s.totalPages
345
335
  }))
346
336
  };
347
337
  };
348
- function oe(e) {
338
+ function te(e) {
349
339
  return {
350
- pageIndex: e.index,
340
+ pageIndex: e.pageIndex,
351
341
  totalPages: e.totalPages
352
342
  };
353
343
  }
354
- function re(e) {
344
+ function oe(e) {
355
345
  return {
356
346
  sectionId: e.sectionId,
357
- sectionIndex: e.index,
347
+ sectionIndex: e.sectionIndex,
358
348
  isPaginated: e.isPaginated,
359
349
  isSuspended: e.isSuspended,
360
- pages: e.pages.map(oe)
350
+ pages: e.pages.map(te)
361
351
  };
362
352
  }
363
- function se(e) {
353
+ function re(e) {
364
354
  return {
365
- sections: e.sections.map(re)
355
+ sections: e.sections.map(oe)
366
356
  };
367
357
  }
368
- function Ce() {
369
- const e = w(), t = c({
358
+ function ve() {
359
+ const e = h(), n = c({
370
360
  sections: []
371
- }), o = H(
372
- (n) => e.monitor.addEventListener(
361
+ }), o = b(
362
+ (t) => e.monitor.addEventListener(
373
363
  "paginationCycleCompleted",
374
364
  (s) => {
375
- t.current = s, n();
365
+ n.current = s, t();
376
366
  }
377
367
  ),
378
- () => t.current
368
+ () => n.current
379
369
  );
380
- return se(o);
370
+ return re(o);
381
371
  }
382
- function ae(e) {
383
- const t = c(null), { addSuspense: o } = g($);
384
- return S(() => {
385
- if (t.current)
372
+ function se(e) {
373
+ const n = c(null), { addSuspense: o } = p($);
374
+ return g(() => {
375
+ if (n.current)
386
376
  return;
387
- const n = e ?? new Promise((s) => {
388
- t.current = s;
377
+ const t = e ?? new Promise((s) => {
378
+ n.current = s;
389
379
  });
390
- t.current ||= () => {
391
- }, o(n);
380
+ n.current ||= () => {
381
+ }, o(t);
392
382
  }, [o, e]), u(
393
383
  () => ({
394
384
  reset: () => {
395
- t.current || o(
396
- new Promise((n) => {
397
- t.current = n;
385
+ n.current || o(
386
+ new Promise((t) => {
387
+ n.current = t;
398
388
  })
399
389
  );
400
390
  },
401
391
  release: () => {
402
- t.current?.(), t.current = null;
392
+ n.current?.(), n.current = null;
403
393
  }
404
394
  }),
405
395
  [o]
406
396
  );
407
397
  }
408
398
  function ie(e) {
409
- let t = null;
410
- return () => (t || (t = e()), t);
399
+ let n = null;
400
+ return () => (n || (n = e()), n);
411
401
  }
412
- const ce = ie(async () => {
413
- if (!(E in window))
402
+ const ae = ie(async () => {
403
+ if (!(R in window))
414
404
  throw new Error(
415
405
  "The function paprize_readJsonDataFile is not available in the current environment."
416
406
  );
417
- const e = await window[E]?.();
407
+ const e = await window[R]?.();
418
408
  return e ? JSON.parse(e) : null;
419
409
  });
420
- function he(e) {
421
- return ae(ce().catch(() => e));
410
+ function Ce(e) {
411
+ return se(ae().catch(() => e));
422
412
  }
423
413
  export {
424
- ye as Layout,
425
- Se as PageBreak,
426
- N as PageContent,
427
- k as PageFooter,
428
- D as PageHeader,
414
+ Se as Layout,
415
+ me as PageBreak,
416
+ z as PageContent,
417
+ B as PageFooter,
418
+ N as PageHeader,
429
419
  L as PageOverlay,
430
- fe as ReportPreview,
431
- ge as ReportRoot,
432
- me as Section,
433
- T as SectionFooter,
434
- j as SectionHeader,
435
- ce as jsonData,
436
- he as useJsonData,
437
- Pe as usePageInfo,
438
- Ce as useReportInfo,
439
- ve as useSectionInfo,
440
- ae as useSectionSuspension
420
+ pe as ReportPreview,
421
+ fe as ReportRoot,
422
+ ge as Section,
423
+ k as SectionFooter,
424
+ T as SectionHeader,
425
+ ae as jsonData,
426
+ Ce as useJsonData,
427
+ ye as usePageInfo,
428
+ ve as useReportInfo,
429
+ Pe as useSectionInfo,
430
+ se as useSectionSuspension
441
431
  };
442
432
  //# 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,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MO,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 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.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\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 { 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","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","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","lazy","factory","jsonData","paprize_readJsonDataFile","strData","useJsonData","defaultValue"],"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,MAAM,IAAIC,EAAA,GAAiB,CAAA,CAAE;AAE3D,SAAAC,EAAU,MAAM;AACZ,IAAAH,EAAc,mBAAA;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,EAAU,MAAM;AACZ,IAAIE,EAAsB,WACtBL,EAAc,mBAAA;AAAA,EAEtB,GAAG,CAACT,GAAUS,CAAa,CAAC,0BAElB,UAAAT,GAAS;AACvB;AC5BO,SAASiB,EAAW,EAAE,UAAAjB,KAA2C;A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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;ACvEA,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,2 +1,2 @@
1
- (function(a,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):(a=typeof globalThis<"u"?globalThis:a||self,r(a["paprize-react"]={},a.jsxRuntime,a.PaprizeCore,a.React,a.ReactDOM))})(this,(function(a,r,u,o,N){"use strict";function z({children:e}){return r.jsx("div",{className:u.previewClassName,children:e})}const b=o.createContext(null);function g(){const e=o.useContext(b);if(!e)throw new Error("ReportRoot is missing. Please wrap your component tree with ReportRoot component.");return e}function L({children:e}){const t=o.useMemo(()=>new u.ReportBuilder,[]);return o.useEffect(()=>{t.schedulePaginate()},[t]),r.jsx(b,{value:t,children:e})}function h({children:e}){const t=g(),s=o.useRef(!1);return o.useEffect(()=>{const n=t.monitor.addEventListener("paginationCycleCompleted",()=>{s.current=!0});return()=>n()},[t.monitor]),o.useEffect(()=>{s.current&&t.schedulePaginate()},[e,t]),r.jsx(r.Fragment,{children:e})}function w({children:e}){return r.jsx(r.Fragment,{children:e})}function I({children:e}){return r.jsx(r.Fragment,{children:e})}function F({children:e}){return r.jsx(r.Fragment,{children:e})}function E({children:e}){return r.jsx(r.Fragment,{children:e})}function m({children:e}){return r.jsx(r.Fragment,{children:e})}const H=[h,I,w,m,E,F];function _(e){let t=null;const s={};if(o.Children.forEach(e,n=>{if(!o.isValidElement(n))throw new Error(`Invalid React element found in children: ${n}`,{cause:{child:n}});const i=H.find(c=>c===n.type);if(!i)throw Error(`Component "${n.type}" is not valid as a child for Section, Expected one of: ${H.map(c=>c.name).join(",")}`);switch(i){case E:s.sectionHeader=n;break;case F:s.sectionFooter=n;break;case h:t=n;break;case I:s.header=n;break;case w:s.footer=n;break;case m:s.overlay=n;break}}),!t)throw Error("PageContent component is a required child for Section");return{...s,content:t}}const S=o.createContext(""),M=o.createContext({pageIndex:0,totalPages:0});function B({elements:e,dimension:t,margin:s,pageIndex:n,totalPages:i,ref:c,sectionHeaderRef:d,sectionFooterRef:l,pageHeaderRef:f,pageFooterRef:y,contentRef:P}){const C=o.useContext(S),v=o.useMemo(()=>({pageIndex:n,totalPages:i}),[n,i]);return r.jsx(M,{value:v,children:r.jsxs("div",{id:`${C}-${n}`,className:u.pageClassName,ref:c,style:u.reportStyles.page(t,s??u.pageMargin.None),children:[e.sectionHeader&&n===0&&r.jsx("div",{style:u.reportStyles.component,ref:d,children:e.sectionHeader}),e.header&&r.jsx("div",{style:u.reportStyles.component,ref:f,children:e.header}),r.jsx("div",{style:u.reportStyles.pageContent,ref:P,children:e.content}),e.overlay&&r.jsx("div",{style:u.reportStyles.overlay,children:e.overlay}),(e.footer||e.sectionFooter)&&r.jsxs("div",{style:{...u.reportStyles.component,marginTop:"auto"},children:[e.footer&&r.jsx("div",{style:u.reportStyles.component,ref:y,children:e.footer}),e.sectionFooter&&n===i-1&&r.jsx("div",{style:u.reportStyles.component,ref:l,children:e.sectionFooter})]})]})})}const D=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 J(e){const t=o.useMemo(()=>({plugins:e??[],suspense:[]}),[e]),s=o.useMemo(()=>({addPlugin:n=>{t.plugins.push(n)},addSuspense:n=>{t.suspense.push(n)}}),[t]);return{controllerState:t,controllerValue:s}}function O({elements:e,dimension:t,margin:s,config:n}){const i=o.useContext(S),{controllerState:c,controllerValue:d}=J(n?.plugins),l=g(),f=o.useRef(null),y=o.useRef(null),P=o.useRef(null),C=o.useRef(null),v=o.useRef(null),x=o.useRef(null),[Y,Z]=o.useState(null);return o.useEffect(()=>{if(x.current)return l.tryAddSection({...n,id:i,dimension:t,margin:s,plugins:c.plugins,suspense:c.suspense},{pageContent:x.current,sectionHeader:y.current,sectionFooter:P.current,pageFooter:v.current,pageHeader:C.current},p=>{Z(p)}),()=>{l.removeSection(i)}},[n,c,t,s,l,i]),r.jsxs(D,{value:d,children:[Y?.map(p=>r.jsx(B,{elements:{...e,content:r.jsx("div",{style:{display:"contents"},dangerouslySetInnerHTML:{__html:p.pageContentHtml}})},dimension:t,margin:s,pageIndex:p.index,totalPages:p.totalPages},p.index)),N.createPortal(r.jsx("div",{style:u.reportStyles.outOfScreen,children:r.jsx(B,{elements:e,dimension:t,margin:s,pageIndex:0,totalPages:1,ref:f,sectionHeaderRef:y,sectionFooterRef:P,pageHeaderRef:C,pageFooterRef:v,contentRef:x})}),document.body)]})}let R=1;function $({children:e,id:t,dimension:s,orientation:n="portrait",margin:i,config:c}){const d=o.useMemo(()=>t??`__000${R++}`,[t]),l=o.useMemo(()=>_(e),[e]),f=o.useMemo(()=>u.adjustDimension(s,n),[s,n]);return r.jsx("section",{className:u.sectionClassName,id:d,style:u.reportStyles.section(d),children:r.jsx(S,{value:d,children:r.jsx(O,{elements:l,dimension:f,margin:i,config:c})})})}function j(){return r.jsx("span",{[u.pageBreakAttributeName]:"true"})}function q({children:e,...t}){return r.jsx("div",{style:{display:"contents"},...u.configToAttributeMap(t),children:e})}const V=()=>{const e=o.useContext(M);return{pageIndex:e.pageIndex,totalPages:e.totalPages}},A=()=>{const e=o.useContext(S),t=g(),s=o.useRef({pages:[],isPaginated:!1,isSuspended:!1,index:-1,sectionId:e}),n=o.useSyncExternalStore(i=>t.monitor.addEventListener("sectionCompleted",c=>{c.sectionId===e&&(s.current=c,i())}),()=>s.current);return{sectionId:e,sectionIndex:n.index,isSuspended:n.isSuspended,isPaginated:n.isPaginated,pages:n.pages.map(i=>({pageIndex:i.index,totalPages:i.totalPages}))}};function G(e){return{pageIndex:e.index,totalPages:e.totalPages}}function K(e){return{sectionId:e.sectionId,sectionIndex:e.index,isPaginated:e.isPaginated,isSuspended:e.isSuspended,pages:e.pages.map(G)}}function Q(e){return{sections:e.sections.map(K)}}function U(){const e=g(),t=o.useRef({sections:[]}),s=o.useSyncExternalStore(n=>e.monitor.addEventListener("paginationCycleCompleted",i=>{t.current=i,n()}),()=>t.current);return Q(s)}function T(e){const t=o.useRef(null),{addSuspense:s}=o.useContext(D);return o.useEffect(()=>{if(t.current)return;const n=e??new Promise(i=>{t.current=i});t.current||=()=>{},s(n)},[s,e]),o.useMemo(()=>({reset:()=>{t.current||s(new Promise(n=>{t.current=n}))},release:()=>{t.current?.(),t.current=null}}),[s])}function W(e){let t=null;return()=>(t||(t=e()),t)}const k=W(async()=>{if(!(u.paprize_readJsonDataFile in window))throw new Error("The function paprize_readJsonDataFile is not available in the current environment.");const e=await window[u.paprize_readJsonDataFile]?.();return e?JSON.parse(e):null});function X(e){return T(k().catch(()=>e))}a.Layout=q,a.PageBreak=j,a.PageContent=h,a.PageFooter=w,a.PageHeader=I,a.PageOverlay=m,a.ReportPreview=z,a.ReportRoot=L,a.Section=$,a.SectionFooter=F,a.SectionHeader=E,a.jsonData=k,a.useJsonData=X,a.usePageInfo=V,a.useReportInfo=U,a.useSectionInfo=A,a.useSectionSuspension=T,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,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):(a=typeof globalThis<"u"?globalThis:a||self,r(a["paprize-react"]={},a.jsxRuntime,a.PaprizeCore,a.React,a.ReactDOM))})(this,(function(a,r,i,o,k){"use strict";function D({children:e}){return r.jsx("div",{className:i.previewClassName,children:e})}const x=o.createContext(null);function f(){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 i.ReportBuilder,[]);return o.useEffect(()=>{n.schedulePagination()},[n]),r.jsx(x,{value:n,children:e})}function v({children:e}){const n=f(),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 h({children:e}){return r.jsx(r.Fragment,{children:e})}function I({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 F({children:e}){return r.jsx(r.Fragment,{children:e})}const z=[v,I,h,F,w,m];function O(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=z.find(c=>c===t.type);if(!u)throw Error(`Component "${t.type}" is not valid as a child for Section, Expected one of: ${z.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 I:s.header=t;break;case h:s.footer=t;break;case F:s.overlay=t;break}}),!n)throw Error("PageContent component is a required child for Section");return{...s,content:n}}const p=o.createContext(""),b=o.createContext({pageIndex:0,totalPages:0});function H({elements:e,size:n,margin:s,pageIndex:t,totalPages:u,ref:c,sectionHeaderRef:E,sectionFooterRef:g,pageHeaderRef:S,pageFooterRef:y,contentRef:P}){const l=o.useContext(p),C=o.useMemo(()=>({pageIndex:t,totalPages:u}),[t,u]);return r.jsx(b,{value:C,children:r.jsxs("div",{id:`${l}-${t}`,className:i.pageClassName,ref:c,style:i.reportStyles.page(n,s??i.pageMargin.None),children:[e.sectionHeader&&t===0&&r.jsx("div",{style:i.reportStyles.component,ref:E,children:e.sectionHeader}),e.header&&r.jsx("div",{style:i.reportStyles.component,ref:S,children:e.header}),r.jsx("div",{style:i.reportStyles.pageContent,ref:P,children:e.content}),e.overlay&&r.jsx("div",{style:i.reportStyles.overlay,children:e.overlay}),(e.footer||e.sectionFooter)&&r.jsxs("div",{style:{...i.reportStyles.component,marginTop:"auto"},children:[e.footer&&r.jsx("div",{style:i.reportStyles.component,ref:y,children:e.footer}),e.sectionFooter&&t===u-1&&r.jsx("div",{style:i.reportStyles.component,ref:g,children:e.sectionFooter})]})]})})}const M=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 L(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 _({elements:e,options:n}){const s=o.useContext(p),{controllerState:t,controllerValue:u}=L(n?.plugins),c=f(),E=o.useRef(null),g=o.useRef(null),S=o.useRef(null),y=o.useRef(null),P=o.useRef(null),l=o.useRef(null),C=o.useMemo(()=>i.adjustPageSize(n.size,n.orientation),[n.orientation,n.size]),[X,Y]=o.useState(null);return o.useEffect(()=>{if(l.current)return c.tryAddSection({...n,id:s,plugins:t.plugins,suspense:t.suspense},{pageContent:l.current,sectionHeader:g.current,sectionFooter:S.current,pageFooter:P.current,pageHeader:y.current},d=>{Y(d)}),()=>{c.removeSection(s)}},[t.plugins,t.suspense,n,c,s]),r.jsxs(M,{value:u,children:[X?.map(d=>r.jsx(H,{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:i.reportStyles.outOfScreen,children:r.jsx(H,{elements:e,size:C,margin:n.margin,pageIndex:0,totalPages:1,ref:E,sectionHeaderRef:g,sectionFooterRef:S,pageHeaderRef:y,pageFooterRef:P,contentRef:l})}),document.body)]})}let J=1;function R({children:e,id:n,...s}){const t=o.useMemo(()=>n??`__000${J++}`,[n]),u=o.useMemo(()=>O(e),[e]),c=o.useMemo(()=>({...s,id:t}),[s,t]);return r.jsx("section",{className:i.sectionClassName,id:t,style:i.reportStyles.section(t),children:r.jsx(p,{value:t,children:r.jsx(_,{elements:u,options:c})})})}function $(){return r.jsx("span",{[i.pageBreakAttributeName]:"true"})}function q({children:e,...n}){return r.jsx("div",{style:{display:"contents"},...i.layoutOptionsToAttributes(n),children:e})}const j=()=>{const e=o.useContext(b);return{pageIndex:e.pageIndex,totalPages:e.totalPages}},V=()=>{const e=o.useContext(p),n=f(),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 A(e){return{pageIndex:e.pageIndex,totalPages:e.totalPages}}function G(e){return{sectionId:e.sectionId,sectionIndex:e.sectionIndex,isPaginated:e.isPaginated,isSuspended:e.isSuspended,pages:e.pages.map(A)}}function K(e){return{sections:e.sections.map(G)}}function Q(){const e=f(),n=o.useRef({sections:[]}),s=o.useSyncExternalStore(t=>e.monitor.addEventListener("paginationCycleCompleted",u=>{n.current=u,t()}),()=>n.current);return K(s)}function B(e){const n=o.useRef(null),{addSuspense:s}=o.useContext(M);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 U(e){let n=null;return()=>(n||(n=e()),n)}const T=U(async()=>{if(!(i.paprize_readJsonDataFile in window))throw new Error("The function paprize_readJsonDataFile is not available in the current environment.");const e=await window[i.paprize_readJsonDataFile]?.();return e?JSON.parse(e):null});function W(e){return B(T().catch(()=>e))}a.Layout=q,a.PageBreak=$,a.PageContent=v,a.PageFooter=h,a.PageHeader=I,a.PageOverlay=F,a.ReportPreview=D,a.ReportRoot=N,a.Section=R,a.SectionFooter=m,a.SectionHeader=w,a.jsonData=T,a.useJsonData=W,a.usePageInfo=j,a.useReportInfo=Q,a.useSectionInfo=V,a.useSectionSuspension=B,Object.defineProperty(a,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,S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AAU,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 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.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\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 { 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","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","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","lazy","factory","jsonData","paprize_readJsonDataFile","strData","useJsonData","defaultValue"],"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,iBACtC,2BACA,IAAM,CACFK,EAAsB,QAAU,EACpC,CAAA,EAGJ,MAAO,IAAME,EAAA,CACjB,EAAG,CAACP,EAA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AA,WAAW4C,CAAwB,EAE3DvC,OAAAA,EAAAA,UAAU,IAAM,CACZ,GAAIqF,EAAU,QACV,OAGJ,MAAME,EACFH,GACA,IAAI,QAAeI,GAAY,CAC3BH,EAAU,QAAUG,CACxB,CAAC,EACLH,EAAU,UAAY,IAAM,CAAC,EAE7BC,EAAYC,CAAmB,CACnC,EAAG,CAACD,EAAaF,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,CCvEA,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paprize/react",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "React library for creating professional, print-ready reports",
5
5
  "type": "module",
6
6
  "files": [