@pipelex/mthds-form 0.17.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1900,6 +1900,18 @@ function frameDocument(content, { styles, imgSrc, fontSrc }) {
|
|
|
1900
1900
|
function escapeAttribute(value) {
|
|
1901
1901
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
1902
1902
|
}
|
|
1903
|
+
var DEFAULT_PAGE_FONT = "system-ui, sans-serif";
|
|
1904
|
+
function pageDocument(content, {
|
|
1905
|
+
imgSrc = DEFAULT_IMG_SRC,
|
|
1906
|
+
fontSrc,
|
|
1907
|
+
fontFamily
|
|
1908
|
+
} = {}) {
|
|
1909
|
+
return frameDocument(content, {
|
|
1910
|
+
styles: frameStyles(pageTypography(fontFamily || DEFAULT_PAGE_FONT)),
|
|
1911
|
+
imgSrc,
|
|
1912
|
+
fontSrc: fontSrc ?? imgSrc
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1903
1915
|
|
|
1904
1916
|
// src/react/markup-storage.ts
|
|
1905
1917
|
var MARKUP_RESOLVE_TIMEOUT_MS = 1e4;
|
|
@@ -2161,6 +2173,7 @@ function ResultEnvProvider({
|
|
|
2161
2173
|
tableLayout,
|
|
2162
2174
|
saveFiles,
|
|
2163
2175
|
downloads,
|
|
2176
|
+
renderPdf,
|
|
2164
2177
|
children
|
|
2165
2178
|
}) {
|
|
2166
2179
|
const env = useMemo(
|
|
@@ -2172,7 +2185,8 @@ function ResultEnvProvider({
|
|
|
2172
2185
|
tableColumns,
|
|
2173
2186
|
tableLayout,
|
|
2174
2187
|
saveFiles,
|
|
2175
|
-
downloads
|
|
2188
|
+
downloads,
|
|
2189
|
+
renderPdf
|
|
2176
2190
|
}),
|
|
2177
2191
|
[
|
|
2178
2192
|
resolveUrl,
|
|
@@ -2182,7 +2196,8 @@ function ResultEnvProvider({
|
|
|
2182
2196
|
tableColumns,
|
|
2183
2197
|
tableLayout,
|
|
2184
2198
|
saveFiles,
|
|
2185
|
-
downloads
|
|
2199
|
+
downloads,
|
|
2200
|
+
renderPdf
|
|
2186
2201
|
]
|
|
2187
2202
|
);
|
|
2188
2203
|
return /* @__PURE__ */ jsx(ResultEnvContext, { value: env, children });
|
|
@@ -2262,6 +2277,9 @@ function useFileDownloadShown(kind) {
|
|
|
2262
2277
|
function usePdfSaveShown() {
|
|
2263
2278
|
return use(ResultEnvContext).downloads?.pdf ?? true;
|
|
2264
2279
|
}
|
|
2280
|
+
function useRenderPdf() {
|
|
2281
|
+
return use(ResultEnvContext).renderPdf;
|
|
2282
|
+
}
|
|
2265
2283
|
function useAskFileName() {
|
|
2266
2284
|
return use(ResultEnvContext).downloads?.askFileName ?? false;
|
|
2267
2285
|
}
|
|
@@ -2789,7 +2807,7 @@ var PT_PER_PX = 72 / 96;
|
|
|
2789
2807
|
async function renderHtmlPdf(content, {
|
|
2790
2808
|
imgSrc = DEFAULT_IMG_SRC,
|
|
2791
2809
|
fontSrc,
|
|
2792
|
-
fontFamily =
|
|
2810
|
+
fontFamily = DEFAULT_PAGE_FONT,
|
|
2793
2811
|
title,
|
|
2794
2812
|
scale = 3,
|
|
2795
2813
|
quality = 0.92
|
|
@@ -2973,11 +2991,7 @@ async function openCopy(content, { imgSrc, fontSrc, fontFamily }) {
|
|
|
2973
2991
|
opacity: "0",
|
|
2974
2992
|
pointerEvents: "none"
|
|
2975
2993
|
});
|
|
2976
|
-
frame.srcdoc =
|
|
2977
|
-
styles: frameStyles(pageTypography(fontFamily)),
|
|
2978
|
-
imgSrc,
|
|
2979
|
-
fontSrc
|
|
2980
|
-
});
|
|
2994
|
+
frame.srcdoc = pageDocument(content, { imgSrc, fontSrc, fontFamily });
|
|
2981
2995
|
const loaded = new Promise(
|
|
2982
2996
|
(resolve) => frame.addEventListener("load", () => resolve(), { once: true })
|
|
2983
2997
|
);
|
|
@@ -3038,6 +3052,7 @@ function PdfDownloadButton({
|
|
|
3038
3052
|
const s = useFieldStrings();
|
|
3039
3053
|
const save = useSaveFiles();
|
|
3040
3054
|
const resolvers = useMarkupResolvers();
|
|
3055
|
+
const hostPdf = useRenderPdf();
|
|
3041
3056
|
const ref = useRef(null);
|
|
3042
3057
|
const statusId = useId();
|
|
3043
3058
|
const [state, setState] = useState("idle");
|
|
@@ -3053,12 +3068,12 @@ function PdfDownloadButton({
|
|
|
3053
3068
|
const fontFamily = ref.current ? getComputedStyle(ref.current).fontFamily : void 0;
|
|
3054
3069
|
const innerHtml = await resolveHtmlStorageUrls(content.innerHtml, resolvers);
|
|
3055
3070
|
const page = innerHtml === content.innerHtml ? content : { ...content, innerHtml };
|
|
3056
|
-
const {
|
|
3071
|
+
const blob = hostPdf ? await makeOnHost(hostPdf, page, { title, imgSrc, fontSrc, fontFamily }) : (await renderHtmlPdf(page, {
|
|
3057
3072
|
...title ? { title } : {},
|
|
3058
3073
|
...imgSrc === void 0 ? {} : { imgSrc },
|
|
3059
3074
|
...fontSrc === void 0 ? {} : { fontSrc },
|
|
3060
3075
|
...fontFamily ? { fontFamily } : {}
|
|
3061
|
-
});
|
|
3076
|
+
})).blob;
|
|
3062
3077
|
const { failed: missed } = await save([
|
|
3063
3078
|
{
|
|
3064
3079
|
name: chosen,
|
|
@@ -3101,6 +3116,11 @@ function PdfDownloadButton({
|
|
|
3101
3116
|
dialog
|
|
3102
3117
|
] });
|
|
3103
3118
|
}
|
|
3119
|
+
async function makeOnHost(render, page, { title, ...frame }) {
|
|
3120
|
+
const blob = await render({ html: pageDocument(page, frame), ...title ? { title } : {} });
|
|
3121
|
+
if (!(blob instanceof Blob) || blob.size === 0) throw new Error("The host made no PDF");
|
|
3122
|
+
return blob;
|
|
3123
|
+
}
|
|
3104
3124
|
function pdfStem(name) {
|
|
3105
3125
|
return (name ?? "").trim().replace(/\.pdf$/i, "").trim();
|
|
3106
3126
|
}
|
|
@@ -4835,5 +4855,5 @@ function pdfFileName(field, value, baseName) {
|
|
|
4835
4855
|
}
|
|
4836
4856
|
|
|
4837
4857
|
export { BooleanField, ConceptPill, DEFAULT_FIELD_STRINGS, DateField, DocumentField, EN_FIELD_STRINGS, EnumField, FIELD_STRINGS_BY_LOCALE, FR_FIELD_STRINGS, FieldDomIdProvider, FieldPresentationProvider, FieldRenderer, FieldShell, FieldStringsProvider, HtmlPreview, ImageField, JsonView, ListField, Markdown, MethodForm, NumberField, ObjectField, OptionalToggle, PdfDownloadButton, ProseField, ResultEnvProvider, ResultField, ResultRoot, SUPPORTED_LOCALES, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StuffViewer, Switch, TextField, ToggleGroup, ToggleGroupItem, UnknownField, cn, fieldControlClass, fieldStringsFor, humanizeFieldName, renderHtmlPdf, resolveHtmlStorageUrls, saveInBrowser, useFieldDomId, useFieldPresentation, useFieldStrings, useMethodForm, useProseImages, useResolveShareUrl, useResolveUrl, useResolvedUrl };
|
|
4838
|
-
//# sourceMappingURL=chunk-
|
|
4839
|
-
//# sourceMappingURL=chunk-
|
|
4858
|
+
//# sourceMappingURL=chunk-QCGIH3WY.js.map
|
|
4859
|
+
//# sourceMappingURL=chunk-QCGIH3WY.js.map
|