@formepdf/react 0.8.3 → 0.9.1
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/dist/index.d.ts +1 -1
- package/dist/serialize.js +47 -7
- package/dist/types.d.ts +11 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export type { FontRegistration } from './font.js';
|
|
|
7
7
|
export { createDataProxy, isRefMarker, isEachMarker, isExprMarker } from './template-proxy.js';
|
|
8
8
|
export { expr } from './expr.js';
|
|
9
9
|
export { render, renderToObject } from './render.js';
|
|
10
|
-
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps, TextRun, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
|
10
|
+
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps, TextRun, CertificationConfig, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
package/dist/serialize.js
CHANGED
|
@@ -66,13 +66,43 @@ function isDocumentType(type) {
|
|
|
66
66
|
function resolveElement(element) {
|
|
67
67
|
let resolved = element;
|
|
68
68
|
for (let i = 0; i < 10 && typeof resolved.type === 'function' && !isDocumentType(resolved.type); i++) {
|
|
69
|
-
const result = resolved.type
|
|
69
|
+
const result = callComponent(resolved.type, resolved.props);
|
|
70
70
|
if (!isValidElement(result))
|
|
71
71
|
break;
|
|
72
72
|
resolved = result;
|
|
73
73
|
}
|
|
74
74
|
return resolved;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Call a function component directly (outside React's render cycle).
|
|
78
|
+
* React Compiler injects `useMemoCache` hooks into compiled components,
|
|
79
|
+
* which throws when called outside a render context. We catch that and
|
|
80
|
+
* give a clear error message pointing to the `'use no memo'` directive.
|
|
81
|
+
*/
|
|
82
|
+
function callComponent(fn, props) {
|
|
83
|
+
try {
|
|
84
|
+
return fn(props);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err instanceof Error && /hook|useMemoCache|Invalid hook call/i.test(err.message)) {
|
|
88
|
+
const name = fn.displayName || fn.name || 'Unknown';
|
|
89
|
+
throw new Error(`Component "${name}" appears to be compiled by React Compiler, which injects hooks ` +
|
|
90
|
+
`that cannot run outside of React's render cycle. Forme's serialize() calls components ` +
|
|
91
|
+
`directly to walk the element tree.\n\n` +
|
|
92
|
+
`Fix: Add 'use no memo' at the top of the component to opt it out of React Compiler:\n\n` +
|
|
93
|
+
` function ${name}(props) {\n` +
|
|
94
|
+
` 'use no memo';\n` +
|
|
95
|
+
` return <Document>...</Document>;\n` +
|
|
96
|
+
` }\n\n` +
|
|
97
|
+
`Alternatively, call the component yourself before passing to renderDocument():\n\n` +
|
|
98
|
+
` const element = <${name} data={data} />;\n` +
|
|
99
|
+
` // becomes:\n` +
|
|
100
|
+
` const element = ${name}({ data });\n` +
|
|
101
|
+
` await renderDocument(element);`);
|
|
102
|
+
}
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
76
106
|
// ─── Public API ──────────────────────────────────────────────────────
|
|
77
107
|
/**
|
|
78
108
|
* Serialize a React element tree into a Forme JSON document object.
|
|
@@ -144,8 +174,13 @@ export function serialize(element) {
|
|
|
144
174
|
result.pdfa = props.pdfa;
|
|
145
175
|
if (props.pdfUa)
|
|
146
176
|
result.pdfUa = true;
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
const cert = props.certification ?? props.signature;
|
|
178
|
+
if (cert) {
|
|
179
|
+
if (props.signature && !props.certification) {
|
|
180
|
+
console.warn('[Forme] The `signature` prop is deprecated. Use `certification` instead.');
|
|
181
|
+
}
|
|
182
|
+
result.certification = cert;
|
|
183
|
+
}
|
|
149
184
|
if (mergedFonts.length > 0) {
|
|
150
185
|
result.fonts = mergedFonts;
|
|
151
186
|
}
|
|
@@ -304,7 +339,7 @@ function serializeChild(child, parent = null) {
|
|
|
304
339
|
}
|
|
305
340
|
// Unknown component — try to call it as a function component
|
|
306
341
|
if (typeof element.type === 'function') {
|
|
307
|
-
const result = element.type
|
|
342
|
+
const result = callComponent(element.type, element.props);
|
|
308
343
|
if (isValidElement(result)) {
|
|
309
344
|
return serializeChild(result, parent);
|
|
310
345
|
}
|
|
@@ -1504,8 +1539,13 @@ export function serializeTemplate(element) {
|
|
|
1504
1539
|
result.pdfa = props.pdfa;
|
|
1505
1540
|
if (props.pdfUa)
|
|
1506
1541
|
result.pdfUa = true;
|
|
1507
|
-
|
|
1508
|
-
|
|
1542
|
+
const cert = props.certification ?? props.signature;
|
|
1543
|
+
if (cert) {
|
|
1544
|
+
if (props.signature && !props.certification) {
|
|
1545
|
+
console.warn('[Forme] The `signature` prop is deprecated. Use `certification` instead.');
|
|
1546
|
+
}
|
|
1547
|
+
result.certification = cert;
|
|
1548
|
+
}
|
|
1509
1549
|
if (mergedFonts.length > 0) {
|
|
1510
1550
|
result.fonts = mergedFonts;
|
|
1511
1551
|
}
|
|
@@ -1633,7 +1673,7 @@ function serializeTemplateChild(child, parent = null) {
|
|
|
1633
1673
|
}
|
|
1634
1674
|
// Unknown function component — call it
|
|
1635
1675
|
if (typeof element.type === 'function') {
|
|
1636
|
-
const result = element.type
|
|
1676
|
+
const result = callComponent(element.type, element.props);
|
|
1637
1677
|
if (isValidElement(result)) {
|
|
1638
1678
|
return serializeTemplateChild(result, parent);
|
|
1639
1679
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -140,16 +140,16 @@ export interface Style {
|
|
|
140
140
|
minWidowLines?: number;
|
|
141
141
|
minOrphanLines?: number;
|
|
142
142
|
}
|
|
143
|
-
export interface
|
|
143
|
+
export interface CertificationConfig {
|
|
144
144
|
/** PEM-encoded X.509 certificate. */
|
|
145
145
|
certificatePem: string;
|
|
146
146
|
/** PEM-encoded RSA private key (PKCS#8). */
|
|
147
147
|
privateKeyPem: string;
|
|
148
|
-
/** Reason for
|
|
148
|
+
/** Reason for certification (e.g. "Approved"). */
|
|
149
149
|
reason?: string;
|
|
150
|
-
/** Location of
|
|
150
|
+
/** Location of certification (e.g. "New York, NY"). */
|
|
151
151
|
location?: string;
|
|
152
|
-
/** Contact info for the
|
|
152
|
+
/** Contact info for the certifier. */
|
|
153
153
|
contact?: string;
|
|
154
154
|
/** Whether to show a visible signature annotation on the page. */
|
|
155
155
|
visible?: boolean;
|
|
@@ -162,6 +162,8 @@ export interface SignatureConfig {
|
|
|
162
162
|
/** Height in points for visible signature. */
|
|
163
163
|
height?: number;
|
|
164
164
|
}
|
|
165
|
+
/** @deprecated Use CertificationConfig */
|
|
166
|
+
export type SignatureConfig = CertificationConfig;
|
|
165
167
|
export interface DocumentProps {
|
|
166
168
|
title?: string;
|
|
167
169
|
author?: string;
|
|
@@ -177,8 +179,10 @@ export interface DocumentProps {
|
|
|
177
179
|
pdfa?: '2a' | '2b';
|
|
178
180
|
/** When true, the PDF claims PDF/UA-1 conformance. Forces tagging. */
|
|
179
181
|
pdfUa?: boolean;
|
|
180
|
-
/** Digital
|
|
181
|
-
|
|
182
|
+
/** Digital certification configuration. Certifies the PDF with an X.509 certificate. */
|
|
183
|
+
certification?: CertificationConfig;
|
|
184
|
+
/** @deprecated Use certification */
|
|
185
|
+
signature?: CertificationConfig;
|
|
182
186
|
fonts?: FontRegistration[];
|
|
183
187
|
children?: ReactNode;
|
|
184
188
|
}
|
|
@@ -596,7 +600,7 @@ export interface FormeDocument {
|
|
|
596
600
|
pdfa?: '2a' | '2b';
|
|
597
601
|
pdfUa?: boolean;
|
|
598
602
|
flattenForms?: boolean;
|
|
599
|
-
|
|
603
|
+
certification?: CertificationConfig;
|
|
600
604
|
}
|
|
601
605
|
export interface FormeMetadata {
|
|
602
606
|
title?: string;
|