@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,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export declare function ApplyLayoutDialog({ layoutSlug, layoutTitle, onOpenChange, onApplied, }: {
|
|
3
|
+
readonly layoutSlug: string;
|
|
4
|
+
readonly layoutTitle: string;
|
|
5
|
+
readonly onOpenChange: (open: boolean) => void;
|
|
6
|
+
readonly onApplied: () => void;
|
|
7
|
+
}): ReactNode;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MAX_SELECTED_TEMPLATES } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
|
+
import { dispatcherErrorText, usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
4
|
+
import { pluralKey } from "@cosmicdrift/kumiko-renderer/headless";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { statusLabel } from "./status-label.js";
|
|
7
|
+
import { DOCUMENT_PDF_KIND } from "./types.js";
|
|
8
|
+
import { templateOutcomeText, useApplyLayout, } from "./use-apply-layout.js";
|
|
9
|
+
import { useOverviewRows } from "./use-overview-rows.js";
|
|
10
|
+
import { templateTitle } from "./used-by-label.js";
|
|
11
|
+
const refKey = ({ slug, locale }) => `${slug}\u0000${locale}`;
|
|
12
|
+
// An open draft beside the served version is what the template shows as its state.
|
|
13
|
+
function rowStatusText(t, row) {
|
|
14
|
+
return row.draftVersion === null
|
|
15
|
+
? statusLabel(t, row.status, row.version)
|
|
16
|
+
: statusLabel(t, "draft", row.draftVersion);
|
|
17
|
+
}
|
|
18
|
+
function TemplateRow({ row, checked, onToggle, statusText, }) {
|
|
19
|
+
const t = useTranslation();
|
|
20
|
+
const { Input, Field } = usePrimitives();
|
|
21
|
+
const checkId = `layout-apply-check-${row.slug}`;
|
|
22
|
+
return (_jsxs("li", { className: "flex items-center justify-between gap-3 px-3 py-2", "data-testid": `layout-apply-row-${row.slug}`, children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx(Field, { id: checkId, label: templateTitle(t, row), layout: "inline", children: _jsx(Input, { kind: "boolean", id: checkId, name: "layout-apply-check", value: checked, onChange: onToggle }) }), _jsx("span", { className: "text-xs text-muted-foreground", children: row.locales.join(", ") })] }), _jsx("span", { className: "shrink-0 text-xs text-muted-foreground", children: statusText })] }));
|
|
23
|
+
}
|
|
24
|
+
function ResultList({ items, label, }) {
|
|
25
|
+
return (_jsx("ul", { className: "list-disc pl-5 text-sm", children: items.map((item) => (_jsx("li", { children: label(item) }, refKey(item)))) }));
|
|
26
|
+
}
|
|
27
|
+
function TargetPicker({ title, mode, onModeChange, rows, selected, onToggle, systemCount, entryCount, tooManyEntries, }) {
|
|
28
|
+
const t = useTranslation();
|
|
29
|
+
const { Banner, Input, Field } = usePrimitives();
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("documentDesigner.applyLayout.intro") }), _jsx(Field, { id: "layout-apply-mode", label: title, hideLabel: true, children: _jsx(Input, { kind: "select", id: "layout-apply-mode", name: "layout-apply-mode", value: mode, onChange: (value) => onModeChange(value === "all" ? "all" : "selected"), radioVariant: "card", options: [
|
|
31
|
+
{
|
|
32
|
+
value: "all",
|
|
33
|
+
label: t("documentDesigner.applyLayout.all"),
|
|
34
|
+
description: t("documentDesigner.applyLayout.allHint"),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: "selected",
|
|
38
|
+
label: t("documentDesigner.applyLayout.selected"),
|
|
39
|
+
description: t("documentDesigner.applyLayout.selectedHint"),
|
|
40
|
+
},
|
|
41
|
+
] }) }), mode === "selected" && (_jsx("ul", { className: "flex max-h-64 flex-col divide-y overflow-auto rounded-md border", children: rows.map((row) => (_jsx(TemplateRow, { row: row, checked: selected.has(row.slug), onToggle: () => onToggle(row.slug), statusText: rowStatusText(t, row) }, row.slug))) })), mode === "selected" && systemCount > 0 && (_jsx(Banner, { variant: "warning", children: t(pluralKey("documentDesigner.applyLayout.systemWarning", systemCount), {
|
|
42
|
+
count: systemCount,
|
|
43
|
+
}) })), tooManyEntries && (_jsx("p", { className: "text-xs text-destructive", "data-testid": "layout-apply-too-many", children: t("documentDesigner.applyLayout.tooMany", {
|
|
44
|
+
count: entryCount,
|
|
45
|
+
max: MAX_SELECTED_TEMPLATES,
|
|
46
|
+
}) }))] }));
|
|
47
|
+
}
|
|
48
|
+
function ApplyResult({ mode, applied, onClose, }) {
|
|
49
|
+
const t = useTranslation();
|
|
50
|
+
const { Button } = usePrimitives();
|
|
51
|
+
return (_jsxs("div", { className: "flex flex-col gap-3", "data-testid": "layout-apply-result", children: [mode === "all" ? (_jsx("p", { className: "text-sm", children: t("documentDesigner.applyLayout.allDone") })) : (_jsx("p", { className: "text-sm", children: t(pluralKey("documentDesigner.applyLayout.drafted", applied.applied.length), {
|
|
52
|
+
count: applied.applied.length,
|
|
53
|
+
}) })), applied.skipped.length > 0 && (_jsxs(_Fragment, { children: [_jsx("strong", { className: "text-sm", children: t("documentDesigner.applyLayout.skipped") }), _jsx(ResultList, { items: applied.skipped, label: (item) => templateOutcomeText(t, item) })] })), _jsx("div", { className: "flex justify-end", children: _jsx(Button, { variant: "secondary", onClick: onClose, children: t("documentDesigner.applyLayout.close") }) })] }));
|
|
54
|
+
}
|
|
55
|
+
export function ApplyLayoutDialog({ layoutSlug, layoutTitle, onOpenChange, onApplied, }) {
|
|
56
|
+
const t = useTranslation();
|
|
57
|
+
const { Modal, Button, Banner } = usePrimitives();
|
|
58
|
+
const { rows } = useOverviewRows(DOCUMENT_PDF_KIND);
|
|
59
|
+
const { apply } = useApplyLayout();
|
|
60
|
+
const [mode, setMode] = useState("selected");
|
|
61
|
+
const [selected, setSelected] = useState(new Set());
|
|
62
|
+
const [applied, setApplied] = useState(null);
|
|
63
|
+
const [error, setError] = useState(null);
|
|
64
|
+
const chosen = rows.filter((row) => selected.has(row.slug));
|
|
65
|
+
const systemCount = chosen.filter((row) => row.origin === "system").length;
|
|
66
|
+
const toggle = (slug) => {
|
|
67
|
+
const next = new Set(selected);
|
|
68
|
+
if (!next.delete(slug))
|
|
69
|
+
next.add(slug);
|
|
70
|
+
setSelected(next);
|
|
71
|
+
};
|
|
72
|
+
const entries = chosen.flatMap((row) => row.locales.map((locale) => ({ slug: row.slug, locale })));
|
|
73
|
+
const tooManyEntries = mode === "selected" && entries.length > MAX_SELECTED_TEMPLATES;
|
|
74
|
+
const submit = async () => {
|
|
75
|
+
setError(null);
|
|
76
|
+
const target = mode === "all" ? { mode } : { mode, templates: entries };
|
|
77
|
+
const result = await apply.mutate({ layoutSlug, target });
|
|
78
|
+
if (!result.isSuccess) {
|
|
79
|
+
setError(dispatcherErrorText(result.error, t));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setApplied(result.data);
|
|
83
|
+
onApplied();
|
|
84
|
+
};
|
|
85
|
+
const canSubmit = mode === "all" || (chosen.length > 0 && !tooManyEntries);
|
|
86
|
+
const title = t("documentDesigner.applyLayout.title", { name: layoutTitle });
|
|
87
|
+
const submitLabel = mode === "all"
|
|
88
|
+
? t("documentDesigner.applyLayout.submitAll")
|
|
89
|
+
: chosen.length === 0
|
|
90
|
+
? t("documentDesigner.applyLayout.submitNone")
|
|
91
|
+
: t(pluralKey("documentDesigner.applyLayout.submit", chosen.length), {
|
|
92
|
+
count: chosen.length,
|
|
93
|
+
});
|
|
94
|
+
return (_jsx(Modal, { open: true, onOpenChange: onOpenChange, title: title, size: "wide", testId: "layout-apply-dialog", children: _jsxs("div", { className: "flex flex-col gap-4", children: [error !== null && _jsx(Banner, { variant: "error", children: error }), applied === null ? (_jsxs(_Fragment, { children: [_jsx(TargetPicker, { title: title, mode: mode, onModeChange: setMode, rows: rows, selected: selected, onToggle: toggle, systemCount: systemCount, entryCount: entries.length, tooManyEntries: tooManyEntries }), _jsxs("div", { className: "flex items-end gap-4", children: [_jsx("p", { className: "min-w-0 flex-1 text-xs text-muted-foreground", children: t("documentDesigner.applyLayout.note") }), _jsxs("div", { className: "flex shrink-0 gap-2", children: [_jsx(Button, { variant: "secondary", onClick: () => onOpenChange(false), children: t("documentDesigner.applyLayout.cancel") }), _jsx(Button, { disabled: !canSubmit || apply.pending, loading: apply.pending, onClick: submit, testId: "layout-apply-submit", children: submitLabel })] })] })] })) : (_jsx(ApplyResult, { mode: mode, applied: applied, onClose: () => onOpenChange(false) }))] }) }));
|
|
95
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SessionContext } from "@cosmicdrift/kumiko-bundled-features/auth-email-password/web";
|
|
3
|
+
import { COMPANY_PLACEHOLDERS } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
4
|
+
import { useAppFeatures, useNav, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
5
|
+
import { toKebab } from "@cosmicdrift/kumiko-types/kebab-case";
|
|
6
|
+
import { useContext } from "react";
|
|
7
|
+
import { PLACEHOLDER_SYMBOL } from "./mail-draft.js";
|
|
8
|
+
import { RailHint, RailRow, RailSection } from "./rail.js";
|
|
9
|
+
const CONFIG_FEATURE_NAME = "config";
|
|
10
|
+
const CONFIG_VALUES_QUERY_QN = "config:query:values";
|
|
11
|
+
const COMPANY_SETTINGS_SCREEN_ID = "tenant-tenant";
|
|
12
|
+
const TENANT_CONFIG_PREFIX = "tenant:config:";
|
|
13
|
+
const COMPANY_CONFIG_KEYS = Object.fromEntries(COMPANY_PLACEHOLDERS.map((name) => [name, `${TENANT_CONFIG_PREFIX}${toKebab(name)}`]));
|
|
14
|
+
function textValueOf(values, name) {
|
|
15
|
+
const key = COMPANY_CONFIG_KEYS[name];
|
|
16
|
+
const value = key === undefined ? undefined : values?.[key]?.value;
|
|
17
|
+
return typeof value === "string" ? value.trim().replace(/\s*\n\s*/g, " · ") : "";
|
|
18
|
+
}
|
|
19
|
+
// RailRow cannot color its label, and a missing value is a prompt rather than an error.
|
|
20
|
+
function MissingValueRow({ name, label, trailing, onPress, }) {
|
|
21
|
+
const content = (_jsxs(_Fragment, { children: [_jsx("span", { className: "min-w-0 grow wrap-anywhere text-sm text-status-warn", children: label }), _jsx("span", { className: "shrink-0 text-xs text-primary", children: trailing })] }));
|
|
22
|
+
const rowClass = "flex min-h-10 min-w-0 grow items-center gap-2 px-3.5 text-left";
|
|
23
|
+
return (_jsx("div", { className: "flex items-center border-b", "data-testid": `company-data-${name}`, children: onPress === undefined ? (_jsx("div", { className: rowClass, children: content })) : (_jsx("button", { type: "button", onClick: onPress, className: `${rowClass} hover:bg-muted`, "data-testid": `company-data-${name}-insert`, children: content })) }));
|
|
24
|
+
}
|
|
25
|
+
export function CompanyDataRail({ onInsert, used, }) {
|
|
26
|
+
const t = useTranslation();
|
|
27
|
+
const nav = useNav();
|
|
28
|
+
const { Link } = usePrimitives();
|
|
29
|
+
const features = useAppFeatures();
|
|
30
|
+
// The designer also renders without an auth provider (tests, embeds): no session, no name.
|
|
31
|
+
const session = useContext(SessionContext);
|
|
32
|
+
const tenantName = session?.tenants.find((tenant) => tenant.tenantId === session.activeTenantId)?.name ?? "";
|
|
33
|
+
const configMounted = features.some((feature) => feature.featureName === CONFIG_FEATURE_NAME);
|
|
34
|
+
const hasSettingsScreen = features.some((feature) => feature.featureName === CONFIG_FEATURE_NAME &&
|
|
35
|
+
feature.screens.some((screen) => screen.id === COMPANY_SETTINGS_SCREEN_ID));
|
|
36
|
+
const values = useQuery(CONFIG_VALUES_QUERY_QN, { keys: Object.values(COMPANY_CONFIG_KEYS) }, { enabled: configMounted });
|
|
37
|
+
const editLink = hasSettingsScreen ? (_jsx(Link, { href: nav.hrefFor({ screenId: COMPANY_SETTINGS_SCREEN_ID }), onPress: () => nav.navigate({ screenId: COMPANY_SETTINGS_SCREEN_ID }), testId: "company-data-edit", children: t("documentDesigner.company.edit") })) : undefined;
|
|
38
|
+
return (_jsxs(RailSection, { title: t("documentDesigner.company.title"), action: editLink, testId: "company-data-rail", children: [["tenantName", ...COMPANY_PLACEHOLDERS].map((name) => {
|
|
39
|
+
const text = name === "tenantName" ? tenantName : textValueOf(values.data ?? undefined, name);
|
|
40
|
+
const onPress = onInsert === undefined ? undefined : () => onInsert(name);
|
|
41
|
+
if (used === undefined && text === "") {
|
|
42
|
+
return (_jsx(MissingValueRow, { name: name, label: t(`documentDesigner.placeholder.${name}`), trailing: t("documentDesigner.company.enter"), onPress: onPress }, name));
|
|
43
|
+
}
|
|
44
|
+
const status = used === undefined
|
|
45
|
+
? { text, tone: "muted" }
|
|
46
|
+
: used.has(name)
|
|
47
|
+
? { text: "✓", tone: "ok" }
|
|
48
|
+
: { text: "–", tone: "muted" };
|
|
49
|
+
return (_jsx(RailRow, { testId: `company-data-${name}`, ...(used === undefined ? {} : { symbol: PLACEHOLDER_SYMBOL.text }), label: t(`documentDesigner.placeholder.${name}`), trailing: status.text, trailingTone: status.tone, ...(onPress === undefined ? {} : { onPress }) }, name));
|
|
50
|
+
}), _jsx(RailHint, { children: t("documentDesigner.company.hint") })] }));
|
|
51
|
+
}
|
package/dist/web/constants.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const USER_ME_QUERY_QN: "user:query:user:me";
|
|
|
14
14
|
export declare const FILES_FEATURE_NAME: "files";
|
|
15
15
|
export declare const PROFILE_FEATURE_NAME: "user-profile";
|
|
16
16
|
export declare const PROFILE_SCREEN_ID: "profile";
|
|
17
|
+
export declare const TEMPLATE_IMPORT_CLIENT_ACTION: "ai-agent:import-template";
|
|
17
18
|
export declare const DEFAULT_LAYOUT_SLUG: "default";
|
|
18
19
|
export type TemplateEditorKind = "mail" | "document-pdf" | "mail-layout" | "pdf-layout";
|
|
19
20
|
export declare const TEMPLATE_EDITOR_SCREENS: Readonly<Partial<Record<TemplateEditorKind, string>>>;
|
package/dist/web/constants.js
CHANGED
|
@@ -17,6 +17,8 @@ export const USER_ME_QUERY_QN = "user:query:user:me";
|
|
|
17
17
|
export const FILES_FEATURE_NAME = "files";
|
|
18
18
|
export const PROFILE_FEATURE_NAME = "user-profile";
|
|
19
19
|
export const PROFILE_SCREEN_ID = "profile";
|
|
20
|
+
// Pinned: registered by the AI assistant client feature, which lives outside this repo.
|
|
21
|
+
export const TEMPLATE_IMPORT_CLIENT_ACTION = "ai-agent:import-template";
|
|
20
22
|
export const DEFAULT_LAYOUT_SLUG = "default";
|
|
21
23
|
// A kind without an entry gets no "Edit" row action. The screen must live in this feature,
|
|
22
24
|
// because the boot validator only accepts navigate targets in the same feature.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const documentDesignerTranslations = {
|
|
2
2
|
en: {
|
|
3
3
|
"documentDesigner.actions.generatePdf": "Generate PDF",
|
|
4
|
+
"documentDesigner.actions.importFromTemplate": "Import from a template",
|
|
4
5
|
"documentDesigner.canvas.caption": 'Page 1 · {format} · The preview shows page breaks only roughly; "Generate PDF" is authoritative.',
|
|
5
6
|
"documentDesigner.canvas.fromLayout": 'from layout "{layout}"',
|
|
6
7
|
"documentDesigner.error.resourceTooLarge": "The image is too large. Please choose a smaller file.",
|
|
@@ -82,6 +83,7 @@ export const documentDesignerTranslations = {
|
|
|
82
83
|
},
|
|
83
84
|
de: {
|
|
84
85
|
"documentDesigner.actions.generatePdf": "PDF erzeugen",
|
|
86
|
+
"documentDesigner.actions.importFromTemplate": "Aus Vorlage übernehmen",
|
|
85
87
|
"documentDesigner.canvas.caption": 'Seite 1 · {format} · Die Vorschau zeigt Seitengrenzen nur ungefähr, verbindlich ist "PDF erzeugen".',
|
|
86
88
|
"documentDesigner.canvas.fromLayout": "aus Layout „{layout}“",
|
|
87
89
|
"documentDesigner.error.resourceTooLarge": "Das Bild ist zu groß. Bitte eine kleinere Datei wählen.",
|
|
@@ -163,6 +165,7 @@ export const documentDesignerTranslations = {
|
|
|
163
165
|
},
|
|
164
166
|
es: {
|
|
165
167
|
"documentDesigner.actions.generatePdf": "Generar PDF",
|
|
168
|
+
"documentDesigner.actions.importFromTemplate": "Importar desde una plantilla",
|
|
166
169
|
"documentDesigner.canvas.caption": "Página 1 · {format} · La vista previa solo muestra los saltos de página de forma aproximada; lo que vale es «Generar PDF».",
|
|
167
170
|
"documentDesigner.canvas.fromLayout": "del diseño «{layout}»",
|
|
168
171
|
"documentDesigner.error.resourceTooLarge": "La imagen es demasiado grande. Elige un archivo más pequeño.",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MarginsMm, PaperSize } from "./paper-geometry.ts";
|
|
2
|
+
export type FrameBox = {
|
|
3
|
+
readonly xMm: number;
|
|
4
|
+
readonly yMm: number;
|
|
5
|
+
readonly widthMm: number;
|
|
6
|
+
readonly heightMm: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const DIN_5008_FORMS: readonly ["form-a", "form-b"];
|
|
9
|
+
export type Din5008Form = (typeof DIN_5008_FORMS)[number];
|
|
10
|
+
export type FramePosition = Din5008Form | "free";
|
|
11
|
+
export declare function din5008Box(form: Din5008Form): FrameBox;
|
|
12
|
+
export declare function framePositionOf(box: FrameBox): FramePosition;
|
|
13
|
+
export type FrameOverhang = {
|
|
14
|
+
readonly intoTopMargin: boolean;
|
|
15
|
+
readonly beyondPaper: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function frameOverhangOf(box: FrameBox, paper: PaperSize, margins: MarginsMm): FrameOverhang;
|
|
18
|
+
export declare function hasFrameOverhang(overhang: FrameOverhang): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const DIN_5008_FORMS = ["form-a", "form-b"];
|
|
2
|
+
const DIN_5008_LEFT_MM = 20;
|
|
3
|
+
const DIN_5008_WIDTH_MM = 85;
|
|
4
|
+
const DIN_5008_HEIGHT_MM = 45;
|
|
5
|
+
const DIN_5008_TOP_MM = { "form-a": 27, "form-b": 45 };
|
|
6
|
+
export function din5008Box(form) {
|
|
7
|
+
return {
|
|
8
|
+
xMm: DIN_5008_LEFT_MM,
|
|
9
|
+
yMm: DIN_5008_TOP_MM[form],
|
|
10
|
+
widthMm: DIN_5008_WIDTH_MM,
|
|
11
|
+
heightMm: DIN_5008_HEIGHT_MM,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function sameBox(a, b) {
|
|
15
|
+
return a.xMm === b.xMm && a.yMm === b.yMm && a.widthMm === b.widthMm && a.heightMm === b.heightMm;
|
|
16
|
+
}
|
|
17
|
+
export function framePositionOf(box) {
|
|
18
|
+
return DIN_5008_FORMS.find((form) => sameBox(box, din5008Box(form))) ?? "free";
|
|
19
|
+
}
|
|
20
|
+
export function frameOverhangOf(box, paper, margins) {
|
|
21
|
+
return {
|
|
22
|
+
intoTopMargin: box.yMm < margins.top,
|
|
23
|
+
beyondPaper: box.xMm + box.widthMm > paper.widthMm || box.yMm + box.heightMm > paper.heightMm,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function hasFrameOverhang(overhang) {
|
|
27
|
+
return overhang.intoTopMargin || overhang.beyondPaper;
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DocumentFrameControl } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { MarginsMm, PaperSize } from "./paper-geometry.ts";
|
|
4
|
+
export type RecipientOption = {
|
|
5
|
+
readonly value: string;
|
|
6
|
+
readonly label: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function FrameSettingsSection({ control, paper, margins, recipientOptions, }: {
|
|
9
|
+
readonly control: DocumentFrameControl;
|
|
10
|
+
readonly paper: PaperSize;
|
|
11
|
+
readonly margins: MarginsMm;
|
|
12
|
+
readonly recipientOptions: readonly RecipientOption[];
|
|
13
|
+
}): ReactNode;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
3
|
+
import { DIN_5008_FORMS, din5008Box, frameOverhangOf, framePositionOf, hasFrameOverhang, } from "./frame-position.js";
|
|
4
|
+
import { RailField, RailHint, RailSection } from "./rail.js";
|
|
5
|
+
const NO_RECIPIENT = "";
|
|
6
|
+
const BOX_FIELDS = [
|
|
7
|
+
{
|
|
8
|
+
key: "xMm",
|
|
9
|
+
testId: "frame-x",
|
|
10
|
+
labelKey: "documentDesigner.frame.left",
|
|
11
|
+
patch: (xMm) => ({ xMm }),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
key: "yMm",
|
|
15
|
+
testId: "frame-y",
|
|
16
|
+
labelKey: "documentDesigner.frame.top",
|
|
17
|
+
patch: (yMm) => ({ yMm }),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: "widthMm",
|
|
21
|
+
testId: "frame-width",
|
|
22
|
+
labelKey: "documentDesigner.frame.width",
|
|
23
|
+
patch: (widthMm) => ({ widthMm }),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "heightMm",
|
|
27
|
+
testId: "frame-height",
|
|
28
|
+
labelKey: "documentDesigner.frame.height",
|
|
29
|
+
patch: (heightMm) => ({ heightMm }),
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
export function FrameSettingsSection({ control, paper, margins, recipientOptions, }) {
|
|
33
|
+
const t = useTranslation();
|
|
34
|
+
const { Button, Field, Input } = usePrimitives();
|
|
35
|
+
const { attrs } = control;
|
|
36
|
+
const isAddress = attrs.preset === "address";
|
|
37
|
+
const overhang = frameOverhangOf(attrs, paper, margins);
|
|
38
|
+
return (_jsxs(RailSection, { title: t(isAddress ? "documentDesigner.frame.titleAddress" : "documentDesigner.frame.title"), testId: "pdf-editor-frame", children: [_jsxs(RailField, { children: [isAddress && (_jsx("div", { "data-testid": "frame-position", children: _jsx(Field, { id: "dd-frame-position", label: t("documentDesigner.frame.position"), children: _jsx(Input, { kind: "select", id: "dd-frame-position", name: "framePosition", value: framePositionOf(attrs), onChange: (value) => {
|
|
39
|
+
const form = DIN_5008_FORMS.find((candidate) => candidate === value);
|
|
40
|
+
if (form !== undefined)
|
|
41
|
+
control.update(din5008Box(form));
|
|
42
|
+
}, display: "dropdown", options: [
|
|
43
|
+
...DIN_5008_FORMS.map((form) => ({
|
|
44
|
+
value: form,
|
|
45
|
+
label: t(`documentDesigner.frame.position.${form}`),
|
|
46
|
+
})),
|
|
47
|
+
{ value: "free", label: t("documentDesigner.frame.position.free") },
|
|
48
|
+
] }) }) })), _jsxs("fieldset", { className: "m-0 border-0 p-0", children: [_jsx("legend", { className: "mb-1 p-0 text-[13px] font-medium text-foreground", children: t("documentDesigner.frame.positionMm") }), _jsx("div", { className: "grid grid-cols-4 gap-1", children: BOX_FIELDS.map((field) => (_jsx(Field, { id: `dd-${field.testId}`, label: t(field.labelKey), children: _jsx(Input, { kind: "number", id: `dd-${field.testId}`, name: field.key, value: attrs[field.key], onChange: (value) => {
|
|
49
|
+
if (value !== undefined)
|
|
50
|
+
control.update(field.patch(value));
|
|
51
|
+
}, testId: field.testId }) }, field.key))) })] }), isAddress && (_jsx("div", { "data-testid": "frame-sender", children: _jsx(Field, { id: "dd-frame-sender", label: t("documentDesigner.frame.sender"), layout: "inline", children: _jsx(Input, { kind: "boolean", id: "dd-frame-sender", name: "frameSender", value: control.senderLine, onChange: control.setSenderLine }) }) })), isAddress && (_jsx("div", { "data-testid": "frame-recipient", children: _jsx(Field, { id: "dd-frame-recipient", label: t("documentDesigner.frame.recipient"), children: _jsx(Input, { kind: "select", id: "dd-frame-recipient", name: "frameRecipient", value: control.recipient ?? NO_RECIPIENT, onChange: (name) => control.setRecipient(name === NO_RECIPIENT ? null : name), display: "dropdown", options: [
|
|
52
|
+
{ value: NO_RECIPIENT, label: t("documentDesigner.frame.recipientNone") },
|
|
53
|
+
...recipientOptions,
|
|
54
|
+
] }) }) })), _jsx("div", { "data-testid": "frame-reserve-flow", children: _jsx(Field, { id: "dd-frame-reserve-flow", label: t("documentDesigner.frame.reserveFlow"), layout: "inline", children: _jsx(Input, { kind: "boolean", id: "dd-frame-reserve-flow", name: "frameReserveFlow", value: attrs.reserveFlow, onChange: (reserveFlow) => control.update({ reserveFlow }) }) }) })] }), isAddress && _jsx(RailHint, { children: t("documentDesigner.frame.positionHint") }), hasFrameOverhang(overhang) && (_jsx("div", { "data-testid": "frame-margin-hint", children: _jsx(RailHint, { children: overhang.beyondPaper
|
|
55
|
+
? t("documentDesigner.frame.beyondPaper")
|
|
56
|
+
: t("documentDesigner.frame.intoMargin") }) })), _jsx("div", { className: "flex justify-start px-3.5 pb-2", children: _jsx(Button, { variant: "danger-ghost", size: "sm", onClick: control.remove, testId: "frame-remove", children: t(isAddress ? "documentDesigner.frame.removeAddress" : "documentDesigner.frame.remove") }) })] }));
|
|
57
|
+
}
|