@pyreon/document-primitives 0.12.10 → 0.12.11
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/lib/index.d.ts +115 -64
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +128 -14
- package/lib/index.js.map +1 -1
- package/package.json +16 -14
- package/src/DocumentPreview.ts +0 -2
- package/src/__tests__/reactivity.test.ts +415 -0
- package/src/__tests__/useDocumentExport.test.ts +224 -1
- package/src/index.ts +1 -1
- package/src/primitives/DocButton.ts +1 -1
- package/src/primitives/DocCode.ts +1 -1
- package/src/primitives/DocColumn.ts +4 -6
- package/src/primitives/DocDivider.ts +0 -2
- package/src/primitives/DocDocument.ts +56 -8
- package/src/primitives/DocHeading.ts +1 -1
- package/src/primitives/DocImage.ts +0 -2
- package/src/primitives/DocLink.ts +1 -1
- package/src/primitives/DocList.ts +1 -1
- package/src/primitives/DocListItem.ts +1 -1
- package/src/primitives/DocPage.ts +0 -2
- package/src/primitives/DocPageBreak.ts +1 -1
- package/src/primitives/DocQuote.ts +4 -6
- package/src/primitives/DocRow.ts +9 -4
- package/src/primitives/DocSection.ts +1 -1
- package/src/primitives/DocSpacer.ts +1 -1
- package/src/primitives/DocTable.ts +33 -12
- package/src/primitives/DocText.ts +1 -5
- package/src/useDocumentExport.ts +44 -7
package/lib/index.d.ts
CHANGED
|
@@ -38,9 +38,7 @@ declare const DocumentPreview: _pyreon_rocketstyle0.RocketStyleComponent<Partial
|
|
|
38
38
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
39
39
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
40
40
|
size?: string;
|
|
41
|
-
tag: string;
|
|
42
41
|
showPageBreaks?: boolean;
|
|
43
|
-
_documentProps: Record<string, unknown>;
|
|
44
42
|
}, {}, {
|
|
45
43
|
backgroundColor: string;
|
|
46
44
|
padding: number;
|
|
@@ -81,10 +79,6 @@ declare const DocButton: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
81
79
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
82
80
|
css: _pyreon_elements0.ExtendCss;
|
|
83
81
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
84
|
-
tag: string;
|
|
85
|
-
_documentProps: {
|
|
86
|
-
href: string;
|
|
87
|
-
};
|
|
88
82
|
href?: string;
|
|
89
83
|
}, {}, {
|
|
90
84
|
padding: string;
|
|
@@ -121,8 +115,6 @@ declare const DocCode: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
121
115
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
122
116
|
css: _pyreon_elements0.ExtendCss;
|
|
123
117
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
124
|
-
tag: string;
|
|
125
|
-
_documentProps: Record<string, unknown>;
|
|
126
118
|
language?: string;
|
|
127
119
|
}, {}, {
|
|
128
120
|
backgroundColor: string;
|
|
@@ -180,9 +172,7 @@ declare const DocColumn: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
180
172
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
181
173
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
182
174
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
183
|
-
tag: string;
|
|
184
175
|
width?: number | string;
|
|
185
|
-
_documentProps: Record<string, unknown>;
|
|
186
176
|
}, {}, {}, {
|
|
187
177
|
_documentType: "column";
|
|
188
178
|
}, {}, {
|
|
@@ -233,8 +223,6 @@ declare const DocDivider: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
233
223
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
234
224
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
235
225
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
236
|
-
tag: string;
|
|
237
|
-
_documentProps: Record<string, unknown>;
|
|
238
226
|
color?: string;
|
|
239
227
|
thickness?: number;
|
|
240
228
|
}, {}, {
|
|
@@ -258,6 +246,52 @@ declare const DocDivider: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
258
246
|
}, true, {}>;
|
|
259
247
|
//#endregion
|
|
260
248
|
//#region src/primitives/DocDocument.d.ts
|
|
249
|
+
/**
|
|
250
|
+
* Root document container with metadata for the export pipeline.
|
|
251
|
+
*
|
|
252
|
+
* The `title`, `author`, and `subject` props each accept either a
|
|
253
|
+
* plain `string` or a `() => string` accessor. Accessors are
|
|
254
|
+
* resolved by `extractDocumentTree` at export time, so consumers
|
|
255
|
+
* can pass live signal accessors without capturing values at
|
|
256
|
+
* component mount.
|
|
257
|
+
*
|
|
258
|
+
* **Why accessors are needed**: rocketstyle's `.attrs()` callback
|
|
259
|
+
* runs ONCE at component mount (see
|
|
260
|
+
* `packages/ui-system/rocketstyle/src/hoc/rocketstyleAttrsHoc.ts`
|
|
261
|
+
* line 38: ".attrs() callbacks run once at mount"). If `title` were
|
|
262
|
+
* `string`-only and a consumer wanted to bind it to a live signal,
|
|
263
|
+
* they'd have to capture the initial value at template setup time
|
|
264
|
+
* — meaning the export metadata would be permanently stale relative
|
|
265
|
+
* to the live UI state.
|
|
266
|
+
*
|
|
267
|
+
* Storing the accessor in `_documentProps` and resolving it at
|
|
268
|
+
* extraction time means every `extractDocumentTree` call (one per
|
|
269
|
+
* export click) reads the live value. Plain string values still
|
|
270
|
+
* work as before — `extractDocumentTree` only calls the value if
|
|
271
|
+
* it's a function.
|
|
272
|
+
*
|
|
273
|
+
* @example Plain string
|
|
274
|
+
* ```tsx
|
|
275
|
+
* <DocDocument title="My Report" author="Alice">
|
|
276
|
+
* ...
|
|
277
|
+
* </DocDocument>
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example Reactive accessor (recommended for templates that drive
|
|
281
|
+
* a live preview AND export the same tree)
|
|
282
|
+
* ```tsx
|
|
283
|
+
* function MyTemplate({ resume }: { resume: () => Resume }) {
|
|
284
|
+
* return (
|
|
285
|
+
* <DocDocument
|
|
286
|
+
* title={() => `${resume().name} — Resume`}
|
|
287
|
+
* author={() => resume().name}
|
|
288
|
+
* >
|
|
289
|
+
* ...
|
|
290
|
+
* </DocDocument>
|
|
291
|
+
* )
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
261
295
|
declare const DocDocument: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
262
296
|
tag: _pyreon_ui_core0.HTMLTags;
|
|
263
297
|
innerRef: _pyreon_elements0.InnerRef;
|
|
@@ -290,11 +324,9 @@ declare const DocDocument: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
290
324
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
291
325
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
292
326
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
author?: string;
|
|
297
|
-
subject?: string;
|
|
327
|
+
title?: string | (() => string);
|
|
328
|
+
author?: string | (() => string);
|
|
329
|
+
subject?: string | (() => string);
|
|
298
330
|
}, {}, {}, {
|
|
299
331
|
_documentType: "document";
|
|
300
332
|
}, {}, {
|
|
@@ -320,11 +352,7 @@ declare const DocHeading: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
320
352
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
321
353
|
css: _pyreon_elements0.ExtendCss;
|
|
322
354
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
323
|
-
tag: string;
|
|
324
355
|
level?: string;
|
|
325
|
-
_documentProps: {
|
|
326
|
-
level: number;
|
|
327
|
-
};
|
|
328
356
|
}, {}, {
|
|
329
357
|
color: string;
|
|
330
358
|
fontWeight: string;
|
|
@@ -395,9 +423,7 @@ declare const DocImage: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
395
423
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
396
424
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
397
425
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
398
|
-
tag: string;
|
|
399
426
|
width?: number | string;
|
|
400
|
-
_documentProps: Record<string, unknown>;
|
|
401
427
|
caption?: string;
|
|
402
428
|
height?: number | string;
|
|
403
429
|
src?: string;
|
|
@@ -427,10 +453,6 @@ declare const DocLink: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
427
453
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
428
454
|
css: _pyreon_elements0.ExtendCss;
|
|
429
455
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
430
|
-
tag: string;
|
|
431
|
-
_documentProps: {
|
|
432
|
-
href: string;
|
|
433
|
-
};
|
|
434
456
|
href?: string;
|
|
435
457
|
}, {}, {
|
|
436
458
|
color: string;
|
|
@@ -485,8 +507,6 @@ declare const DocList: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
485
507
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
486
508
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
487
509
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
488
|
-
tag: string;
|
|
489
|
-
_documentProps: Record<string, unknown>;
|
|
490
510
|
ordered?: boolean;
|
|
491
511
|
}, {}, {
|
|
492
512
|
marginBottom: number;
|
|
@@ -515,10 +535,7 @@ declare const DocListItem: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
515
535
|
paragraph: boolean;
|
|
516
536
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
517
537
|
css: _pyreon_elements0.ExtendCss;
|
|
518
|
-
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
519
|
-
tag: string;
|
|
520
|
-
_documentProps: Record<string, unknown>;
|
|
521
|
-
}, {}, {
|
|
538
|
+
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {}, {}, {
|
|
522
539
|
fontSize: number;
|
|
523
540
|
lineHeight: number;
|
|
524
541
|
}, {
|
|
@@ -572,9 +589,7 @@ declare const DocPage: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
572
589
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
573
590
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
574
591
|
size?: string;
|
|
575
|
-
tag: string;
|
|
576
592
|
orientation?: string;
|
|
577
|
-
_documentProps: Record<string, unknown>;
|
|
578
593
|
}, {}, {
|
|
579
594
|
backgroundColor: string;
|
|
580
595
|
padding: string;
|
|
@@ -627,10 +642,7 @@ declare const DocPageBreak: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
627
642
|
contentCss: _pyreon_elements0.ExtendCss;
|
|
628
643
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
629
644
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
630
|
-
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
631
|
-
tag: string;
|
|
632
|
-
_documentProps: Record<string, unknown>;
|
|
633
|
-
}, {}, {}, {
|
|
645
|
+
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {}, {}, {}, {
|
|
634
646
|
_documentType: "page-break";
|
|
635
647
|
}, {}, {
|
|
636
648
|
readonly states: "state";
|
|
@@ -680,8 +692,6 @@ declare const DocQuote: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
680
692
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
681
693
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
682
694
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
683
|
-
tag: string;
|
|
684
|
-
_documentProps: Record<string, unknown>;
|
|
685
695
|
borderColor?: string;
|
|
686
696
|
}, {}, {
|
|
687
697
|
padding: string;
|
|
@@ -706,6 +716,12 @@ declare const DocQuote: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
706
716
|
}, true, {}>;
|
|
707
717
|
//#endregion
|
|
708
718
|
//#region src/primitives/DocRow.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* Horizontal row of inline children. Per project conventions, layout
|
|
721
|
+
* props (`direction`, `gap`) live in `.attrs()`, not `.theme()`. The
|
|
722
|
+
* Element base accepts `direction: 'inline' | 'rows' | 'reverseInline'
|
|
723
|
+
* | 'reverseRows'` — `'row'` is not a valid value.
|
|
724
|
+
*/
|
|
709
725
|
declare const DocRow: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
710
726
|
tag: _pyreon_ui_core0.HTMLTags;
|
|
711
727
|
innerRef: _pyreon_elements0.InnerRef;
|
|
@@ -737,12 +753,7 @@ declare const DocRow: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
737
753
|
contentCss: _pyreon_elements0.ExtendCss;
|
|
738
754
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
739
755
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
740
|
-
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
741
|
-
tag: string;
|
|
742
|
-
_documentProps: Record<string, unknown>;
|
|
743
|
-
}, {}, {
|
|
744
|
-
direction: string;
|
|
745
|
-
}, {
|
|
756
|
+
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {}, {}, {}, {
|
|
746
757
|
_documentType: "row";
|
|
747
758
|
}, {}, {
|
|
748
759
|
readonly states: "state";
|
|
@@ -792,11 +803,7 @@ declare const DocSection: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
792
803
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
793
804
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
794
805
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
795
|
-
tag: string;
|
|
796
806
|
direction?: string;
|
|
797
|
-
_documentProps: {
|
|
798
|
-
direction: string;
|
|
799
|
-
};
|
|
800
807
|
}, {}, {
|
|
801
808
|
padding: number;
|
|
802
809
|
}, {
|
|
@@ -845,10 +852,6 @@ declare const DocSpacer: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
845
852
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
846
853
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
847
854
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
848
|
-
tag: string;
|
|
849
|
-
_documentProps: {
|
|
850
|
-
height: number;
|
|
851
|
-
};
|
|
852
855
|
height?: number;
|
|
853
856
|
}, {}, {}, {
|
|
854
857
|
_documentType: "spacer";
|
|
@@ -868,6 +871,24 @@ declare const DocSpacer: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
868
871
|
}, true, {}>;
|
|
869
872
|
//#endregion
|
|
870
873
|
//#region src/primitives/DocTable.d.ts
|
|
874
|
+
/**
|
|
875
|
+
* Tabular data primitive.
|
|
876
|
+
*
|
|
877
|
+
* The `columns`, `rows`, `headerStyle`, `striped`, `bordered`, and
|
|
878
|
+
* `caption` props are document-export metadata — they belong in
|
|
879
|
+
* `_documentProps` only and must NOT be forwarded to the rendered
|
|
880
|
+
* `<table>` element. The `filter` option on `.attrs()` strips them
|
|
881
|
+
* from the props that flow into the DOM.
|
|
882
|
+
*
|
|
883
|
+
* Why this matters: HTMLTableElement's `rows` property is a
|
|
884
|
+
* read-only `HTMLCollection` of `<tr>` elements. If `rows` were
|
|
885
|
+
* forwarded as a DOM attr, the runtime would call
|
|
886
|
+
* `el.rows = [...]` and crash with
|
|
887
|
+
* `TypeError: Cannot set property rows of [object Object] which has
|
|
888
|
+
* only a getter`. Same family for `columns` (`HTMLTableColElement`'s
|
|
889
|
+
* column collection on parent table). Filtering them at the
|
|
890
|
+
* rocketstyle layer keeps the DOM render path clean.
|
|
891
|
+
*/
|
|
871
892
|
declare const DocTable: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
872
893
|
tag: _pyreon_ui_core0.HTMLTags;
|
|
873
894
|
innerRef: _pyreon_elements0.InnerRef;
|
|
@@ -900,8 +921,6 @@ declare const DocTable: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
900
921
|
beforeContentCss: _pyreon_elements0.ExtendCss;
|
|
901
922
|
afterContentCss: _pyreon_elements0.ExtendCss;
|
|
902
923
|
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
903
|
-
tag: string;
|
|
904
|
-
_documentProps: Record<string, unknown>;
|
|
905
924
|
caption?: string;
|
|
906
925
|
rows?: unknown[];
|
|
907
926
|
columns?: unknown[];
|
|
@@ -924,10 +943,7 @@ declare const DocText: _pyreon_rocketstyle0.RocketStyleComponent<Partial<{
|
|
|
924
943
|
paragraph: boolean;
|
|
925
944
|
tag: _pyreon_ui_core0.HTMLTextTags;
|
|
926
945
|
css: _pyreon_elements0.ExtendCss;
|
|
927
|
-
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {
|
|
928
|
-
tag: string;
|
|
929
|
-
_documentProps: Record<string, unknown>;
|
|
930
|
-
}, {}, {
|
|
946
|
+
}> & _pyreon_core0.PyreonHTMLAttributes<HTMLElement>, {}, {}, {
|
|
931
947
|
color: string;
|
|
932
948
|
lineHeight: number;
|
|
933
949
|
marginBottom: number;
|
|
@@ -1012,6 +1028,39 @@ interface DocumentExport {
|
|
|
1012
1028
|
/** Extract the DocNode tree from the template. */
|
|
1013
1029
|
getDocNode: () => DocNode$1;
|
|
1014
1030
|
}
|
|
1031
|
+
/**
|
|
1032
|
+
* One-step helper: extract a DocNode tree from a template function.
|
|
1033
|
+
*
|
|
1034
|
+
* Equivalent to `createDocumentExport(templateFn).getDocNode()` but
|
|
1035
|
+
* without the wrapper-object indirection. Use this when you just
|
|
1036
|
+
* need the tree to feed into `@pyreon/document`'s `render()` or
|
|
1037
|
+
* `download()` — which is the only thing the wrapper object was
|
|
1038
|
+
* ever used for in practice.
|
|
1039
|
+
*
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* import { extractDocNode } from '@pyreon/document-primitives'
|
|
1042
|
+
* import { download } from '@pyreon/document'
|
|
1043
|
+
*
|
|
1044
|
+
* function ResumeTemplate({ resume }: { resume: () => Resume }) {
|
|
1045
|
+
* return (
|
|
1046
|
+
* <DocDocument title={() => `${resume().name} — Resume`}>
|
|
1047
|
+
* <DocPage>...</DocPage>
|
|
1048
|
+
* </DocDocument>
|
|
1049
|
+
* )
|
|
1050
|
+
* }
|
|
1051
|
+
*
|
|
1052
|
+
* // Export click handler:
|
|
1053
|
+
* const tree = extractDocNode(() => <ResumeTemplate resume={store.resume} />)
|
|
1054
|
+
* await download(tree, 'resume.pdf')
|
|
1055
|
+
* ```
|
|
1056
|
+
*
|
|
1057
|
+
* The two-step `createDocumentExport` form is still exported for
|
|
1058
|
+
* backward compatibility and for callers that want to pass the
|
|
1059
|
+
* helper object around (e.g. to wrapper components that take a
|
|
1060
|
+
* `DocumentExport` instance). New code should prefer this one-step
|
|
1061
|
+
* form unless you specifically need the helper object.
|
|
1062
|
+
*/
|
|
1063
|
+
declare function extractDocNode(templateFn: () => unknown, options?: DocumentExportOptions): DocNode$1;
|
|
1015
1064
|
/**
|
|
1016
1065
|
* Create a document export helper from a template function.
|
|
1017
1066
|
*
|
|
@@ -1030,10 +1079,12 @@ interface DocumentExport {
|
|
|
1030
1079
|
* // Pass to @pyreon/document's render() for any format
|
|
1031
1080
|
* ```
|
|
1032
1081
|
*
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1082
|
+
* **Most consumers should use `extractDocNode(templateFn)` instead**
|
|
1083
|
+
* — it's the same operation in one call without the wrapper
|
|
1084
|
+
* object. `createDocumentExport` is kept for callers that want to
|
|
1085
|
+
* pass the helper object around.
|
|
1035
1086
|
*/
|
|
1036
1087
|
declare function createDocumentExport(templateFn: () => unknown, options?: DocumentExportOptions): DocumentExport;
|
|
1037
1088
|
//#endregion
|
|
1038
|
-
export { DocButton, type DocChild, DocCode, DocColumn, DocDivider, DocDocument, DocHeading, DocImage, DocLink, DocList, DocListItem, type DocNode, DocPage, DocPageBreak, DocQuote, DocRow, DocSection, DocSpacer, DocTable, DocText, type DocumentExport, type DocumentExportOptions, DocumentPreview, type DocumentTheme, type ExtractOptions, type NodeType, type ResolvedStyles, createDocumentExport, documentTheme, extractDocumentTree, resolveStyles };
|
|
1089
|
+
export { DocButton, type DocChild, DocCode, DocColumn, DocDivider, DocDocument, DocHeading, DocImage, DocLink, DocList, DocListItem, type DocNode, DocPage, DocPageBreak, DocQuote, DocRow, DocSection, DocSpacer, DocTable, DocText, type DocumentExport, type DocumentExportOptions, DocumentPreview, type DocumentTheme, type ExtractOptions, type NodeType, type ResolvedStyles, createDocumentExport, documentTheme, extractDocNode, extractDocumentTree, resolveStyles };
|
|
1039
1090
|
//# sourceMappingURL=index2.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/DocumentPreview.ts","../../src/primitives/DocButton.ts","../../src/primitives/DocCode.ts","../../src/primitives/DocColumn.ts","../../src/primitives/DocDivider.ts","../../src/primitives/DocDocument.ts","../../src/primitives/DocHeading.ts","../../src/primitives/DocImage.ts","../../src/primitives/DocLink.ts","../../src/primitives/DocList.ts","../../src/primitives/DocListItem.ts","../../src/primitives/DocPage.ts","../../src/primitives/DocPageBreak.ts","../../src/primitives/DocQuote.ts","../../src/primitives/DocRow.ts","../../src/primitives/DocSection.ts","../../src/primitives/DocSpacer.ts","../../src/primitives/DocTable.ts","../../src/primitives/DocText.ts","../../src/theme.ts","../../src/useDocumentExport.ts"],"mappings":";;;;;;;cAGM,eAAA,uBAAe,oBAAA,CAAA,OAAA;
|
|
1
|
+
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/DocumentPreview.ts","../../src/primitives/DocButton.ts","../../src/primitives/DocCode.ts","../../src/primitives/DocColumn.ts","../../src/primitives/DocDivider.ts","../../src/primitives/DocDocument.ts","../../src/primitives/DocHeading.ts","../../src/primitives/DocImage.ts","../../src/primitives/DocLink.ts","../../src/primitives/DocList.ts","../../src/primitives/DocListItem.ts","../../src/primitives/DocPage.ts","../../src/primitives/DocPageBreak.ts","../../src/primitives/DocQuote.ts","../../src/primitives/DocRow.ts","../../src/primitives/DocSection.ts","../../src/primitives/DocSpacer.ts","../../src/primitives/DocTable.ts","../../src/primitives/DocText.ts","../../src/theme.ts","../../src/useDocumentExport.ts"],"mappings":"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"}
|
package/lib/index.js
CHANGED
|
@@ -129,15 +129,61 @@ const DocDivider = rocketstyle()({
|
|
|
129
129
|
|
|
130
130
|
//#endregion
|
|
131
131
|
//#region src/primitives/DocDocument.ts
|
|
132
|
+
/**
|
|
133
|
+
* Root document container with metadata for the export pipeline.
|
|
134
|
+
*
|
|
135
|
+
* The `title`, `author`, and `subject` props each accept either a
|
|
136
|
+
* plain `string` or a `() => string` accessor. Accessors are
|
|
137
|
+
* resolved by `extractDocumentTree` at export time, so consumers
|
|
138
|
+
* can pass live signal accessors without capturing values at
|
|
139
|
+
* component mount.
|
|
140
|
+
*
|
|
141
|
+
* **Why accessors are needed**: rocketstyle's `.attrs()` callback
|
|
142
|
+
* runs ONCE at component mount (see
|
|
143
|
+
* `packages/ui-system/rocketstyle/src/hoc/rocketstyleAttrsHoc.ts`
|
|
144
|
+
* line 38: ".attrs() callbacks run once at mount"). If `title` were
|
|
145
|
+
* `string`-only and a consumer wanted to bind it to a live signal,
|
|
146
|
+
* they'd have to capture the initial value at template setup time
|
|
147
|
+
* — meaning the export metadata would be permanently stale relative
|
|
148
|
+
* to the live UI state.
|
|
149
|
+
*
|
|
150
|
+
* Storing the accessor in `_documentProps` and resolving it at
|
|
151
|
+
* extraction time means every `extractDocumentTree` call (one per
|
|
152
|
+
* export click) reads the live value. Plain string values still
|
|
153
|
+
* work as before — `extractDocumentTree` only calls the value if
|
|
154
|
+
* it's a function.
|
|
155
|
+
*
|
|
156
|
+
* @example Plain string
|
|
157
|
+
* ```tsx
|
|
158
|
+
* <DocDocument title="My Report" author="Alice">
|
|
159
|
+
* ...
|
|
160
|
+
* </DocDocument>
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example Reactive accessor (recommended for templates that drive
|
|
164
|
+
* a live preview AND export the same tree)
|
|
165
|
+
* ```tsx
|
|
166
|
+
* function MyTemplate({ resume }: { resume: () => Resume }) {
|
|
167
|
+
* return (
|
|
168
|
+
* <DocDocument
|
|
169
|
+
* title={() => `${resume().name} — Resume`}
|
|
170
|
+
* author={() => resume().name}
|
|
171
|
+
* >
|
|
172
|
+
* ...
|
|
173
|
+
* </DocDocument>
|
|
174
|
+
* )
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
132
178
|
const DocDocument = rocketstyle()({
|
|
133
179
|
name: "DocDocument",
|
|
134
180
|
component: Element
|
|
135
181
|
}).statics({ _documentType: "document" }).attrs((props) => ({
|
|
136
182
|
tag: "div",
|
|
137
183
|
_documentProps: {
|
|
138
|
-
...props.title ? { title: props.title } : {},
|
|
139
|
-
...props.author ? { author: props.author } : {},
|
|
140
|
-
...props.subject ? { subject: props.subject } : {}
|
|
184
|
+
...props.title != null ? { title: props.title } : {},
|
|
185
|
+
...props.author != null ? { author: props.author } : {},
|
|
186
|
+
...props.subject != null ? { subject: props.subject } : {}
|
|
141
187
|
}
|
|
142
188
|
}));
|
|
143
189
|
|
|
@@ -236,7 +282,7 @@ const DocListItem = rocketstyle()({
|
|
|
236
282
|
}).theme({
|
|
237
283
|
fontSize: 14,
|
|
238
284
|
lineHeight: 1.5
|
|
239
|
-
}).statics({ _documentType: "list-item" }).attrs((
|
|
285
|
+
}).statics({ _documentType: "list-item" }).attrs(() => ({
|
|
240
286
|
tag: "li",
|
|
241
287
|
_documentProps: {}
|
|
242
288
|
}));
|
|
@@ -262,7 +308,7 @@ const DocPage = rocketstyle()({
|
|
|
262
308
|
const DocPageBreak = rocketstyle()({
|
|
263
309
|
name: "DocPageBreak",
|
|
264
310
|
component: Element
|
|
265
|
-
}).statics({ _documentType: "page-break" }).attrs((
|
|
311
|
+
}).statics({ _documentType: "page-break" }).attrs(() => ({
|
|
266
312
|
tag: "div",
|
|
267
313
|
_documentProps: {}
|
|
268
314
|
}));
|
|
@@ -284,11 +330,19 @@ const DocQuote = rocketstyle()({
|
|
|
284
330
|
|
|
285
331
|
//#endregion
|
|
286
332
|
//#region src/primitives/DocRow.ts
|
|
333
|
+
/**
|
|
334
|
+
* Horizontal row of inline children. Per project conventions, layout
|
|
335
|
+
* props (`direction`, `gap`) live in `.attrs()`, not `.theme()`. The
|
|
336
|
+
* Element base accepts `direction: 'inline' | 'rows' | 'reverseInline'
|
|
337
|
+
* | 'reverseRows'` — `'row'` is not a valid value.
|
|
338
|
+
*/
|
|
287
339
|
const DocRow = rocketstyle()({
|
|
288
340
|
name: "DocRow",
|
|
289
341
|
component: Element
|
|
290
|
-
}).
|
|
342
|
+
}).statics({ _documentType: "row" }).attrs(() => ({
|
|
291
343
|
tag: "div",
|
|
344
|
+
direction: "inline",
|
|
345
|
+
gap: 8,
|
|
292
346
|
_documentProps: {}
|
|
293
347
|
}));
|
|
294
348
|
|
|
@@ -320,6 +374,24 @@ const DocSpacer = rocketstyle()({
|
|
|
320
374
|
|
|
321
375
|
//#endregion
|
|
322
376
|
//#region src/primitives/DocTable.ts
|
|
377
|
+
/**
|
|
378
|
+
* Tabular data primitive.
|
|
379
|
+
*
|
|
380
|
+
* The `columns`, `rows`, `headerStyle`, `striped`, `bordered`, and
|
|
381
|
+
* `caption` props are document-export metadata — they belong in
|
|
382
|
+
* `_documentProps` only and must NOT be forwarded to the rendered
|
|
383
|
+
* `<table>` element. The `filter` option on `.attrs()` strips them
|
|
384
|
+
* from the props that flow into the DOM.
|
|
385
|
+
*
|
|
386
|
+
* Why this matters: HTMLTableElement's `rows` property is a
|
|
387
|
+
* read-only `HTMLCollection` of `<tr>` elements. If `rows` were
|
|
388
|
+
* forwarded as a DOM attr, the runtime would call
|
|
389
|
+
* `el.rows = [...]` and crash with
|
|
390
|
+
* `TypeError: Cannot set property rows of [object Object] which has
|
|
391
|
+
* only a getter`. Same family for `columns` (`HTMLTableColElement`'s
|
|
392
|
+
* column collection on parent table). Filtering them at the
|
|
393
|
+
* rocketstyle layer keeps the DOM render path clean.
|
|
394
|
+
*/
|
|
323
395
|
const DocTable = rocketstyle({
|
|
324
396
|
dimensions: { variants: "variant" },
|
|
325
397
|
useBooleans: true
|
|
@@ -339,7 +411,14 @@ const DocTable = rocketstyle({
|
|
|
339
411
|
...props.bordered ? { bordered: props.bordered } : {},
|
|
340
412
|
...props.caption ? { caption: props.caption } : {}
|
|
341
413
|
}
|
|
342
|
-
})
|
|
414
|
+
}), { filter: [
|
|
415
|
+
"columns",
|
|
416
|
+
"rows",
|
|
417
|
+
"headerStyle",
|
|
418
|
+
"striped",
|
|
419
|
+
"bordered",
|
|
420
|
+
"caption"
|
|
421
|
+
] });
|
|
343
422
|
|
|
344
423
|
//#endregion
|
|
345
424
|
//#region src/primitives/DocText.ts
|
|
@@ -369,7 +448,7 @@ const DocText = rocketstyle({
|
|
|
369
448
|
}).weights({
|
|
370
449
|
normal: { fontWeight: "normal" },
|
|
371
450
|
bold: { fontWeight: "bold" }
|
|
372
|
-
}).statics({ _documentType: "text" }).attrs((
|
|
451
|
+
}).statics({ _documentType: "text" }).attrs(() => ({
|
|
373
452
|
tag: "p",
|
|
374
453
|
_documentProps: {}
|
|
375
454
|
}));
|
|
@@ -415,6 +494,41 @@ const documentTheme = {
|
|
|
415
494
|
//#endregion
|
|
416
495
|
//#region src/useDocumentExport.ts
|
|
417
496
|
/**
|
|
497
|
+
* One-step helper: extract a DocNode tree from a template function.
|
|
498
|
+
*
|
|
499
|
+
* Equivalent to `createDocumentExport(templateFn).getDocNode()` but
|
|
500
|
+
* without the wrapper-object indirection. Use this when you just
|
|
501
|
+
* need the tree to feed into `@pyreon/document`'s `render()` or
|
|
502
|
+
* `download()` — which is the only thing the wrapper object was
|
|
503
|
+
* ever used for in practice.
|
|
504
|
+
*
|
|
505
|
+
* ```ts
|
|
506
|
+
* import { extractDocNode } from '@pyreon/document-primitives'
|
|
507
|
+
* import { download } from '@pyreon/document'
|
|
508
|
+
*
|
|
509
|
+
* function ResumeTemplate({ resume }: { resume: () => Resume }) {
|
|
510
|
+
* return (
|
|
511
|
+
* <DocDocument title={() => `${resume().name} — Resume`}>
|
|
512
|
+
* <DocPage>...</DocPage>
|
|
513
|
+
* </DocDocument>
|
|
514
|
+
* )
|
|
515
|
+
* }
|
|
516
|
+
*
|
|
517
|
+
* // Export click handler:
|
|
518
|
+
* const tree = extractDocNode(() => <ResumeTemplate resume={store.resume} />)
|
|
519
|
+
* await download(tree, 'resume.pdf')
|
|
520
|
+
* ```
|
|
521
|
+
*
|
|
522
|
+
* The two-step `createDocumentExport` form is still exported for
|
|
523
|
+
* backward compatibility and for callers that want to pass the
|
|
524
|
+
* helper object around (e.g. to wrapper components that take a
|
|
525
|
+
* `DocumentExport` instance). New code should prefer this one-step
|
|
526
|
+
* form unless you specifically need the helper object.
|
|
527
|
+
*/
|
|
528
|
+
function extractDocNode(templateFn, options = {}) {
|
|
529
|
+
return extractDocumentTree$1(templateFn(), options);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
418
532
|
* Create a document export helper from a template function.
|
|
419
533
|
*
|
|
420
534
|
* The template function should return a VNode tree built with
|
|
@@ -432,16 +546,16 @@ const documentTheme = {
|
|
|
432
546
|
* // Pass to @pyreon/document's render() for any format
|
|
433
547
|
* ```
|
|
434
548
|
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
549
|
+
* **Most consumers should use `extractDocNode(templateFn)` instead**
|
|
550
|
+
* — it's the same operation in one call without the wrapper
|
|
551
|
+
* object. `createDocumentExport` is kept for callers that want to
|
|
552
|
+
* pass the helper object around.
|
|
437
553
|
*/
|
|
438
554
|
function createDocumentExport(templateFn, options = {}) {
|
|
439
|
-
const getDocNode = () =>
|
|
440
|
-
return extractDocumentTree$1(templateFn(), options);
|
|
441
|
-
};
|
|
555
|
+
const getDocNode = () => extractDocNode(templateFn, options);
|
|
442
556
|
return { getDocNode };
|
|
443
557
|
}
|
|
444
558
|
|
|
445
559
|
//#endregion
|
|
446
|
-
export { DocButton, DocCode, DocColumn, DocDivider, DocDocument, DocHeading, DocImage, DocLink, DocList, DocListItem, DocPage, DocPageBreak, DocQuote, DocRow, DocSection, DocSpacer, DocTable, DocText, DocumentPreview, createDocumentExport, documentTheme, extractDocumentTree, resolveStyles };
|
|
560
|
+
export { DocButton, DocCode, DocColumn, DocDivider, DocDocument, DocHeading, DocImage, DocLink, DocList, DocListItem, DocPage, DocPageBreak, DocQuote, DocRow, DocSection, DocSpacer, DocTable, DocText, DocumentPreview, createDocumentExport, documentTheme, extractDocNode, extractDocumentTree, resolveStyles };
|
|
447
561
|
//# sourceMappingURL=index.js.map
|