@cosmicdrift/kumiko-document-designer 0.417.0 → 0.419.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.
Files changed (47) hide show
  1. package/dist/web/apply-layout-dialog.d.ts +7 -0
  2. package/dist/web/apply-layout-dialog.js +95 -0
  3. package/dist/web/company-data-rail.d.ts +5 -0
  4. package/dist/web/company-data-rail.js +51 -0
  5. package/dist/web/frame-position.d.ts +18 -0
  6. package/dist/web/frame-position.js +28 -0
  7. package/dist/web/frame-settings-section.d.ts +13 -0
  8. package/dist/web/frame-settings-section.js +57 -0
  9. package/dist/web/i18n.js +250 -3
  10. package/dist/web/layout-appearance-section.d.ts +8 -0
  11. package/dist/web/layout-appearance-section.js +55 -0
  12. package/dist/web/layout-editor-body.js +5 -2
  13. package/dist/web/layout-editor-logic.d.ts +3 -1
  14. package/dist/web/layout-editor-logic.js +15 -7
  15. package/dist/web/layout-editor-paper.d.ts +1 -1
  16. package/dist/web/layout-editor-paper.js +36 -8
  17. package/dist/web/layout-html.js +2 -2
  18. package/dist/web/layout-meta.d.ts +37 -0
  19. package/dist/web/layout-meta.js +83 -1
  20. package/dist/web/layout-rails.d.ts +7 -1
  21. package/dist/web/layout-rails.js +9 -4
  22. package/dist/web/layout-types.d.ts +2 -2
  23. package/dist/web/layout-usage-section.d.ts +4 -0
  24. package/dist/web/layout-usage-section.js +71 -0
  25. package/dist/web/page-canvas.d.ts +6 -3
  26. package/dist/web/page-canvas.js +23 -32
  27. package/dist/web/page-ruler.d.ts +6 -0
  28. package/dist/web/page-ruler.js +33 -0
  29. package/dist/web/paper-geometry.d.ts +50 -0
  30. package/dist/web/paper-geometry.js +106 -0
  31. package/dist/web/paper-sheet.d.ts +11 -0
  32. package/dist/web/paper-sheet.js +24 -0
  33. package/dist/web/pdf-editor-panes.js +5 -4
  34. package/dist/web/pdf-editor-view.d.ts +4 -0
  35. package/dist/web/pdf-editor-view.js +23 -3
  36. package/dist/web/pdf-left-rail.d.ts +8 -0
  37. package/dist/web/pdf-left-rail.js +23 -3
  38. package/dist/web/settings-panel.d.ts +10 -2
  39. package/dist/web/settings-panel.js +32 -17
  40. package/dist/web/use-apply-layout.d.ts +28 -0
  41. package/dist/web/use-apply-layout.js +13 -0
  42. package/dist/web/use-layout-editor-state.d.ts +5 -0
  43. package/dist/web/use-layout-editor-state.js +38 -15
  44. package/dist/web/use-pdf-editor-state.d.ts +5 -0
  45. package/dist/web/use-pdf-editor-state.js +42 -10
  46. package/package.json +6 -6
  47. package/src/changes.json +25 -0
@@ -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>>;
@@ -1,8 +1,8 @@
1
1
  import { TemplateResolverHandlers, TemplateResolverQueries, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
2
2
  import { useMutation, useQuery } from "@cosmicdrift/kumiko-renderer";
3
- import { useState } from "react";
3
+ import { useRef, useState } from "react";
4
4
  import { accentLineShown, appearanceFlags, footerMessageOf, initialTab, layoutBlocks, layoutContent, layoutDirty, layoutSaveFlags, resourcePreviewsOf, saveLayout, shownRowOf, } from "./layout-editor-logic.js";
5
- import { appearanceOf } from "./layout-meta.js";
5
+ import { appearanceOf, isPdfLayoutLookValid, pdfLayoutLookOf, pdfLayoutMetaToSave, samePdfLayoutLook, } from "./layout-meta.js";
6
6
  import { systemLabelMap } from "./mail-draft.js";
7
7
  import { useBranding } from "./use-branding.js";
8
8
  import { useDebouncedValue } from "./use-debounced-value.js";
@@ -19,7 +19,10 @@ export function useLayoutEditorState(props, t) {
19
19
  const [mjml, setMjml] = useState(source.mjmlSource ?? "");
20
20
  const storedAppearance = appearanceOf(source.meta);
21
21
  const [appearance, setAppearance] = useState(storedAppearance);
22
+ const storedPdfLook = pdfLayoutLookOf(source.meta);
23
+ const [pdfLook, setPdfLook] = useState(storedPdfLook);
22
24
  const [activeRegion, setActiveRegion] = useState("header");
25
+ const regionHandles = useRef({});
23
26
  const [toolbarHost, setToolbarHost] = useState(null);
24
27
  const [pendingKind, setPendingKind] = useState(null);
25
28
  const [saveError, setSaveError] = useState(null);
@@ -34,17 +37,20 @@ export function useLayoutEditorState(props, t) {
34
37
  source,
35
38
  appearance,
36
39
  });
37
- const dirty = layoutDirty({
38
- mjmlMode,
39
- mjml,
40
- header,
41
- signature,
42
- footer,
43
- appearance,
44
- storedAppearance,
45
- appearanceEditable,
46
- source,
47
- });
40
+ const pdfLookDirty = !isMail && !samePdfLayoutLook(pdfLook, storedPdfLook);
41
+ const pdfLookValid = isMail || isPdfLayoutLookValid(pdfLook);
42
+ const dirty = pdfLookDirty ||
43
+ layoutDirty({
44
+ mjmlMode,
45
+ mjml,
46
+ header,
47
+ signature,
48
+ footer,
49
+ appearance,
50
+ storedAppearance,
51
+ appearanceEditable,
52
+ source,
53
+ });
48
54
  const content = layoutContent({ mjmlMode, mjml, header, signature, footer, isMail });
49
55
  const debouncedContent = useDebouncedValue(content, VALIDATE_DEBOUNCE_MS);
50
56
  const validation = useQuery(TemplateResolverQueries.validate, {
@@ -80,6 +86,7 @@ export function useLayoutEditorState(props, t) {
80
86
  isSystemAdmin,
81
87
  appearanceEditable,
82
88
  appearance,
89
+ ...(isMail ? {} : { pdfMeta: pdfLayoutMetaToSave(pdfLook, source.meta) }),
83
90
  t,
84
91
  upsertTenant,
85
92
  upsertSystem,
@@ -91,21 +98,33 @@ export function useLayoutEditorState(props, t) {
91
98
  const { canSave, canPublish } = layoutSaveFlags({
92
99
  dirty,
93
100
  checked,
94
- appearanceValid,
101
+ appearanceValid: appearanceValid && pdfLookValid,
95
102
  busy,
96
103
  shownRow,
97
104
  });
98
- const footerMessage = footerMessageOf({ t, checked, appearanceValid, isMail, userCount });
105
+ const checkedFooterMessage = footerMessageOf({ t, checked, appearanceValid, isMail, userCount });
106
+ const footerMessage = pdfLookValid
107
+ ? checkedFooterMessage
108
+ : { tone: "bad", text: t("documentDesigner.appearance.pdfInvalid") };
99
109
  const accentColor = branding.data?.accentColor ?? "";
100
110
  const showAccentLine = accentLineShown({ isMail, appearanceEditable, appearance, accentColor });
101
111
  const blocks = layoutBlocks(isMail);
102
112
  const resourcePreviews = resourcePreviewsOf(branding.data, isMail, t);
113
+ // The region editors are lazy and report their handle once loaded; company data goes into the focused region.
114
+ const registerRegion = (region) => (handle) => {
115
+ if (handle === null)
116
+ delete regionHandles.current[region];
117
+ else
118
+ regionHandles.current[region] = handle;
119
+ };
120
+ const insertIntoActiveRegion = (name) => regionHandles.current[activeRegion]?.insertPlaceholder(name);
103
121
  const discard = () => {
104
122
  setHeader(source.regions.header);
105
123
  setSignature(source.regions.signature);
106
124
  setFooter(source.regions.footer);
107
125
  setMjml(source.mjmlSource ?? "");
108
126
  setAppearance(storedAppearance);
127
+ setPdfLook(storedPdfLook);
109
128
  setSaveError(null);
110
129
  };
111
130
  return {
@@ -122,6 +141,10 @@ export function useLayoutEditorState(props, t) {
122
141
  mjml,
123
142
  setMjml,
124
143
  appearance,
144
+ pdfLook,
145
+ setPdfLook,
146
+ registerRegion,
147
+ insertIntoActiveRegion,
125
148
  setAppearance,
126
149
  activeRegion,
127
150
  setActiveRegion,
@@ -1,3 +1,4 @@
1
+ import { type DocumentFrameControl } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
1
2
  import type { Translate } from "@cosmicdrift/kumiko-renderer/headless";
2
3
  import type { EditorMode } from "./editor-header.tsx";
3
4
  import { type EditorState, type GeneratedPdf } from "./pdf-editor-draft.ts";
@@ -39,17 +40,21 @@ export declare function usePdfEditorState(input: {
39
40
  autoPrintedFor: import("react").RefObject<string | null>;
40
41
  pendingLocale: string | null;
41
42
  setPendingLocale: import("react").Dispatch<import("react").SetStateAction<string | null>>;
43
+ frameControl: DocumentFrameControl | null;
44
+ setFrameControl: import("react").Dispatch<import("react").SetStateAction<DocumentFrameControl | null>>;
42
45
  };
43
46
  server: {
44
47
  variableSchema: Record<string, unknown>;
45
48
  validationQuery: import("@cosmicdrift/kumiko-renderer").UseQueryResult<ValidationResult>;
46
49
  validation: ValidationResult | null;
50
+ paperReady: boolean;
47
51
  layout: {
48
52
  readonly slug: string;
49
53
  readonly scope: TemplateScope;
50
54
  readonly html: string;
51
55
  readonly regions: import("./types.ts").LayoutRegionsHtml;
52
56
  } | null;
57
+ layoutMeta: import("./layout-meta.ts").LayoutMeta & import("./layout-meta.ts").PdfLayoutMeta;
53
58
  layouts: import("./use-overview-rows.ts").OverviewRows;
54
59
  brandingLogoFile: string;
55
60
  statusQuery: import("@cosmicdrift/kumiko-renderer").UseQueryResult<PuppeteerStatus>;
@@ -1,4 +1,4 @@
1
- import { TemplateResolverQueries } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
1
+ import { TemplateResolverQueries, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
2
2
  import { useQuery, useUserRoles } from "@cosmicdrift/kumiko-renderer";
3
3
  import { RendererPuppeteerClientQueries } from "@cosmicdrift/kumiko-renderer-puppeteer-client/qualified-names";
4
4
  import { useEffect, useMemo, useRef, useState } from "react";
@@ -7,11 +7,12 @@ import { draftFromDetail, imageLabelSource, NO_VARIABLES, snapshotOf, textVariab
7
7
  import { visibleSystemPlaceholders } from "./pdf-left-rail.js";
8
8
  import { serializePdfMeta } from "./pdf-meta.js";
9
9
  import { localesOf, parseJsonObject, pickRow, resolveLocale } from "./template-rows.js";
10
- import { DOCUMENT_PDF_KIND, PDF_LAYOUT_KIND, } from "./types.js";
10
+ import { DEFAULT_LAYOUT_SLUG, DOCUMENT_PDF_KIND, PDF_LAYOUT_KIND, } from "./types.js";
11
11
  import { useBranding } from "./use-branding.js";
12
12
  import { useFilesCapability } from "./use-files-capability.js";
13
13
  import { useInsertTargets } from "./use-insert-targets.js";
14
14
  import { useOverviewRows } from "./use-overview-rows.js";
15
+ const NO_LAYOUT_META = {};
15
16
  function usePdfHostServices() {
16
17
  const insert = useInsertTargets();
17
18
  const filesAvailable = useFilesCapability();
@@ -58,6 +59,7 @@ function usePdfUiState() {
58
59
  const [generated, setGenerated] = useState(null);
59
60
  const autoPrintedFor = useRef(null);
60
61
  const [pendingLocale, setPendingLocale] = useState(null);
62
+ const [frameControl, setFrameControl] = useState(null);
61
63
  return {
62
64
  overridesOpen,
63
65
  setOverridesOpen,
@@ -74,8 +76,36 @@ function usePdfUiState() {
74
76
  autoPrintedFor,
75
77
  pendingLocale,
76
78
  setPendingLocale,
79
+ frameControl,
80
+ setFrameControl,
77
81
  };
78
82
  }
83
+ function hasAnswered(query) {
84
+ return (query.data !== undefined && query.data !== null) || query.error !== null;
85
+ }
86
+ function usePdfLayoutPreview(input) {
87
+ const { slug, scope, variableSchema } = input;
88
+ const { locale, detail, current } = input.doc;
89
+ const layoutSlug = current?.settled.meta.layoutSlug ?? "";
90
+ const previewQuery = useQuery(TemplateResolverQueries.preview, {
91
+ slug,
92
+ kind: DOCUMENT_PDF_KIND,
93
+ locale,
94
+ content: detail?.content ?? "",
95
+ meta: layoutSlug === "" ? {} : { layoutSlug },
96
+ variableSchema,
97
+ }, { enabled: detail !== null });
98
+ const layout = previewQuery.error === null ? (previewQuery.data?.layout ?? null) : null;
99
+ // The template inherits margins from its layout; the preview already resolved the tenant default when none is named.
100
+ const shownLayoutSlug = layoutSlug === "" ? (layout?.slug ?? DEFAULT_LAYOUT_SLUG) : layoutSlug;
101
+ const layoutSourceQuery = useQuery(TemplateResolverQueries.layoutSource, { kind: PDF_LAYOUT_KIND, slug: shownLayoutSlug, scope },
102
+ // Until the preview names the tenant default, the slug is only a guess; its answer would open the paper early.
103
+ { enabled: detail !== null && (layoutSlug !== "" || hasAnswered(previewQuery)) });
104
+ const layoutMeta = layoutSourceQuery.error === null
105
+ ? (layoutSourceQuery.data?.meta ?? NO_LAYOUT_META)
106
+ : NO_LAYOUT_META;
107
+ return { previewQuery, layout, layoutSourceQuery, layoutMeta };
108
+ }
79
109
  function usePdfServerQueries(input) {
80
110
  const { slug, scope } = input;
81
111
  const { locale, detail, current } = input.doc;
@@ -92,16 +122,16 @@ function usePdfServerQueries(input) {
92
122
  scope,
93
123
  }, { enabled: current !== null });
94
124
  const validation = validationQuery.data;
95
- const layoutSlug = current?.settled.meta.layoutSlug ?? "";
96
- const previewQuery = useQuery(TemplateResolverQueries.preview, {
125
+ const { previewQuery, layout, layoutSourceQuery, layoutMeta } = usePdfLayoutPreview({
97
126
  slug,
98
- kind: DOCUMENT_PDF_KIND,
99
- locale,
100
- content: detail?.content ?? "",
101
- meta: layoutSlug === "" ? {} : { layoutSlug },
127
+ scope,
128
+ doc: input.doc,
102
129
  variableSchema,
103
- }, { enabled: detail !== null });
104
- const layout = previewQuery.error === null ? (previewQuery.data?.layout ?? null) : null;
130
+ });
131
+ // The editor rebuilds when the first vocabulary arrives and would drop the caret; the
132
+ // preview and layout source answers also shift the paper text. useQuery keeps previous
133
+ // data on key change, so later refetches do not flip this back.
134
+ const paperReady = hasAnswered(validationQuery) && hasAnswered(previewQuery) && hasAnswered(layoutSourceQuery);
105
135
  const layouts = useOverviewRows(PDF_LAYOUT_KIND);
106
136
  // The built-in "logo" resource of a layout is the tenant's branding logo.
107
137
  const branding = useBranding();
@@ -113,7 +143,9 @@ function usePdfServerQueries(input) {
113
143
  variableSchema,
114
144
  validationQuery,
115
145
  validation,
146
+ paperReady,
116
147
  layout,
148
+ layoutMeta,
117
149
  layouts,
118
150
  brandingLogoFile,
119
151
  statusQuery,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-document-designer",
3
- "version": "0.417.0",
3
+ "version": "0.419.0",
4
4
  "description": "Document designer for Kumiko: template overview, layout editor (mail layout, PDF letterhead) and the PDF template editor.",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -20,11 +20,11 @@
20
20
  "./web/styles.css": "./src/web/styles.css"
21
21
  },
22
22
  "dependencies": {
23
- "@cosmicdrift/kumiko-bundled-features": "0.417.0",
24
- "@cosmicdrift/kumiko-framework": "0.417.0",
25
- "@cosmicdrift/kumiko-renderer": "0.417.0",
26
- "@cosmicdrift/kumiko-renderer-puppeteer-client": "0.417.0",
27
- "@cosmicdrift/kumiko-types": "0.417.0",
23
+ "@cosmicdrift/kumiko-bundled-features": "0.419.0",
24
+ "@cosmicdrift/kumiko-framework": "0.419.0",
25
+ "@cosmicdrift/kumiko-renderer": "0.419.0",
26
+ "@cosmicdrift/kumiko-renderer-puppeteer-client": "0.419.0",
27
+ "@cosmicdrift/kumiko-types": "0.419.0",
28
28
  "react": "^19.3.1"
29
29
  },
30
30
  "devDependencies": {
package/src/changes.json CHANGED
@@ -1,4 +1,29 @@
1
1
  [
2
+ {
3
+ "version": "0.419.0",
4
+ "type": "improvement",
5
+ "title": "Layout appearance, ruler and company data rail",
6
+ "detail": "A PDF layout sets font, size, text colour, table style, table header colour and page margins in its `meta`. The editor paper shows them with a cm ruler and the margin zones; a template inherits the layout margins (\"Aus Layout: ...\") and can override them. Footer and header accept a columns block. The company data rail lists the tenant's company settings next to the placeholders and inserts them on click; a placeholder without a value is flagged by the validate query (`emptyCompanyData`). Company placeholder names (`companyAddress`, `companyIban`, ...) are reserved and cannot be declared as template variables."
7
+ },
8
+ {
9
+ "version": "0.419.0",
10
+ "type": "improvement",
11
+ "title": "PDF paper opens once its layout and placeholders are known",
12
+ "detail": "The PDF template editor shows a loading state in the canvas until the first validate, preview and layout source answers are in, so the editor no longer rebuilds right after opening and drops the caret, and the text no longer shifts when the layout arrives. A tenant default layout that was archived or deleted falls back to the built-in letterhead in the PDF, the preview and the usage lists."
13
+ },
14
+ {
15
+ "version": "0.419.0",
16
+ "type": "breaking",
17
+ "title": "The template title is a rich-text field in front of the body",
18
+ "detail": "The title above the PDF template body is a contenteditable field now, so the first `[contenteditable]` of the editor is the title, not the body. While the editor loads, a read-only placeholder carries the body id `document-designer-content`.",
19
+ "migration": "In e2e specs, target the body with `#document-designer-content[contenteditable=\"true\"]` instead of the first `[contenteditable]` of the editor."
20
+ },
21
+ {
22
+ "version": "0.419.0",
23
+ "type": "fix",
24
+ "title": "Visible loading state in the PDF template editor",
25
+ "detail": "While the layout loads, the canvas shows skeleton rows on a white sheet; before, they had the colour of the canvas background and the editor looked empty. The \"From layout\" margin line appears once the layout is in instead of showing the default margins first."
26
+ },
2
27
  {
3
28
  "version": "0.414.0",
4
29
  "type": "improvement",