@cosmicdrift/kumiko-document-designer 0.418.0 → 0.420.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.
- package/dist/web/apply-layout-dialog.d.ts +7 -0
- package/dist/web/apply-layout-dialog.js +95 -0
- package/dist/web/company-data-rail.d.ts +5 -0
- package/dist/web/company-data-rail.js +51 -0
- package/dist/web/constants.d.ts +1 -0
- package/dist/web/constants.js +2 -0
- package/dist/web/default-translations.js +3 -0
- package/dist/web/frame-position.d.ts +18 -0
- package/dist/web/frame-position.js +28 -0
- package/dist/web/frame-settings-section.d.ts +13 -0
- package/dist/web/frame-settings-section.js +57 -0
- package/dist/web/i18n.js +285 -3
- package/dist/web/index.d.ts +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/layout-appearance-section.d.ts +8 -0
- package/dist/web/layout-appearance-section.js +64 -0
- package/dist/web/layout-editor-body.js +5 -2
- package/dist/web/layout-editor-logic.d.ts +3 -1
- package/dist/web/layout-editor-logic.js +15 -7
- package/dist/web/layout-editor-paper.d.ts +1 -1
- package/dist/web/layout-editor-paper.js +43 -8
- package/dist/web/layout-html.js +2 -2
- package/dist/web/layout-meta.d.ts +49 -0
- package/dist/web/layout-meta.js +155 -1
- package/dist/web/layout-rails.d.ts +7 -1
- package/dist/web/layout-rails.js +10 -5
- package/dist/web/layout-types.d.ts +2 -2
- package/dist/web/layout-usage-section.d.ts +4 -0
- package/dist/web/layout-usage-section.js +71 -0
- package/dist/web/page-canvas.d.ts +6 -3
- package/dist/web/page-canvas.js +23 -32
- package/dist/web/page-ruler.d.ts +6 -0
- package/dist/web/page-ruler.js +33 -0
- package/dist/web/paper-geometry.d.ts +72 -0
- package/dist/web/paper-geometry.js +134 -0
- package/dist/web/paper-sheet.d.ts +11 -0
- package/dist/web/paper-sheet.js +36 -0
- package/dist/web/pdf-editor-chrome.js +3 -3
- package/dist/web/pdf-editor-context.d.ts +2 -0
- package/dist/web/pdf-editor-panes.js +5 -4
- package/dist/web/pdf-editor-view.d.ts +4 -0
- package/dist/web/pdf-editor-view.js +23 -3
- package/dist/web/pdf-left-rail.d.ts +8 -0
- package/dist/web/pdf-left-rail.js +23 -3
- package/dist/web/pdf-template-editor.js +25 -2
- package/dist/web/settings-panel.d.ts +10 -2
- package/dist/web/settings-panel.js +32 -17
- package/dist/web/use-apply-layout.d.ts +28 -0
- package/dist/web/use-apply-layout.js +13 -0
- package/dist/web/use-layout-editor-state.d.ts +5 -0
- package/dist/web/use-layout-editor-state.js +38 -15
- package/dist/web/use-pdf-editor-state.d.ts +5 -0
- package/dist/web/use-pdf-editor-state.js +42 -10
- package/package.json +6 -6
- package/src/changes.json +31 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { DOCUMENT_FONT_PRINT_STACKS, PDF_DEFAULT_MARGIN_MM, PDF_FOOTER_MARGIN_MM, PDF_HEADER_MARGIN_MM, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { DEFAULT_PDF_FONT_SIZE_PT, isHexColor, PDF_LAYOUT_FONT_SIZE_RANGE, } from "./layout-meta.js";
|
|
3
|
+
import { MARGIN_SIDES } from "./pdf-meta.js";
|
|
4
|
+
const MM_PER_INCH = 25.4;
|
|
5
|
+
const PT_PER_INCH = 72;
|
|
6
|
+
const MM_PER_CM = 10;
|
|
7
|
+
const PORTRAIT_SIZES_MM = {
|
|
8
|
+
A4: { widthMm: 210, heightMm: 297 },
|
|
9
|
+
Letter: { widthMm: 215.9, heightMm: 279.4 },
|
|
10
|
+
};
|
|
11
|
+
export function paperSizeMm(format, orientation) {
|
|
12
|
+
const portrait = PORTRAIT_SIZES_MM[format];
|
|
13
|
+
return orientation === "portrait"
|
|
14
|
+
? portrait
|
|
15
|
+
: { widthMm: portrait.heightMm, heightMm: portrait.widthMm };
|
|
16
|
+
}
|
|
17
|
+
export function paperWidthPt(size) {
|
|
18
|
+
return Number(((size.widthMm * PT_PER_INCH) / MM_PER_INCH).toFixed(2));
|
|
19
|
+
}
|
|
20
|
+
export const EMPTY_MARGIN_INPUT = { top: "", right: "", bottom: "", left: "" };
|
|
21
|
+
// Mirrors the renderer: the template's own value wins over the layout's, which wins over the default.
|
|
22
|
+
export function resolveMarginsMm(input) {
|
|
23
|
+
const { template, layout } = input;
|
|
24
|
+
const pick = (side, fallback) => {
|
|
25
|
+
const own = template[side];
|
|
26
|
+
return own === "" ? (layout[side] ?? fallback) : own;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
top: pick("top", input.hasHeader ? PDF_HEADER_MARGIN_MM : PDF_DEFAULT_MARGIN_MM),
|
|
30
|
+
right: pick("right", PDF_DEFAULT_MARGIN_MM),
|
|
31
|
+
bottom: pick("bottom", input.hasFooter ? PDF_FOOTER_MARGIN_MM : PDF_DEFAULT_MARGIN_MM),
|
|
32
|
+
left: pick("left", PDF_DEFAULT_MARGIN_MM),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function layoutRegionFlags(layoutHeaderFooter, regions) {
|
|
36
|
+
const showRegions = layoutHeaderFooter && regions !== null;
|
|
37
|
+
return {
|
|
38
|
+
showRegions,
|
|
39
|
+
hasHeader: showRegions && regions.header.trim() !== "",
|
|
40
|
+
hasFooter: showRegions && regions.footer.trim() !== "",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function percentOfExtent(mm, extentMm) {
|
|
44
|
+
return Number(((mm / extentMm) * 100).toFixed(3));
|
|
45
|
+
}
|
|
46
|
+
export function rulerMarks(extentMm) {
|
|
47
|
+
// A mark on the paper edge would be cut off by the ruler, so the last full centimetre stays inside.
|
|
48
|
+
const count = Math.ceil(extentMm / MM_PER_CM) - 1;
|
|
49
|
+
return Array.from({ length: count }, (_, index) => {
|
|
50
|
+
const cm = index + 1;
|
|
51
|
+
return { cm, percent: percentOfExtent(cm * MM_PER_CM, extentMm) };
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const MM_PER_HALF_CM = 5;
|
|
55
|
+
// The 5 mm ticks between the centimetre ticks: 5, 15, 25 ... while they still fit on the paper.
|
|
56
|
+
export function rulerHalfMarks(extentMm) {
|
|
57
|
+
const count = Math.floor((extentMm - MM_PER_HALF_CM) / MM_PER_CM) + 1;
|
|
58
|
+
return Array.from({ length: Math.max(count, 0) }, (_, index) => {
|
|
59
|
+
const mm = MM_PER_HALF_CM + index * MM_PER_CM;
|
|
60
|
+
return { mm, percent: percentOfExtent(mm, extentMm) };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// DIN 5008 distances from the top edge, as the PDF prints them (document-pdf-print.ts).
|
|
64
|
+
const FOLD_MARK_FOLDS_MM = {
|
|
65
|
+
"din-a": [87, 192],
|
|
66
|
+
"din-b": [105, 210],
|
|
67
|
+
};
|
|
68
|
+
const PUNCH_MARK_MM = 148.5;
|
|
69
|
+
export function foldMarkLines(foldMarks) {
|
|
70
|
+
if (foldMarks === "none")
|
|
71
|
+
return [];
|
|
72
|
+
return [
|
|
73
|
+
...FOLD_MARK_FOLDS_MM[foldMarks].map((topMm) => ({ topMm, lengthMm: 5 })),
|
|
74
|
+
{ topMm: PUNCH_MARK_MM, lengthMm: 8 },
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
export const CORNER_MARK_PLACEMENTS = [
|
|
78
|
+
{ vertical: "top", horizontal: "left" },
|
|
79
|
+
{ vertical: "top", horizontal: "right" },
|
|
80
|
+
{ vertical: "bottom", horizontal: "left" },
|
|
81
|
+
{ vertical: "bottom", horizontal: "right" },
|
|
82
|
+
];
|
|
83
|
+
// 100cqw only resolves for descendants of the sized container, so these are set on a child that fills the paper.
|
|
84
|
+
export function paperVariables(input) {
|
|
85
|
+
const { size, margins, look } = input;
|
|
86
|
+
const variables = {
|
|
87
|
+
"--paper-mm": `calc(100cqw / ${size.widthMm})`,
|
|
88
|
+
"--paper-pt": `calc(100cqw / ${paperWidthPt(size)})`,
|
|
89
|
+
"--paper-height": `calc(${size.heightMm} * var(--paper-mm))`,
|
|
90
|
+
"--paper-font-size": `calc(${look.fontSizePt} * var(--paper-pt))`,
|
|
91
|
+
"--page-margin-left": "0px",
|
|
92
|
+
"--first-page-top": "0px",
|
|
93
|
+
"--page-margin-top-mm": String(margins.top),
|
|
94
|
+
};
|
|
95
|
+
for (const side of MARGIN_SIDES) {
|
|
96
|
+
variables[`--paper-margin-${side}`] = `calc(${margins[side]} * var(--paper-mm))`;
|
|
97
|
+
}
|
|
98
|
+
if (look.fontStack !== null)
|
|
99
|
+
variables["--paper-font-family"] = look.fontStack;
|
|
100
|
+
if (look.textColor !== null)
|
|
101
|
+
variables["--paper-text-color"] = look.textColor;
|
|
102
|
+
if (look.tableHeaderBackground !== null) {
|
|
103
|
+
variables["--paper-table-header"] = look.tableHeaderBackground;
|
|
104
|
+
}
|
|
105
|
+
if (look.tableLineColor !== null)
|
|
106
|
+
variables["--paper-table-line"] = look.tableLineColor;
|
|
107
|
+
if (look.paperColor !== null)
|
|
108
|
+
variables["--paper-color"] = look.paperColor;
|
|
109
|
+
return variables;
|
|
110
|
+
}
|
|
111
|
+
export function applyCssVariables(element, variables) {
|
|
112
|
+
if (element === null)
|
|
113
|
+
return;
|
|
114
|
+
for (const [name, value] of Object.entries(variables))
|
|
115
|
+
element.style.setProperty(name, value);
|
|
116
|
+
}
|
|
117
|
+
// A half-typed value must not blow up the paper, so anything invalid falls back to the default.
|
|
118
|
+
export function paperLookOf(look) {
|
|
119
|
+
const size = look.fontSizePt;
|
|
120
|
+
const sizeUsable = size !== "" && size >= PDF_LAYOUT_FONT_SIZE_RANGE.min && size <= PDF_LAYOUT_FONT_SIZE_RANGE.max;
|
|
121
|
+
return {
|
|
122
|
+
tableStyle: look.tableStyle,
|
|
123
|
+
fontStack: DOCUMENT_FONT_PRINT_STACKS[look.fontFamily],
|
|
124
|
+
fontSizePt: sizeUsable ? size : DEFAULT_PDF_FONT_SIZE_PT,
|
|
125
|
+
textColor: isHexColor(look.textColor) ? look.textColor : null,
|
|
126
|
+
tableHeaderBackground: isHexColor(look.tableHeaderBackground)
|
|
127
|
+
? look.tableHeaderBackground
|
|
128
|
+
: null,
|
|
129
|
+
tableLineColor: isHexColor(look.tableLineColor) ? look.tableLineColor : null,
|
|
130
|
+
foldMarks: look.foldMarks,
|
|
131
|
+
cornerMarks: look.cornerMarks,
|
|
132
|
+
paperColor: isHexColor(look.paperColor) ? look.paperColor : null,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type MarginsMm, type PaperLook, type PaperSize } from "./paper-geometry.ts";
|
|
3
|
+
/** The measured container is the outer element; the paper child fills it so cq lengths resolve for it and everything inside. */
|
|
4
|
+
export declare function PaperSheet({ size, margins, look, testId, className, children, }: {
|
|
5
|
+
readonly size: PaperSize;
|
|
6
|
+
readonly margins: MarginsMm;
|
|
7
|
+
readonly look: PaperLook;
|
|
8
|
+
readonly testId: string;
|
|
9
|
+
readonly className?: string;
|
|
10
|
+
readonly children: ReactNode;
|
|
11
|
+
}): ReactNode;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PDF_CORNER_MARK_INSET_MM, PDF_CORNER_MARK_LEG_MM, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
|
+
import { cn } from "@cosmicdrift/kumiko-renderer/web";
|
|
4
|
+
import { PageRuler } from "./page-ruler.js";
|
|
5
|
+
import { applyCssVariables, CORNER_MARK_PLACEMENTS, foldMarkLines, paperVariables, } from "./paper-geometry.js";
|
|
6
|
+
const RULER_GUTTER_REM = 1;
|
|
7
|
+
// Text in the outer columns sits on the text margin; a header background is a visible box whose
|
|
8
|
+
// edge is flush instead, so its th keep the padding.
|
|
9
|
+
const FLUSH_CELLS_CLASS = "[&_tr>:first-child]:pl-0 [&_tr>:last-child]:pr-0";
|
|
10
|
+
const FLUSH_BODY_CELLS_CLASS = "[&_tr>td:first-child]:pl-0 [&_tr>td:last-child]:pr-0";
|
|
11
|
+
// Same grey as the PDF table rule (TABLE_LINE in document-pdf-style.ts).
|
|
12
|
+
const PRINT_RULE_COLOR_CLASS = "[&_td]:border-(--paper-table-line,#bbb) [&_th]:border-(--paper-table-line,#bbb)";
|
|
13
|
+
const TABLE_STYLE_CLASS = {
|
|
14
|
+
plain: "[&_td]:border-0 [&_th]:border-0",
|
|
15
|
+
lines: `[&_td]:border-0 [&_th]:border-0 [&_td]:border-b [&_th]:border-b ${PRINT_RULE_COLOR_CLASS}`,
|
|
16
|
+
header: `[&_td]:border-0 [&_th]:border-0 [&_th]:border-b ${PRINT_RULE_COLOR_CLASS}`,
|
|
17
|
+
grid: `[&_td]:border [&_th]:border ${PRINT_RULE_COLOR_CLASS}`,
|
|
18
|
+
};
|
|
19
|
+
/** The measured container is the outer element; the paper child fills it so cq lengths resolve for it and everything inside. */
|
|
20
|
+
export function PaperSheet({ size, margins, look, testId, className, children, }) {
|
|
21
|
+
return (_jsx("div", { className: "@container w-full max-w-(--paper-outer-max) pt-4 pl-4", ref: (element) => applyCssVariables(element, {
|
|
22
|
+
"--paper-outer-max": `calc(${size.widthMm}mm + ${RULER_GUTTER_REM}rem)`,
|
|
23
|
+
}), children: _jsxs("div", { "data-testid": testId, "data-document-paper": "", "data-paper-width-mm": size.widthMm, "data-paper-margin-left-mm": margins.left, "data-paper-margin-right-mm": margins.right, "data-paper-margin-top-mm": margins.top, className: cn("relative flex min-h-(--paper-height) w-full flex-col text-(length:--paper-font-size) text-(color:--paper-text-color) font-(family-name:--paper-font-family) shadow-md [&_th]:bg-(--paper-table-header)", look.paperColor === null ? "bg-card" : "bg-(--paper-color)", TABLE_STYLE_CLASS[look.tableStyle], look.tableStyle !== "grid" &&
|
|
24
|
+
(look.tableHeaderBackground === null ? FLUSH_CELLS_CLASS : FLUSH_BODY_CELLS_CLASS), className), ref: (element) => applyCssVariables(element, paperVariables({ size, margins, look })), children: [_jsx(PageRuler, { size: size, margins: margins }), foldMarkLines(look.foldMarks).map((line) => (_jsx("span", { "data-testid": "paper-fold-mark", "data-fold-mark-top-mm": line.topMm, className: "pointer-events-none absolute left-0 h-px bg-muted-foreground/60 top-[calc(var(--fold-top)*var(--paper-mm))] w-[calc(var(--fold-length)*var(--paper-mm))]", ref: (element) => {
|
|
25
|
+
element?.style.setProperty("--fold-top", String(line.topMm));
|
|
26
|
+
element?.style.setProperty("--fold-length", String(line.lengthMm));
|
|
27
|
+
} }, line.topMm))), look.cornerMarks &&
|
|
28
|
+
CORNER_MARK_PLACEMENTS.map(({ vertical, horizontal }) => (_jsx("span", { "data-testid": "paper-corner-mark", className: cn("pointer-events-none absolute size-[calc(var(--corner-leg)*var(--paper-mm))] border-0 border-muted-foreground/60", vertical === "top"
|
|
29
|
+
? "top-[calc(var(--corner-inset)*var(--paper-mm))] border-t"
|
|
30
|
+
: "bottom-[calc(var(--corner-inset)*var(--paper-mm))] border-b", horizontal === "left"
|
|
31
|
+
? "left-[calc(var(--corner-inset)*var(--paper-mm))] border-l"
|
|
32
|
+
: "right-[calc(var(--corner-inset)*var(--paper-mm))] border-r"), ref: (element) => {
|
|
33
|
+
element?.style.setProperty("--corner-inset", String(PDF_CORNER_MARK_INSET_MM));
|
|
34
|
+
element?.style.setProperty("--corner-leg", String(PDF_CORNER_MARK_LEG_MM));
|
|
35
|
+
} }, `${vertical}-${horizontal}`))), children] }) }));
|
|
36
|
+
}
|
|
@@ -3,15 +3,15 @@ import { EditorHeader, EditorLocaleSwitch, EditorModeSwitch, originOf } from "./
|
|
|
3
3
|
import { EditorFooter, EditorInfoBar } from "./editor-shell.js";
|
|
4
4
|
import { OverridesDrawer } from "./overrides-drawer.js";
|
|
5
5
|
export function renderPdfHeader(c) {
|
|
6
|
-
const { s, view, detail, actions } = c;
|
|
6
|
+
const { t, Button, s, view, detail, actions, startTemplateImport } = c;
|
|
7
7
|
const { busy, mode, setMode } = s.ui;
|
|
8
|
-
return (
|
|
8
|
+
return (_jsxs(EditorHeader, { title: view.title, stored: { status: detail.status, version: detail.version }, actions: {
|
|
9
9
|
busy: busy === "save",
|
|
10
10
|
canSave: busy === null && s.server.validation?.canSave !== false,
|
|
11
11
|
canPublish: busy === null && view.canPublish,
|
|
12
12
|
onSave: () => void actions.save(),
|
|
13
13
|
onPublish: () => void actions.publish(),
|
|
14
|
-
}, children: _jsx(EditorModeSwitch, { testIdPrefix: "pdf", mode: mode, onMode: setMode }) }));
|
|
14
|
+
}, children: [_jsx(EditorModeSwitch, { testIdPrefix: "pdf", mode: mode, onMode: setMode }), startTemplateImport !== undefined && (_jsx(Button, { variant: "secondary", disabled: busy !== null || view.dirty, onClick: startTemplateImport, testId: "pdf-import-from-template", children: t("documentDesigner.actions.importFromTemplate") }))] }));
|
|
15
15
|
}
|
|
16
16
|
function renderInfoControls(c) {
|
|
17
17
|
const { t, Button, s, view, actions } = c;
|
|
@@ -18,5 +18,7 @@ export type PdfRenderContext = {
|
|
|
18
18
|
readonly detail: TemplateDetail;
|
|
19
19
|
readonly onLocaleChange: ((locale: string) => void) | undefined;
|
|
20
20
|
readonly exportBundle: () => Promise<void>;
|
|
21
|
+
/** Undefined when no client feature registers the template-import action. */
|
|
22
|
+
readonly startTemplateImport: (() => void) | undefined;
|
|
21
23
|
};
|
|
22
24
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { PreviewPane } from "@cosmicdrift/kumiko-renderer";
|
|
3
|
+
import { LoadingState } from "@cosmicdrift/kumiko-renderer/web";
|
|
3
4
|
import { PlaceholderSection, SystemPlaceholderSection } from "./mail-left-rail.js";
|
|
4
5
|
import { PageCanvas } from "./page-canvas.js";
|
|
5
|
-
import { PdfResourceSection } from "./pdf-left-rail.js";
|
|
6
|
+
import { PdfCompanyDataSection, PdfResourceSection } from "./pdf-left-rail.js";
|
|
6
7
|
import { serializePdfMeta } from "./pdf-meta.js";
|
|
7
8
|
import { PdfPreviewControllerContext } from "./pdf-preview-renderer.js";
|
|
8
9
|
import { SettingsPanel } from "./settings-panel.js";
|
|
@@ -10,13 +11,13 @@ import { DOCUMENT_PDF_KIND } from "./types.js";
|
|
|
10
11
|
export function renderPdfLeftRail(c) {
|
|
11
12
|
const { s, view, detail, actions } = c;
|
|
12
13
|
const { insert, filesAvailable, scope } = s.host;
|
|
13
|
-
return (_jsxs(_Fragment, { children: [_jsx(PlaceholderSection, { validation: view.placeholderSource, onInsert: insert.insertPlaceholder, idPrefix: "pdf" }), _jsx(SystemPlaceholderSection, { validation: view.placeholderSource, onInsert: insert.insertPlaceholder, idPrefix: "pdf", isLayoutOwned: view.layoutFills }), _jsx(PdfResourceSection, { resourceKeys: view.resourceKeys, canUpload: detail.scope === scope, filesAvailable: filesAvailable, layoutName: view.layoutName, onInsert: insert.insertResource, onUpload: actions.uploadResource })] }));
|
|
14
|
+
return (_jsxs(_Fragment, { children: [_jsx(PlaceholderSection, { validation: view.placeholderSource, onInsert: insert.insertPlaceholder, idPrefix: "pdf" }), _jsx(PdfCompanyDataSection, { onInsertPlaceholder: insert.insertPlaceholder, used: view.companyDataUsed }), _jsx(SystemPlaceholderSection, { validation: view.placeholderSource, onInsert: insert.insertPlaceholder, idPrefix: "pdf", isLayoutOwned: view.layoutFills }), _jsx(PdfResourceSection, { resourceKeys: view.resourceKeys, canUpload: detail.scope === scope, filesAvailable: filesAvailable, layoutName: view.layoutName, onInsert: insert.insertResource, onUpload: actions.uploadResource })] }));
|
|
14
15
|
}
|
|
15
16
|
export function renderPdfEditCanvas(c) {
|
|
16
17
|
const { s, view, current, actions } = c;
|
|
17
18
|
const { insert } = s.host;
|
|
18
19
|
const { vocabulary } = s;
|
|
19
|
-
return (_jsx("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", onFocusCapture: insert.markFocused("body"), children: _jsx(PageCanvas, { meta: current.draft.meta, content: current.draft.content, onContentChange: (content) => actions.updateDraft({ ...current.draft, content }), regions: s.server.layout?.regions ?? null, layoutName: view.layoutName, resourceSrc: view.layoutResourceSrc, variableLabels: vocabulary.variableLabels, systemVariables: vocabulary.systemVariables, systemLabels: vocabulary.systemLabels, variableNames: vocabulary.variableNames, imageVariables: vocabulary.imageVariables, resourcePreviews: vocabulary.resourcePreviews, onEditorReady: insert.register("body") }) }));
|
|
20
|
+
return (_jsx("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", onFocusCapture: insert.markFocused("body"), children: s.server.paperReady ? (_jsx(PageCanvas, { meta: current.draft.meta, layoutMeta: s.server.layoutMeta, content: current.draft.content, onContentChange: (content) => actions.updateDraft({ ...current.draft, content }), regions: s.server.layout?.regions ?? null, layoutName: view.layoutName, resourceSrc: view.layoutResourceSrc, variableLabels: vocabulary.variableLabels, systemVariables: vocabulary.systemVariables, systemLabels: vocabulary.systemLabels, variableNames: vocabulary.variableNames, imageVariables: vocabulary.imageVariables, resourcePreviews: vocabulary.resourcePreviews, onEditorReady: insert.register("body"), onFrameControlChange: s.ui.setFrameControl })) : (_jsx("div", { className: "m-6 rounded-md bg-card p-6 shadow-sm", children: _jsx(LoadingState, { rows: 8 }) })) }));
|
|
20
21
|
}
|
|
21
22
|
export function renderPdfPreviewPane(c) {
|
|
22
23
|
const { s, view, actions, current, slug } = c;
|
|
@@ -39,5 +40,5 @@ export function renderPdfPreviewPane(c) {
|
|
|
39
40
|
}
|
|
40
41
|
export function renderPdfSettings(c) {
|
|
41
42
|
const { s, view, current, detail, actions } = c;
|
|
42
|
-
return (_jsx(SettingsPanel, { meta: current.draft.meta, onMetaChange: (meta) => actions.updateDraft({ ...current.draft, meta }), layouts: s.server.layouts.rows, locale: s.doc.locale, version: { id: detail.id, version: detail.version, status: detail.status }, vocabulary: view.vocabulary, insert: s.host.insert, draftKey: `${current.key}:${s.ui.draftEpoch}` }));
|
|
43
|
+
return (_jsx(SettingsPanel, { meta: current.draft.meta, onMetaChange: (meta) => actions.updateDraft({ ...current.draft, meta }), layouts: s.server.layouts.rows, locale: s.doc.locale, version: { id: detail.id, version: detail.version, status: detail.status }, vocabulary: view.vocabulary, insert: s.host.insert, frameControl: s.ui.frameControl, paper: view.paper, marginsMm: view.marginsMm, inheritedMarginsMm: s.server.paperReady ? view.inheritedMarginsMm : null, draftKey: `${current.key}:${s.ui.draftEpoch}` }));
|
|
43
44
|
}
|
|
@@ -9,6 +9,9 @@ export declare function buildPdfView(input: {
|
|
|
9
9
|
readonly current: EditorState;
|
|
10
10
|
readonly detail: TemplateDetail;
|
|
11
11
|
}): {
|
|
12
|
+
paper: import("./paper-geometry.ts").PaperSize;
|
|
13
|
+
marginsMm: Readonly<Record<import("./pdf-meta.ts").MarginSide, number>>;
|
|
14
|
+
inheritedMarginsMm: Readonly<Record<import("./pdf-meta.ts").MarginSide, number>>;
|
|
12
15
|
dirty: boolean;
|
|
13
16
|
generatedFresh: boolean;
|
|
14
17
|
canPublish: boolean;
|
|
@@ -29,6 +32,7 @@ export declare function buildPdfView(input: {
|
|
|
29
32
|
variables: Readonly<Record<string, import("./mail-types.ts").MailVariable>>;
|
|
30
33
|
systemPlaceholders: readonly string[];
|
|
31
34
|
} | null;
|
|
35
|
+
companyDataUsed: ReadonlySet<string>;
|
|
32
36
|
layoutFills: (name: string) => boolean;
|
|
33
37
|
resourceKeys: string[];
|
|
34
38
|
title: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { fileUrl } from "./file-name.js";
|
|
2
|
+
import { EMPTY_MARGIN_INPUT, layoutRegionFlags, paperSizeMm, resolveMarginsMm, } from "./paper-geometry.js";
|
|
2
3
|
import { snapshotOf } from "./pdf-editor-draft.js";
|
|
3
4
|
import { pdfFooterMessage } from "./pdf-footer.js";
|
|
4
|
-
import {
|
|
5
|
+
import { companyNamesUsedIn, railSystemPlaceholders, withoutCompanyNames, } from "./pdf-left-rail.js";
|
|
5
6
|
import { draftBesideActiveSentence } from "./status-label.js";
|
|
6
7
|
import { parseJsonObject } from "./template-rows.js";
|
|
7
8
|
import { DEFAULT_LAYOUT_SLUG } from "./types.js";
|
|
@@ -46,8 +47,8 @@ function placeholderSourceOf(s) {
|
|
|
46
47
|
? null
|
|
47
48
|
: {
|
|
48
49
|
...validation,
|
|
49
|
-
variables: s.vocabulary.variables,
|
|
50
|
-
systemPlaceholders:
|
|
50
|
+
variables: withoutCompanyNames(s.vocabulary.variables),
|
|
51
|
+
systemPlaceholders: railSystemPlaceholders(validation.systemPlaceholders),
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
export function buildPdfView(input) {
|
|
@@ -61,7 +62,25 @@ export function buildPdfView(input) {
|
|
|
61
62
|
const overviewRow = s.host.overview.rows.find((candidate) => candidate.slug === slug);
|
|
62
63
|
const systemVersion = overviewRow?.systemVersion ?? null;
|
|
63
64
|
const showOverrideLinks = s.server.showOrigin && detail.scope === "system";
|
|
65
|
+
const { meta } = current.draft;
|
|
66
|
+
const { hasHeader, hasFooter } = layoutRegionFlags(meta.layoutHeaderFooter, layout?.regions ?? null);
|
|
67
|
+
const layoutMargins = s.server.layoutMeta.margins ?? {};
|
|
68
|
+
const marginsMm = resolveMarginsMm({
|
|
69
|
+
template: meta.margins,
|
|
70
|
+
layout: layoutMargins,
|
|
71
|
+
hasHeader,
|
|
72
|
+
hasFooter,
|
|
73
|
+
});
|
|
74
|
+
const inheritedMarginsMm = resolveMarginsMm({
|
|
75
|
+
template: EMPTY_MARGIN_INPUT,
|
|
76
|
+
layout: layoutMargins,
|
|
77
|
+
hasHeader,
|
|
78
|
+
hasFooter,
|
|
79
|
+
});
|
|
64
80
|
return {
|
|
81
|
+
paper: paperSizeMm(meta.pageFormat, meta.orientation),
|
|
82
|
+
marginsMm,
|
|
83
|
+
inheritedMarginsMm,
|
|
65
84
|
dirty: snapshotOf(current.draft) !== current.snapshot,
|
|
66
85
|
generatedFresh: generated !== null && generated.forSnapshot === snapshotOf(current.draft),
|
|
67
86
|
canPublish: validation?.canPublish === true,
|
|
@@ -71,6 +90,7 @@ export function buildPdfView(input) {
|
|
|
71
90
|
layoutName,
|
|
72
91
|
layoutResourceSrc: (key) => key === "logo" && brandingLogoFile !== "" ? fileUrl(brandingLogoFile) : undefined,
|
|
73
92
|
placeholderSource: placeholderSourceOf(s),
|
|
93
|
+
companyDataUsed: companyNamesUsedIn(current.draft.content),
|
|
74
94
|
layoutFills: (name) => layout !== null &&
|
|
75
95
|
(layout.html.includes(`data-variable="${name}"`) || layout.html.includes(`{{${name}}}`)),
|
|
76
96
|
resourceKeys: Object.keys(parseJsonObject(detail.linkedResources)),
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
export declare function visibleSystemPlaceholders(names: readonly string[]): readonly string[];
|
|
3
|
+
export declare function railSystemPlaceholders(names: readonly string[]): readonly string[];
|
|
4
|
+
export declare function placeholdersUsedIn(content: string, names: readonly string[]): ReadonlySet<string>;
|
|
5
|
+
export declare function companyNamesUsedIn(content: string): ReadonlySet<string>;
|
|
6
|
+
export declare function withoutCompanyNames<T>(variables: Readonly<Record<string, T>>): Readonly<Record<string, T>>;
|
|
3
7
|
export declare function PdfResourceSection({ resourceKeys, canUpload, filesAvailable, layoutName, onInsert, onUpload, }: {
|
|
4
8
|
readonly resourceKeys: readonly string[];
|
|
5
9
|
readonly canUpload: boolean;
|
|
@@ -8,3 +12,7 @@ export declare function PdfResourceSection({ resourceKeys, canUpload, filesAvail
|
|
|
8
12
|
readonly onInsert: (key: string) => void;
|
|
9
13
|
readonly onUpload: (file: File) => Promise<void>;
|
|
10
14
|
}): ReactNode;
|
|
15
|
+
export declare function PdfCompanyDataSection({ onInsertPlaceholder, used, }: {
|
|
16
|
+
readonly onInsertPlaceholder: (name: string) => void;
|
|
17
|
+
readonly used: ReadonlySet<string>;
|
|
18
|
+
}): ReactNode;
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { COMPANY_PLACEHOLDERS } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
3
|
import { usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
3
4
|
import { UploadZone } from "@cosmicdrift/kumiko-renderer/web";
|
|
5
|
+
import { CompanyDataRail } from "./company-data-rail.js";
|
|
4
6
|
import { RailField, RailHint, RailRow, RailSection } from "./rail.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const COMPANY_DATA_NAMES = ["tenantName", ...COMPANY_PLACEHOLDERS];
|
|
8
|
+
// unsubscribeUrl belongs to mail.
|
|
7
9
|
export function visibleSystemPlaceholders(names) {
|
|
8
|
-
return names.filter((name) =>
|
|
10
|
+
return names.filter((name) => name !== "unsubscribeUrl");
|
|
11
|
+
}
|
|
12
|
+
// The company names have their own rail in the PDF designer, so the placeholder lists skip them.
|
|
13
|
+
export function railSystemPlaceholders(names) {
|
|
14
|
+
return visibleSystemPlaceholders(names).filter((name) => !COMPANY_DATA_NAMES.includes(name));
|
|
15
|
+
}
|
|
16
|
+
// The validation never lists system placeholders as used, so the rail reads the draft itself.
|
|
17
|
+
export function placeholdersUsedIn(content, names) {
|
|
18
|
+
return new Set(names.filter((name) => content.includes(`data-variable="${name}"`) || content.includes(`{{${name}}}`)));
|
|
19
|
+
}
|
|
20
|
+
export function companyNamesUsedIn(content) {
|
|
21
|
+
return placeholdersUsedIn(content, COMPANY_DATA_NAMES);
|
|
22
|
+
}
|
|
23
|
+
export function withoutCompanyNames(variables) {
|
|
24
|
+
return Object.fromEntries(Object.entries(variables).filter(([name]) => !COMPANY_DATA_NAMES.includes(name)));
|
|
9
25
|
}
|
|
10
26
|
const IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
11
27
|
export function PdfResourceSection({ resourceKeys, canUpload, filesAvailable, layoutName, onInsert, onUpload, }) {
|
|
@@ -13,3 +29,7 @@ export function PdfResourceSection({ resourceKeys, canUpload, filesAvailable, la
|
|
|
13
29
|
const { Button } = usePrimitives();
|
|
14
30
|
return (_jsxs(RailSection, { title: t("documentDesigner.resources.title"), testId: "pdf-editor-resources", children: [resourceKeys.length === 0 && _jsx(RailRow, { label: t("documentDesigner.resources.empty") }), resourceKeys.map((key) => (_jsx(RailRow, { testId: `pdf-resource-${key}`, symbol: "\u25A3", label: key, onPress: () => onInsert(key) }, key))), _jsx(RailField, { children: canUpload && filesAvailable ? (_jsx(UploadZone, { multiple: false, accept: IMAGE_TYPES, title: t("documentDesigner.resources.upload"), onUpload: onUpload, testId: "document-designer-upload" })) : (_jsx(Button, { variant: "secondary", size: "sm", disabled: true, children: t("documentDesigner.resources.upload") })) }), !filesAvailable && _jsx(RailHint, { children: t("documentDesigner.resources.noFilesFeature") }), filesAvailable && !canUpload && (_jsx(RailHint, { children: t("documentDesigner.resources.saveFirst") })), _jsx(RailHint, { children: t("documentDesigner.placeholders.layoutHint", { layout: layoutName }) })] }));
|
|
15
31
|
}
|
|
32
|
+
// Company data of the tenant as placeholders, shown in the left rail beside the resources.
|
|
33
|
+
export function PdfCompanyDataSection({ onInsertPlaceholder, used, }) {
|
|
34
|
+
return _jsx(CompanyDataRail, { onInsert: onInsertPlaceholder, used: used });
|
|
35
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { TemplateResolverQueries } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
|
-
import { useDispatcher, usePrimitives, useSetScreenFocus, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
3
|
+
import { runClientAction, useClientActionHandler, useClientActionRuntime, useDispatcher, usePrimitives, useSetScreenFocus, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
4
4
|
import { ErrorState, LoadingState } from "@cosmicdrift/kumiko-renderer/web";
|
|
5
5
|
import { useMemo } from "react";
|
|
6
|
-
import { TEMPLATE_RESOURCE_ENTITY } from "./constants.js";
|
|
6
|
+
import { TEMPLATE_IMPORT_CLIENT_ACTION, TEMPLATE_RESOURCE_ENTITY } from "./constants.js";
|
|
7
7
|
import { EditorBody, EditorFrame } from "./editor-shell.js";
|
|
8
8
|
import { describeError } from "./errors.js";
|
|
9
9
|
import { buildPdfActions } from "./pdf-editor-actions.js";
|
|
@@ -29,6 +29,8 @@ export function PdfTemplateEditor({ slug, locale: requestedLocale, onLocaleChang
|
|
|
29
29
|
facts: { slug: row.slug, kind: row.kind, locale: row.locale },
|
|
30
30
|
}, [row, detail, slug]);
|
|
31
31
|
useSetScreenFocus(focus);
|
|
32
|
+
const clientActionRuntime = useClientActionRuntime();
|
|
33
|
+
const hasTemplateImport = useClientActionHandler(TEMPLATE_IMPORT_CLIENT_ACTION) !== undefined;
|
|
32
34
|
if (rowsQuery.loading && rowsQuery.data === null)
|
|
33
35
|
return _jsx(LoadingState, {});
|
|
34
36
|
if (rowsQuery.error !== null)
|
|
@@ -61,9 +63,30 @@ export function PdfTemplateEditor({ slug, locale: requestedLocale, onLocaleChang
|
|
|
61
63
|
detail,
|
|
62
64
|
onLocaleChange,
|
|
63
65
|
exportBundle,
|
|
66
|
+
startTemplateImport: hasTemplateImport ? () => void startTemplateImport() : undefined,
|
|
64
67
|
};
|
|
65
68
|
const editing = s.ui.mode === "edit";
|
|
66
69
|
return (_jsxs(EditorFrame, { testId: "pdf-template-editor", children: [renderPdfHeader(context), renderPdfInfoBar(context), _jsx(EditorBody, { left: editing ? renderPdfLeftRail(context) : undefined, center: editing ? renderPdfEditCanvas(context) : renderPdfPreviewPane(context), right: renderPdfSettings(context) }), renderPdfFooter(context), renderPdfLocaleDialog(context)] }));
|
|
70
|
+
async function startTemplateImport() {
|
|
71
|
+
s.ui.setActionError(null);
|
|
72
|
+
try {
|
|
73
|
+
await runClientAction({
|
|
74
|
+
action: {
|
|
75
|
+
kind: "clientAction",
|
|
76
|
+
id: "import-template",
|
|
77
|
+
label: "documentDesigner.actions.importFromTemplate",
|
|
78
|
+
action: TEMPLATE_IMPORT_CLIENT_ACTION,
|
|
79
|
+
successMessage: false,
|
|
80
|
+
},
|
|
81
|
+
payload: { slug, locale: s.doc.locale, title: view.title },
|
|
82
|
+
runtime: clientActionRuntime,
|
|
83
|
+
translate: t,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
s.ui.setActionError(error instanceof Error ? error.message : String(error));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
67
90
|
async function exportBundle() {
|
|
68
91
|
const result = await dispatcher.query(TemplateResolverQueries.exportBundle, {
|
|
69
92
|
slug,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DocumentFrameControl } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
2
3
|
import type { EditorVocabulary } from "./mail-edit-center.tsx";
|
|
3
4
|
import type { OverviewRowView } from "./overview-row.ts";
|
|
5
|
+
import { type MarginsMm, type PaperSize } from "./paper-geometry.ts";
|
|
4
6
|
import { type PdfMetaDraft } from "./pdf-meta.ts";
|
|
5
7
|
import { type TemplateStatus } from "./types.ts";
|
|
6
8
|
import type { InsertTargets } from "./use-insert-targets.ts";
|
|
@@ -17,7 +19,13 @@ export type SettingsPanelProps = {
|
|
|
17
19
|
readonly version: VersionInfo;
|
|
18
20
|
readonly vocabulary: EditorVocabulary;
|
|
19
21
|
readonly insert: InsertTargets;
|
|
22
|
+
readonly frameControl: DocumentFrameControl | null;
|
|
23
|
+
readonly paper: PaperSize;
|
|
24
|
+
/** Margins as the renderer will apply them: template, then layout, then default. */
|
|
25
|
+
readonly marginsMm: MarginsMm;
|
|
26
|
+
/** Margins without the template's own values, i.e. what the layout hands down; null until the layout is loaded. */
|
|
27
|
+
readonly inheritedMarginsMm: MarginsMm | null;
|
|
20
28
|
/** Changes when the draft is replaced from outside, so the single-line editors re-read it. */
|
|
21
29
|
readonly draftKey: string;
|
|
22
30
|
};
|
|
23
|
-
export declare function SettingsPanel({ meta, onMetaChange, layouts, locale, version, vocabulary, insert, draftKey, }: SettingsPanelProps): ReactNode;
|
|
31
|
+
export declare function SettingsPanel({ meta, onMetaChange, layouts, locale, version, vocabulary, insert, frameControl, paper, marginsMm, inheritedMarginsMm, draftKey, }: SettingsPanelProps): ReactNode;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { PDF_ORIENTATIONS, PDF_PAGE_FORMATS, PlaceholderLineEditor, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
3
|
import { usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { FrameSettingsSection } from "./frame-settings-section.js";
|
|
4
6
|
import { languageName } from "./mail-origin-bar.js";
|
|
5
7
|
import { layoutOptionLabel } from "./mail-right-rail.js";
|
|
6
8
|
import { VersionsSection } from "./mail-versions.js";
|
|
9
|
+
import { EMPTY_MARGIN_INPUT } from "./paper-geometry.js";
|
|
7
10
|
import { MARGIN_SIDES } from "./pdf-meta.js";
|
|
8
11
|
import { RailField, RailHint, RailSection } from "./rail.js";
|
|
9
12
|
import { DEFAULT_LAYOUT_SLUG } from "./types.js";
|
|
@@ -13,23 +16,35 @@ const SIDE_LABEL_KEYS = {
|
|
|
13
16
|
bottom: "documentDesigner.settings.marginBottom",
|
|
14
17
|
left: "documentDesigner.settings.marginLeft",
|
|
15
18
|
};
|
|
16
|
-
export function SettingsPanel({ meta, onMetaChange, layouts, locale, version, vocabulary, insert, draftKey, }) {
|
|
19
|
+
export function SettingsPanel({ meta, onMetaChange, layouts, locale, version, vocabulary, insert, frameControl, paper, marginsMm, inheritedMarginsMm, draftKey, }) {
|
|
17
20
|
const t = useTranslation();
|
|
18
|
-
const { Field, Input, Text } = usePrimitives();
|
|
21
|
+
const { Button, Field, Input, Text } = usePrimitives();
|
|
22
|
+
const [overrideOpened, setOverrideOpened] = useState(false);
|
|
23
|
+
const hasMarginOverride = MARGIN_SIDES.some((side) => meta.margins[side] !== "");
|
|
24
|
+
const showMarginFields = overrideOpened || hasMarginOverride;
|
|
25
|
+
const recipientOptions = vocabulary.names.map((name) => ({
|
|
26
|
+
value: name,
|
|
27
|
+
label: vocabulary.labels[name] ?? name,
|
|
28
|
+
}));
|
|
19
29
|
const patch = (changes) => onMetaChange({ ...meta, ...changes });
|
|
20
|
-
return (_jsxs("div", { "data-testid": "document-designer-settings", children: [_jsx(RailSection, { title: t("documentDesigner.settings.page"), testId: "pdf-editor-document", children: _jsxs(RailField, { children: [_jsx(Field, { id: "dd-layout", label: t("documentDesigner.settings.layout"), children: _jsx(Input, { kind: "select", id: "dd-layout", name: "layoutSlug", value: meta.layoutSlug === "" ? DEFAULT_LAYOUT_SLUG : meta.layoutSlug, onChange: (layoutSlug) => patch({ layoutSlug }), display: "dropdown", options: layouts.map((layout) => ({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
return (_jsxs("div", { "data-testid": "document-designer-settings", children: [frameControl !== null && (_jsx(FrameSettingsSection, { control: frameControl, paper: paper, margins: marginsMm, recipientOptions: recipientOptions })), _jsxs(RailSection, { title: t("documentDesigner.settings.page"), testId: "pdf-editor-document", children: [_jsxs(RailField, { children: [_jsx(Field, { id: "dd-layout", label: t("documentDesigner.settings.layout"), children: _jsx(Input, { kind: "select", id: "dd-layout", name: "layoutSlug", value: meta.layoutSlug === "" ? DEFAULT_LAYOUT_SLUG : meta.layoutSlug, onChange: (layoutSlug) => patch({ layoutSlug }), display: "dropdown", options: layouts.map((layout) => ({
|
|
31
|
+
value: layout.slug,
|
|
32
|
+
label: layoutOptionLabel(t, layout),
|
|
33
|
+
})) }) }), _jsx(Field, { id: "dd-file-name", label: t("documentDesigner.settings.fileName"), children: _jsx(Input, { kind: "text", id: "dd-file-name", name: "fileName", value: meta.fileName, onChange: (fileName) => patch({ fileName }), placeholder: t("documentDesigner.settings.fileNamePlaceholder") }) }), _jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)] gap-2", children: [_jsx(Field, { id: "dd-page-format", label: t("documentDesigner.settings.pageFormat"), children: _jsx(Input, { kind: "select", id: "dd-page-format", name: "pageFormat", value: meta.pageFormat, onChange: (pageFormat) => {
|
|
34
|
+
const next = PDF_PAGE_FORMATS.find((format) => format === pageFormat);
|
|
35
|
+
if (next !== undefined)
|
|
36
|
+
patch({ pageFormat: next });
|
|
37
|
+
}, display: "dropdown", options: PDF_PAGE_FORMATS.map((value) => ({ value, label: value })) }) }), _jsx(Field, { id: "dd-orientation", label: t("documentDesigner.settings.orientation"), children: _jsx(Input, { kind: "select", id: "dd-orientation", name: "orientation", value: meta.orientation, onChange: (orientation) => {
|
|
38
|
+
const next = PDF_ORIENTATIONS.find((candidate) => candidate === orientation);
|
|
39
|
+
if (next !== undefined)
|
|
40
|
+
patch({ orientation: next });
|
|
41
|
+
}, display: "dropdown", options: PDF_ORIENTATIONS.map((value) => ({
|
|
42
|
+
value,
|
|
43
|
+
label: t(`documentDesigner.settings.${value}`),
|
|
44
|
+
})) }) })] }), showMarginFields ? (_jsxs("fieldset", { className: "m-0 flex min-w-0 flex-col gap-1 border-0 p-0", "data-testid": "pdf-override-margins", children: [_jsx("legend", { className: "p-0 text-sm font-medium", children: t("documentDesigner.margins.legendShort") }), _jsx("div", { className: "grid grid-cols-4 gap-1", children: MARGIN_SIDES.map((side) => (_jsx(Field, { id: `dd-margin-${side}`, label: t(SIDE_LABEL_KEYS[side]), hideLabel: true, children: _jsx(Input, { kind: "number", id: `dd-margin-${side}`, name: `margin-${side}`, value: meta.margins[side], onChange: (value) => patch({ margins: { ...meta.margins, [side]: value ?? "" } }), placeholder: inheritedMarginsMm === null ? "" : String(inheritedMarginsMm[side]) }) }, side))) }), _jsx(Button, { variant: "link", size: "sm", onClick: () => {
|
|
45
|
+
patch({ margins: EMPTY_MARGIN_INPUT });
|
|
46
|
+
setOverrideOpened(false);
|
|
47
|
+
}, testId: "pdf-reset-margins", children: t("documentDesigner.margins.useLayout") })] })) : (_jsxs("div", { className: "flex flex-col gap-1", "data-testid": "pdf-inherited-margins", children: [_jsx("span", { className: "text-sm font-medium", children: t("documentDesigner.margins.legendShort") }), inheritedMarginsMm !== null && (_jsx(Text, { children: t("documentDesigner.margins.fromLayout", {
|
|
48
|
+
margins: MARGIN_SIDES.map((side) => inheritedMarginsMm[side]).join(" · "),
|
|
49
|
+
}) })), _jsx("div", { className: "flex justify-start", children: _jsx(Button, { variant: "link", size: "sm", onClick: () => setOverrideOpened(true), testId: "pdf-override-margins-open", children: t("documentDesigner.margins.override") }) })] })), _jsx(Field, { id: "dd-print-background", label: t("documentDesigner.settings.printBackground"), layout: "inline", children: _jsx(Input, { kind: "boolean", id: "dd-print-background", name: "printBackground", value: meta.printBackground, onChange: (printBackground) => patch({ printBackground }) }) }), _jsx(Field, { id: "dd-layout-header-footer", label: t("documentDesigner.settings.layoutHeaderFooter"), layout: "inline", children: _jsx(Input, { kind: "boolean", id: "dd-layout-header-footer", name: "layoutHeaderFooter", value: meta.layoutHeaderFooter, onChange: (layoutHeaderFooter) => patch({ layoutHeaderFooter }) }) })] }), _jsx(RailHint, { children: t("documentDesigner.pdf.lookFromLayout") })] }), _jsxs(RailSection, { title: t("documentDesigner.settings.metadata"), testId: "pdf-editor-metadata", children: [_jsxs(RailField, { children: [_jsx("div", { onFocusCapture: insert.markFocused("title"), "data-testid": "pdf-meta-title", children: _jsx(Field, { id: "dd-meta-title", label: t("documentDesigner.settings.metaTitle"), children: _jsx(PlaceholderLineEditor, { id: "dd-meta-title", value: meta.title, onChange: (title) => patch({ title }), variableLabels: vocabulary.labels, systemVariables: vocabulary.system, onEditorReady: insert.register("title"), "aria-label": t("documentDesigner.settings.metaTitle") }, `title:${draftKey}`) }) }), _jsx("div", { onFocusCapture: insert.markFocused("author"), "data-testid": "pdf-meta-author", children: _jsx(Field, { id: "dd-meta-author", label: t("documentDesigner.settings.metaAuthor"), children: _jsx(PlaceholderLineEditor, { id: "dd-meta-author", value: meta.author, onChange: (author) => patch({ author }), variableLabels: vocabulary.labels, systemVariables: vocabulary.system, onEditorReady: insert.register("author"), "aria-label": t("documentDesigner.settings.metaAuthor") }, `author:${draftKey}`) }) }), _jsxs("div", { className: "flex flex-col gap-1", "data-testid": "pdf-meta-language", children: [_jsx("span", { className: "text-sm font-medium", children: t("documentDesigner.settings.metaLanguage") }), _jsx(Text, { children: `${languageName(t, locale)} (${locale})` })] })] }), _jsx(RailHint, { children: t("documentDesigner.settings.metaLanguageHint") })] }), _jsx(RailSection, { title: t("documentDesigner.settings.storage"), testId: "pdf-editor-storage", children: _jsx(RailHint, { children: t("documentDesigner.settings.storageHint") }) }), _jsx(VersionsSection, { rowId: version.id, currentVersion: version.version, currentStatus: version.status })] }));
|
|
35
50
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type UseMutationResult } from "@cosmicdrift/kumiko-renderer";
|
|
2
|
+
import type { Translate } from "@cosmicdrift/kumiko-renderer/headless";
|
|
3
|
+
export type TemplateRef = {
|
|
4
|
+
readonly slug: string;
|
|
5
|
+
readonly locale: string;
|
|
6
|
+
};
|
|
7
|
+
export type TemplateOutcome = TemplateRef & {
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function templateOutcomeText(t: Translate, item: TemplateOutcome): string;
|
|
11
|
+
export type ApplyLayoutTarget = {
|
|
12
|
+
readonly mode: "all";
|
|
13
|
+
} | {
|
|
14
|
+
readonly mode: "selected";
|
|
15
|
+
readonly templates: readonly TemplateRef[];
|
|
16
|
+
};
|
|
17
|
+
export type ApplyLayoutResponse = {
|
|
18
|
+
readonly applied: readonly TemplateRef[];
|
|
19
|
+
readonly skipped: readonly TemplateOutcome[];
|
|
20
|
+
};
|
|
21
|
+
export type PublishTemplatesResponse = {
|
|
22
|
+
readonly published: readonly TemplateRef[];
|
|
23
|
+
readonly failed: readonly TemplateOutcome[];
|
|
24
|
+
};
|
|
25
|
+
export declare function useApplyLayout(): {
|
|
26
|
+
readonly apply: UseMutationResult<ApplyLayoutResponse>;
|
|
27
|
+
readonly publish: UseMutationResult<PublishTemplatesResponse>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TemplateResolverHandlers } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { useMutation } from "@cosmicdrift/kumiko-renderer";
|
|
3
|
+
export function templateOutcomeText(t, item) {
|
|
4
|
+
const key = `templateResolver.errors.${item.reason}`;
|
|
5
|
+
const translated = t(key);
|
|
6
|
+
return `${item.slug} (${item.locale}): ${translated === key ? item.reason : translated}`;
|
|
7
|
+
}
|
|
8
|
+
export function useApplyLayout() {
|
|
9
|
+
return {
|
|
10
|
+
apply: useMutation(TemplateResolverHandlers.applyLayout),
|
|
11
|
+
publish: useMutation(TemplateResolverHandlers.publishTemplates),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DocumentEditorHandle } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
1
2
|
import type { Translate } from "@cosmicdrift/kumiko-renderer/headless";
|
|
2
3
|
import { type EditorTab, type Region } from "./layout-editor-logic.ts";
|
|
3
4
|
import type { LayoutKind, LayoutSourceView, LayoutValidation, TenantOverrideCounts } from "./layout-types.ts";
|
|
@@ -27,6 +28,10 @@ export declare function useLayoutEditorState(props: LayoutEditorBodyProps, t: Tr
|
|
|
27
28
|
mjml: string;
|
|
28
29
|
setMjml: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
29
30
|
appearance: import("./layout-meta.ts").LayoutAppearance;
|
|
31
|
+
pdfLook: import("./layout-meta.ts").PdfLayoutLook;
|
|
32
|
+
setPdfLook: import("react").Dispatch<import("react").SetStateAction<import("./layout-meta.ts").PdfLayoutLook>>;
|
|
33
|
+
registerRegion: (region: Region) => (handle: DocumentEditorHandle | null) => void;
|
|
34
|
+
insertIntoActiveRegion: (name: string) => void;
|
|
30
35
|
setAppearance: import("react").Dispatch<import("react").SetStateAction<import("./layout-meta.ts").LayoutAppearance>>;
|
|
31
36
|
activeRegion: Region;
|
|
32
37
|
setActiveRegion: import("react").Dispatch<import("react").SetStateAction<Region>>;
|