@cosmicdrift/kumiko-samples 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/package.json +1 -1
- package/packages/bundled-features/package.json +11 -1
- package/packages/bundled-features/src/shared/index.ts +6 -0
- package/packages/bundled-features/src/shared/tenant-scoped-subject.ts +28 -0
- package/packages/bundled-features/src/signature/changes.json +6 -0
- package/packages/bundled-features/src/signature/feature.ts +1 -1
- package/packages/bundled-features/src/signature/grant.ts +13 -14
- package/packages/bundled-features/src/signature/png.ts +33 -12
- package/packages/bundled-features/src/template-resolver/api.ts +17 -7
- package/packages/bundled-features/src/template-resolver/changes.json +62 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +10 -9
- package/packages/bundled-features/src/template-resolver/compile-document-styles.ts +170 -0
- package/packages/bundled-features/src/template-resolver/document-frames.ts +68 -0
- package/packages/bundled-features/src/template-resolver/document-op-blocks.ts +682 -0
- package/packages/bundled-features/src/template-resolver/document-ops.ts +170 -128
- package/packages/bundled-features/src/template-resolver/document-print-only.ts +65 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +53 -19
- package/packages/bundled-features/src/template-resolver/feature.ts +15 -0
- package/packages/bundled-features/src/template-resolver/handlers/apply-layout.write.ts +137 -0
- package/packages/bundled-features/src/template-resolver/handlers/create-layout.write.ts +87 -0
- package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +2 -2
- package/packages/bundled-features/src/template-resolver/handlers/document-blocks.query.ts +13 -8
- package/packages/bundled-features/src/template-resolver/handlers/document-region.ts +47 -0
- package/packages/bundled-features/src/template-resolver/handlers/failure-reason.ts +13 -0
- package/packages/bundled-features/src/template-resolver/handlers/import-bundle-system.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/handlers/layout-source.query.ts +17 -5
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +16 -4
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +20 -6
- package/packages/bundled-features/src/template-resolver/handlers/publish-templates.write.ts +69 -0
- package/packages/bundled-features/src/template-resolver/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/template-resolver/handlers/template-write.ts +15 -3
- package/packages/bundled-features/src/template-resolver/handlers/tenant-settings.ts +159 -0
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +25 -10
- package/packages/bundled-features/src/template-resolver/handlers/upsert-system.write.ts +7 -3
- package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +131 -18
- package/packages/bundled-features/src/template-resolver/handlers/validate.query.ts +10 -0
- package/packages/bundled-features/src/template-resolver/i18n.ts +3 -0
- package/packages/bundled-features/src/template-resolver/index.ts +39 -0
- package/packages/bundled-features/src/template-resolver/layout-regions.ts +54 -16
- package/packages/bundled-features/src/template-resolver/print-document.ts +3 -1
- package/packages/bundled-features/src/template-resolver/seeding.ts +4 -0
- package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +11 -1
- package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +37 -1
- package/packages/bundled-features/src/template-resolver/template-meta.ts +31 -6
- package/packages/bundled-features/src/template-resolver/template-preview.ts +29 -9
- package/packages/bundled-features/src/template-resolver/template-validation.ts +10 -3
- package/packages/bundled-features/src/template-resolver/web/constants.ts +33 -0
- package/packages/bundled-features/src/template-resolver/web/document-blocks.ts +5 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +93 -25
- package/packages/bundled-features/src/template-resolver/web/document-editor-fonts.ts +13 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor.tsx +4 -1
- package/packages/bundled-features/src/template-resolver/web/document-fonts.ts +21 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-control.ts +428 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-node-view.tsx +207 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-decorations.ts +246 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-defaults.ts +59 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-style.ts +381 -0
- package/packages/bundled-features/src/template-resolver/web/document-repeat-strip.ts +80 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +87 -19
- package/packages/bundled-features/src/template-resolver/web/document-style-css.ts +214 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +185 -16
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +70 -7
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +13 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +25 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +276 -23
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +449 -10
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +108 -17
- package/packages/bundled-features/src/template-resolver/web/document-toolbar-blocks.ts +20 -0
- package/packages/bundled-features/src/template-resolver/web/fontsource-css.d.ts +2 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +32 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +38 -0
- package/packages/bundled-features/src/template-resolver/web/pdf-constants.ts +16 -0
- package/packages/bundled-features/src/template-resolver/web/placeholder-text.ts +6 -3
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +74 -5
- package/packages/bundled-features/src/tenant/company-config.ts +48 -0
- package/packages/bundled-features/src/tenant/feature.ts +11 -0
- package/packages/bundled-features/src/tenant/i18n.ts +14 -0
- package/samples/apps/ui-walkthrough/src/app/auth-constants.ts +51 -0
- package/samples/apps/ui-walkthrough/src/app/seed-print-editor-tenants.ts +118 -0
- package/samples/apps/ui-walkthrough/src/app/seed-templates.ts +2 -0
- package/samples/apps/ui-walkthrough/src/app/server.ts +9 -1
- package/samples/apps/ui-walkthrough/src/app/template-seed-data.ts +27 -1
- package/samples/apps/ui-walkthrough/src/features/rental/i18n.ts +8 -0
- package/samples/apps/ui-walkthrough/src/features/rental/screens.ts +1 -0
- package/samples/apps/ui-walkthrough/src/run-config.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +236 -0
- package/samples/recipes/pdf-letterhead/README.md +23 -0
- package/samples/recipes/pdf-letterhead/package.json +12 -0
- package/samples/recipes/pdf-letterhead/src/letterhead.ts +92 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Pure CSS-string builders over already validated values. Shared by the server compile and the
|
|
2
|
+
// editor decorations, so the PDF and the editor measure the same way. The custom properties
|
|
3
|
+
// (--paper-pt, --paper-mm, ...) default to real units for print; the editor overrides them to scale.
|
|
4
|
+
import { DOCUMENT_FONT_PRINT_STACKS, type DocumentFont } from "./document-fonts.ts";
|
|
5
|
+
|
|
6
|
+
export type DocumentTextStyle = {
|
|
7
|
+
readonly color?: string | null;
|
|
8
|
+
readonly font?: DocumentFont | null;
|
|
9
|
+
readonly sizePt?: number | null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type DocumentBlockStyle = {
|
|
13
|
+
readonly lineHeight?: number | null;
|
|
14
|
+
readonly spaceBeforePt?: number | null;
|
|
15
|
+
readonly spaceAfterPt?: number | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type DocumentFrameBox = {
|
|
19
|
+
readonly xMm: number;
|
|
20
|
+
readonly yMm: number;
|
|
21
|
+
readonly widthMm: number;
|
|
22
|
+
readonly heightMm: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function pt(value: number): string {
|
|
26
|
+
return `calc(${value} * var(--paper-pt,1pt))`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function mm(value: number): string {
|
|
30
|
+
return `calc(${value} * var(--paper-mm,1mm))`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function declarations(parts: ReadonlyArray<string | null>): string {
|
|
34
|
+
return parts.filter((part): part is string => part !== null).join(";");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function documentTextStyleCss(style: DocumentTextStyle): string {
|
|
38
|
+
return declarations([
|
|
39
|
+
style.color == null ? null : `color:${style.color}`,
|
|
40
|
+
style.font == null ? null : `font-family:${DOCUMENT_FONT_PRINT_STACKS[style.font]}`,
|
|
41
|
+
style.sizePt == null ? null : `font-size:${pt(style.sizePt)}`,
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function documentBlockStyleCss(style: DocumentBlockStyle): string {
|
|
46
|
+
return declarations([
|
|
47
|
+
style.lineHeight == null ? null : `line-height:${style.lineHeight}`,
|
|
48
|
+
style.spaceBeforePt == null ? null : `margin-top:${pt(style.spaceBeforePt)}`,
|
|
49
|
+
style.spaceAfterPt == null ? null : `margin-bottom:${pt(style.spaceAfterPt)}`,
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Chromium clips body content at the margin box, so a frame that sits in the margin is moved
|
|
54
|
+
// to the content edge; the first-page margin override in the print CSS makes that edge reach the frame.
|
|
55
|
+
export function documentFrameCss(frame: DocumentFrameBox): string {
|
|
56
|
+
return declarations([
|
|
57
|
+
"position:absolute",
|
|
58
|
+
"overflow:hidden",
|
|
59
|
+
`--frame-x:${mm(frame.xMm)}`,
|
|
60
|
+
`left:max(0px,calc(${frame.xMm} * var(--paper-mm,1mm) - var(--page-margin-left,0px)))`,
|
|
61
|
+
`top:max(0px,calc(${frame.yMm} * var(--paper-mm,1mm) - var(--first-page-top,0px)))`,
|
|
62
|
+
`width:${mm(frame.widthMm)}`,
|
|
63
|
+
`height:${mm(frame.heightMm)}`,
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type DocumentImageStyle = {
|
|
68
|
+
readonly widthMm?: number | null;
|
|
69
|
+
readonly align?: "left" | "center" | "right" | null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const IMAGE_ALIGN_MARGINS = {
|
|
73
|
+
left: "margin-left:0;margin-right:auto",
|
|
74
|
+
center: "margin-left:auto;margin-right:auto",
|
|
75
|
+
right: "margin-left:auto;margin-right:0",
|
|
76
|
+
} as const;
|
|
77
|
+
|
|
78
|
+
// An explicit width replaces the region's height cap, so a layout logo can be as large as the author set it.
|
|
79
|
+
export function documentImageCss(style: DocumentImageStyle): string {
|
|
80
|
+
return declarations([
|
|
81
|
+
style.widthMm == null
|
|
82
|
+
? null
|
|
83
|
+
: `width:${mm(style.widthMm)};max-width:100%;height:auto;max-height:none`,
|
|
84
|
+
style.align == null ? null : `display:block;${IMAGE_ALIGN_MARGINS[style.align]}`,
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const DIVIDER_DEFAULT_COLOR = "#bbb";
|
|
89
|
+
const DIVIDER_DEFAULT_WEIGHT_PT = 0.75;
|
|
90
|
+
|
|
91
|
+
export function documentDividerCss(style: {
|
|
92
|
+
readonly color?: string | null;
|
|
93
|
+
readonly weightPt?: number | null;
|
|
94
|
+
}): string {
|
|
95
|
+
if (style.color == null && style.weightPt == null) return "";
|
|
96
|
+
return declarations([
|
|
97
|
+
"border:0",
|
|
98
|
+
`border-top:${pt(style.weightPt ?? DIVIDER_DEFAULT_WEIGHT_PT)} solid ${style.color ?? DIVIDER_DEFAULT_COLOR}`,
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type DocumentRowLine = { readonly color: string; readonly weightPt: number };
|
|
103
|
+
|
|
104
|
+
export type DocumentRowEdges = {
|
|
105
|
+
readonly top: DocumentRowLine | null;
|
|
106
|
+
readonly bottom: DocumentRowLine | null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// The rule between two rows is one edge: a row's own line wins, otherwise it mirrors its
|
|
110
|
+
// neighbour's, so a thin dark rule is not outvoted by the table style's rule on the other cell.
|
|
111
|
+
// A repeat row expands into any number of rows at render time, so a neighbour's line cannot be
|
|
112
|
+
// mirrored onto it (it would hit every copy) and its own lines are never mirrored outward.
|
|
113
|
+
export function resolveRowEdges(
|
|
114
|
+
rows: ReadonlyArray<{
|
|
115
|
+
readonly lineAbove: DocumentRowLine | null;
|
|
116
|
+
readonly lineBelow: DocumentRowLine | null;
|
|
117
|
+
readonly repeats?: boolean;
|
|
118
|
+
}>,
|
|
119
|
+
): DocumentRowEdges[] {
|
|
120
|
+
const mirrorable = (index: number): boolean => rows[index]?.repeats !== true;
|
|
121
|
+
return rows.map((row, index) => {
|
|
122
|
+
const own = mirrorable(index);
|
|
123
|
+
return {
|
|
124
|
+
top:
|
|
125
|
+
row.lineAbove ??
|
|
126
|
+
(own && mirrorable(index - 1) ? (rows[index - 1]?.lineBelow ?? null) : null),
|
|
127
|
+
bottom:
|
|
128
|
+
row.lineBelow ??
|
|
129
|
+
(own && mirrorable(index + 1) ? (rows[index + 1]?.lineAbove ?? null) : null),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type DocumentCellStyle = {
|
|
135
|
+
readonly background?: string | null;
|
|
136
|
+
readonly paddingMm?: number | null;
|
|
137
|
+
readonly isFirstInRow?: boolean;
|
|
138
|
+
readonly isLastInRow?: boolean;
|
|
139
|
+
readonly edges?: DocumentRowEdges | undefined;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// 6px, the inset the layout's header background restores: a filled cell must not run flush against its text.
|
|
143
|
+
export const FILLED_CELL_EDGE_INSET_MM = 1.5875;
|
|
144
|
+
|
|
145
|
+
function ruleCss(side: "top" | "bottom", line: DocumentRowLine | null | undefined): string | null {
|
|
146
|
+
return line == null ? null : `border-${side}:${pt(line.weightPt)} solid ${line.color}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The outer columns of a table print flush with the text margin; a filled outer cell keeps an inset so its text stays inside the fill.
|
|
150
|
+
export function documentCellStyleCss(style: DocumentCellStyle): string {
|
|
151
|
+
const hasBackground = style.background != null;
|
|
152
|
+
const padding = style.paddingMm ?? null;
|
|
153
|
+
const outerMm = hasBackground ? (padding ?? FILLED_CELL_EDGE_INSET_MM) : null;
|
|
154
|
+
const left = style.isFirstInRow === true ? outerMm : padding;
|
|
155
|
+
const right = style.isLastInRow === true ? outerMm : padding;
|
|
156
|
+
return declarations([
|
|
157
|
+
hasBackground ? `background-color:${style.background}` : null,
|
|
158
|
+
padding === null ? null : `padding-top:${mm(padding)};padding-bottom:${mm(padding)}`,
|
|
159
|
+
left === null ? null : `padding-left:${mm(left)}`,
|
|
160
|
+
right === null ? null : `padding-right:${mm(right)}`,
|
|
161
|
+
ruleCss("top", style.edges?.top),
|
|
162
|
+
ruleCss("bottom", style.edges?.bottom),
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type DocumentTableStyle = {
|
|
167
|
+
readonly widthMm?: number | null;
|
|
168
|
+
readonly align?: "left" | "center" | "right" | null;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export function documentTableCss(style: DocumentTableStyle): string {
|
|
172
|
+
return declarations([
|
|
173
|
+
style.widthMm == null ? null : `width:${mm(style.widthMm)};max-width:100%`,
|
|
174
|
+
style.align == null ? null : IMAGE_ALIGN_MARGINS[style.align],
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Gap between the bottom of a flow-reserving frame and the first flowing line, shared by the
|
|
179
|
+
// editor's reserved area and the PDF's first-page spacer.
|
|
180
|
+
export const FRAME_FLOW_GAP_MM = 8;
|
|
181
|
+
|
|
182
|
+
// Effective paragraph defaults when nothing is set: the PDF body and the editor paper both use
|
|
183
|
+
// them, so a line sits at the same height in both.
|
|
184
|
+
export const PARAGRAPH_DEFAULT_LINE_HEIGHT = 1.2;
|
|
185
|
+
// One "line" (the body size times the default line height) is the spacing unit of paragraphs,
|
|
186
|
+
// headings, tables and lists, so text sits on a line grid with one blank line between blocks.
|
|
187
|
+
export function documentLinePt(fontSizePt: number): number {
|
|
188
|
+
return Number((fontSizePt * PARAGRAPH_DEFAULT_LINE_HEIGHT).toFixed(2));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const DOCUMENT_LINE_VARIABLE = "--doc-line";
|
|
192
|
+
|
|
193
|
+
export const SENDER_LINE_SIZE_PT = 7;
|
|
194
|
+
const SENDER_LINE_INSET_MM = 1.7;
|
|
195
|
+
const SENDER_LINE_RECIPIENT_GAP_MM = 4;
|
|
196
|
+
const SENDER_LINE_RULE_COLOR = "#8a877e";
|
|
197
|
+
|
|
198
|
+
// Every paragraph of an address frame starts at the page's text margin, or inset when the frame
|
|
199
|
+
// sits right of it; the sender line also carries the rule and the gap to the recipient. Only
|
|
200
|
+
// emitted for a real sender line, so an address frame without one starts with the recipient.
|
|
201
|
+
export function addressParagraphCss(isSenderLine: boolean): string {
|
|
202
|
+
return declarations([
|
|
203
|
+
`margin-left:max(${mm(SENDER_LINE_INSET_MM)},calc(var(--paper-margin-left,0px) - var(--frame-x,0px)))`,
|
|
204
|
+
`padding-right:${mm(SENDER_LINE_INSET_MM)}`,
|
|
205
|
+
"margin-bottom:0",
|
|
206
|
+
...(isSenderLine
|
|
207
|
+
? [
|
|
208
|
+
`border-bottom:1px solid ${SENDER_LINE_RULE_COLOR}`,
|
|
209
|
+
`margin-bottom:${mm(SENDER_LINE_RECIPIENT_GAP_MM)}`,
|
|
210
|
+
`padding-bottom:${mm(0.7)}`,
|
|
211
|
+
]
|
|
212
|
+
: []),
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import type { Editor } from "@tiptap/core";
|
|
2
|
+
import { NodeSelection } from "@tiptap/pm/state";
|
|
2
3
|
import { BubbleMenu } from "@tiptap/react/menus";
|
|
3
4
|
import type { ReactNode } from "react";
|
|
4
5
|
import { DOCUMENT_BLOCK_ATTRIBUTE } from "./document-editor-extensions.ts";
|
|
6
|
+
import {
|
|
7
|
+
DIVIDER_WEIGHT_PT_RANGE,
|
|
8
|
+
DOCUMENT_IMAGE_ALIGNMENTS,
|
|
9
|
+
IMAGE_WIDTH_MM_RANGE,
|
|
10
|
+
} from "./document-print-style.ts";
|
|
11
|
+
import { DOCUMENT_DATE_STYLES } from "./document-schema.ts";
|
|
5
12
|
import type { TiptapContext } from "./document-tiptap-context.ts";
|
|
6
13
|
import {
|
|
7
14
|
buttonTargetLabel,
|
|
15
|
+
type DividerBlock,
|
|
8
16
|
findRepeatTable,
|
|
17
|
+
type ResourceBlock,
|
|
9
18
|
type SelectedBlock,
|
|
10
19
|
toggleRepeatHeader,
|
|
20
|
+
type VariableBlock,
|
|
11
21
|
} from "./document-tiptap-helpers.ts";
|
|
22
|
+
import { colorPicker, renderNumberField } from "./document-tiptap-toolbar-groups.tsx";
|
|
12
23
|
|
|
13
24
|
// The bubble menu registers its plugin once per mount, so a rebuilt editor needs a fresh mount.
|
|
14
25
|
const editorMountKeys = new WeakMap<Editor, number>();
|
|
@@ -45,9 +56,21 @@ function selectedBlockReference(editor: Editor): {
|
|
|
45
56
|
getClientRects: () => DOMRect[];
|
|
46
57
|
contextElement: Element;
|
|
47
58
|
} | null {
|
|
48
|
-
const {
|
|
49
|
-
|
|
50
|
-
const
|
|
59
|
+
const { selection } = editor.state;
|
|
60
|
+
// A selected leaf (divider) is its own reference; domAtPos would point at its parent.
|
|
61
|
+
const selectedNode =
|
|
62
|
+
selection instanceof NodeSelection ? editor.view.nodeDOM(selection.from) : null;
|
|
63
|
+
const { node } = editor.view.domAtPos(selection.from);
|
|
64
|
+
const start =
|
|
65
|
+
selectedNode instanceof Element
|
|
66
|
+
? selectedNode
|
|
67
|
+
: node instanceof Element
|
|
68
|
+
? node
|
|
69
|
+
: node.parentElement;
|
|
70
|
+
const block =
|
|
71
|
+
selectedNode instanceof Element
|
|
72
|
+
? selectedNode
|
|
73
|
+
: start?.closest(`[${DOCUMENT_BLOCK_ATTRIBUTE}], table`);
|
|
51
74
|
if (block === null || block === undefined) return null;
|
|
52
75
|
return {
|
|
53
76
|
getBoundingClientRect: () => block.getBoundingClientRect(),
|
|
@@ -69,21 +92,161 @@ function repeatBarLabelOf(c: TiptapContext): string {
|
|
|
69
92
|
: t("template-resolver.documentEditor.repeatBarList", { list: repeatListLabel });
|
|
70
93
|
}
|
|
71
94
|
|
|
72
|
-
|
|
95
|
+
// The print attributes of the selected block; an empty field removes the attribute again.
|
|
96
|
+
function setBlockAttributes(
|
|
97
|
+
editor: Editor,
|
|
98
|
+
nodeName: "resource" | "divider",
|
|
99
|
+
attributes: Readonly<Record<string, unknown>>,
|
|
100
|
+
): void {
|
|
101
|
+
editor.chain().focus().updateAttributes(nodeName, attributes).run();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function renderImagePrintControls(c: TiptapContext, selectedBlock: ResourceBlock): ReactNode {
|
|
73
105
|
const { t, Button, editor } = c;
|
|
74
106
|
return (
|
|
75
|
-
|
|
107
|
+
<>
|
|
108
|
+
{renderNumberField(c, {
|
|
109
|
+
id: "document-image-width",
|
|
110
|
+
label: t("documentDesigner.editor.imageWidth"),
|
|
111
|
+
value: selectedBlock.widthMm,
|
|
112
|
+
range: IMAGE_WIDTH_MM_RANGE,
|
|
113
|
+
onChange: (widthMm) => setBlockAttributes(editor, "resource", { widthMm }),
|
|
114
|
+
})}
|
|
115
|
+
{DOCUMENT_IMAGE_ALIGNMENTS.map((align) => (
|
|
116
|
+
<Button
|
|
117
|
+
key={align}
|
|
118
|
+
type="button"
|
|
119
|
+
size="sm"
|
|
120
|
+
variant="secondary"
|
|
121
|
+
pressed={selectedBlock.align === align}
|
|
122
|
+
testId={`document-image-align-${align}`}
|
|
123
|
+
onClick={() =>
|
|
124
|
+
setBlockAttributes(editor, "resource", {
|
|
125
|
+
align: selectedBlock.align === align ? null : align,
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
>
|
|
129
|
+
{t(`documentDesigner.editor.imageAlign.${align}`)}
|
|
130
|
+
</Button>
|
|
131
|
+
))}
|
|
132
|
+
</>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function renderDividerControls(c: TiptapContext, selectedBlock: DividerBlock): ReactNode {
|
|
137
|
+
const { t, editor } = c;
|
|
138
|
+
return (
|
|
139
|
+
<>
|
|
140
|
+
{colorPicker(
|
|
141
|
+
c,
|
|
142
|
+
"document-divider-color",
|
|
143
|
+
t("documentDesigner.editor.dividerColor"),
|
|
144
|
+
selectedBlock.color,
|
|
145
|
+
(color) => setBlockAttributes(editor, "divider", { color }),
|
|
146
|
+
)}
|
|
147
|
+
{renderNumberField(c, {
|
|
148
|
+
id: "document-divider-weight",
|
|
149
|
+
label: t("documentDesigner.editor.dividerWeight"),
|
|
150
|
+
value: selectedBlock.weightPt,
|
|
151
|
+
range: DIVIDER_WEIGHT_PT_RANGE,
|
|
152
|
+
onChange: (weightPt) => setBlockAttributes(editor, "divider", { weightPt }),
|
|
153
|
+
})}
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function renderDateStyleControls(c: TiptapContext, selectedBlock: VariableBlock): ReactNode {
|
|
159
|
+
const { t, Button, editor } = c;
|
|
160
|
+
return (
|
|
161
|
+
<>
|
|
162
|
+
<span className="text-[10px] text-muted-foreground">
|
|
163
|
+
{t("documentDesigner.editor.dateFormat")}
|
|
164
|
+
</span>
|
|
165
|
+
{DOCUMENT_DATE_STYLES.map((style) => (
|
|
166
|
+
<Button
|
|
167
|
+
key={style}
|
|
168
|
+
type="button"
|
|
169
|
+
size="sm"
|
|
170
|
+
variant="secondary"
|
|
171
|
+
pressed={(selectedBlock.dateStyle ?? "long") === style}
|
|
172
|
+
disabled={c.readOnly}
|
|
173
|
+
testId={`document-date-style-${style}`}
|
|
174
|
+
onClick={() => {
|
|
175
|
+
editor
|
|
176
|
+
.chain()
|
|
177
|
+
.focus()
|
|
178
|
+
.updateAttributes("variable", { dateStyle: style === "long" ? null : style })
|
|
179
|
+
.run();
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
{t(`documentDesigner.editor.dateFormat.${style}`)}
|
|
183
|
+
</Button>
|
|
184
|
+
))}
|
|
185
|
+
</>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function blockOptionsTitle(c: TiptapContext, selectedBlock: SelectedBlock): ReactNode {
|
|
190
|
+
const { t } = c;
|
|
191
|
+
if (selectedBlock.type === "variable") {
|
|
192
|
+
return (
|
|
76
193
|
<span className="px-1.5 text-[10px] text-muted-foreground">
|
|
77
|
-
{
|
|
78
|
-
? t("template-resolver.documentEditor.resourceKey")
|
|
79
|
-
: t("template-resolver.documentEditor.buttonTarget")}
|
|
194
|
+
{t("documentDesigner.editor.placeholderTitle")}
|
|
80
195
|
{": "}
|
|
81
|
-
{selectedBlock.
|
|
82
|
-
<strong>{buttonTargetLabel(selectedBlock.detail, c.variableLabels)}</strong>
|
|
83
|
-
) : (
|
|
84
|
-
<code>{selectedBlock.detail}</code>
|
|
85
|
-
)}
|
|
196
|
+
<strong>{c.variableLabels[selectedBlock.detail] ?? selectedBlock.detail}</strong>
|
|
86
197
|
</span>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (selectedBlock.type === "divider") {
|
|
201
|
+
return (
|
|
202
|
+
<span className="px-1.5 text-[10px] text-muted-foreground">
|
|
203
|
+
{t("documentDesigner.editor.divider")}
|
|
204
|
+
</span>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return (
|
|
208
|
+
<span className="px-1.5 text-[10px] text-muted-foreground">
|
|
209
|
+
{selectedBlock.type === "resource"
|
|
210
|
+
? t("template-resolver.documentEditor.resourceKey")
|
|
211
|
+
: t("template-resolver.documentEditor.buttonTarget")}
|
|
212
|
+
{": "}
|
|
213
|
+
{selectedBlock.type === "button" ? (
|
|
214
|
+
<strong>{buttonTargetLabel(selectedBlock.detail, c.variableLabels)}</strong>
|
|
215
|
+
) : (
|
|
216
|
+
<code>{selectedBlock.detail}</code>
|
|
217
|
+
)}
|
|
218
|
+
</span>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function renderBlockOptionsBar(c: TiptapContext, selectedBlock: SelectedBlock): ReactNode {
|
|
223
|
+
const { t, Button, editor } = c;
|
|
224
|
+
return (
|
|
225
|
+
<div className={BUBBLE_BAR_CLASS} data-testid="document-block-options">
|
|
226
|
+
{blockOptionsTitle(c, selectedBlock)}
|
|
227
|
+
{selectedBlock.type === "resource" &&
|
|
228
|
+
c.print !== "none" &&
|
|
229
|
+
renderImagePrintControls(c, selectedBlock)}
|
|
230
|
+
{selectedBlock.type === "divider" && renderDividerControls(c, selectedBlock)}
|
|
231
|
+
{selectedBlock.type === "variable" && renderDateStyleControls(c, selectedBlock)}
|
|
232
|
+
{selectedBlock.type === "resource" && c.hosted && c.print === "flow" && (
|
|
233
|
+
<Button
|
|
234
|
+
type="button"
|
|
235
|
+
size="sm"
|
|
236
|
+
variant="secondary"
|
|
237
|
+
pressed={selectedBlock.bleed}
|
|
238
|
+
testId="document-image-bleed"
|
|
239
|
+
onClick={() => {
|
|
240
|
+
editor
|
|
241
|
+
.chain()
|
|
242
|
+
.focus()
|
|
243
|
+
.updateAttributes("resource", { bleed: !selectedBlock.bleed })
|
|
244
|
+
.run();
|
|
245
|
+
}}
|
|
246
|
+
>
|
|
247
|
+
{t("documentDesigner.editor.imageBleed")}
|
|
248
|
+
</Button>
|
|
249
|
+
)}
|
|
87
250
|
<Button
|
|
88
251
|
type="button"
|
|
89
252
|
size="sm"
|
|
@@ -102,7 +265,8 @@ function renderBubbleRepeatBar(c: TiptapContext): ReactNode {
|
|
|
102
265
|
const { t, Button, editor } = c;
|
|
103
266
|
const repeatTable = c.activeState?.repeatTable ?? null;
|
|
104
267
|
return (
|
|
105
|
-
repeatTable !== null &&
|
|
268
|
+
repeatTable !== null &&
|
|
269
|
+
c.print === "none" && (
|
|
106
270
|
<div data-testid="document-repeat-bar" className={BUBBLE_BAR_CLASS}>
|
|
107
271
|
<span className="px-1.5 text-[10px] uppercase tracking-wide text-muted-foreground">
|
|
108
272
|
{repeatBarLabelOf(c)}
|
|
@@ -131,7 +295,7 @@ export function renderBubbleMenu(c: TiptapContext): ReactNode {
|
|
|
131
295
|
editor={editor}
|
|
132
296
|
options={{
|
|
133
297
|
strategy: "fixed",
|
|
134
|
-
placement: "top-end",
|
|
298
|
+
placement: selectedBlock?.type === "resource" ? "top-start" : "top-end",
|
|
135
299
|
offset: bubbleOffset(editor),
|
|
136
300
|
scrollTarget: c.canvasScroller ?? window,
|
|
137
301
|
onShow: () => requestAnimationFrame(() => repositionBubble(editor)),
|
|
@@ -140,7 +304,11 @@ export function renderBubbleMenu(c: TiptapContext): ReactNode {
|
|
|
140
304
|
shouldShow={({ editor: e, element }) =>
|
|
141
305
|
// A leading image is selected by default; the bubble belongs to a deliberate selection.
|
|
142
306
|
(e.isFocused || element.contains(document.activeElement)) &&
|
|
143
|
-
(e.isActive("resource") ||
|
|
307
|
+
(e.isActive("resource") ||
|
|
308
|
+
e.isActive("button") ||
|
|
309
|
+
e.isActive("variable") ||
|
|
310
|
+
(c.print !== "none" && e.isActive("divider")) ||
|
|
311
|
+
(c.print === "none" && findRepeatTable(e) !== null))
|
|
144
312
|
}
|
|
145
313
|
>
|
|
146
314
|
{selectedBlock !== null ? renderBlockOptionsBar(c, selectedBlock) : renderBubbleRepeatBar(c)}
|
|
@@ -153,6 +321,7 @@ export function renderInlineRepeatBar(c: TiptapContext): ReactNode {
|
|
|
153
321
|
const repeatTable = c.activeState?.repeatTable ?? null;
|
|
154
322
|
return (
|
|
155
323
|
repeatTable !== null &&
|
|
324
|
+
c.print === "none" &&
|
|
156
325
|
!c.readOnly &&
|
|
157
326
|
!c.canvas && (
|
|
158
327
|
<div
|
|
@@ -2,8 +2,59 @@ import { cn } from "@cosmicdrift/kumiko-renderer/web";
|
|
|
2
2
|
import type { Editor } from "@tiptap/core";
|
|
3
3
|
import { EditorContent } from "@tiptap/react";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
|
+
import type { DocumentPrintMode } from "./document-toolbar-blocks.ts";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
// The PDF pads cells 4px / 6px; in paper units so the canvas lines up at every zoom.
|
|
8
|
+
const CANVAS_CELL_PADDING_CLASS =
|
|
9
|
+
"[&_td]:px-[calc(1.5875*var(--paper-mm,1mm))] [&_td]:py-[calc(1.0583*var(--paper-mm,1mm))] [&_th]:px-[calc(1.5875*var(--paper-mm,1mm))] [&_th]:py-[calc(1.0583*var(--paper-mm,1mm))]";
|
|
10
|
+
|
|
11
|
+
// The PDF has no heading rules, so the canvas copies the browser defaults (size, margin, inherited line height).
|
|
12
|
+
function headingClasses(canvas: boolean, page: boolean): string {
|
|
13
|
+
return canvas
|
|
14
|
+
? cn(
|
|
15
|
+
"[&_h1]:text-[length:2em] [&_h1]:leading-[inherit] [&_h1]:font-bold [&_h2]:text-[length:1.5em] [&_h2]:leading-[inherit] [&_h2]:font-bold [&_h3]:text-[length:1.17em] [&_h3]:leading-[inherit] [&_h3]:font-bold",
|
|
16
|
+
page
|
|
17
|
+
? "[&_:is(h1,h2,h3)]:mt-0 [&_:is(h1,h2,h3)]:mb-(--doc-line)"
|
|
18
|
+
: "[&_h1]:my-[0.67em] [&_h2]:my-[0.83em] [&_h3]:my-[1em]",
|
|
19
|
+
" [&_:is(h1,h2,h3)_[data-variable-chip]]:text-[length:calc(var(--paper-font-size)*0.9)]",
|
|
20
|
+
)
|
|
21
|
+
: "[&_h1]:text-xl [&_h1]:font-bold [&_h2]:text-lg [&_h2]:font-bold [&_h3]:text-base [&_h3]:font-bold";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function tableClasses(canvas: boolean, page: boolean): string {
|
|
25
|
+
return canvas
|
|
26
|
+
? cn(
|
|
27
|
+
page
|
|
28
|
+
? "[&_table]:mb-(--doc-line) [&_table]:mt-0 [&_.ProseMirror>.tableWrapper:last-child_table]:mb-0"
|
|
29
|
+
: "[&_table]:mb-2 [&_table]:mt-6 [&_.ProseMirror>:first-child_table]:mt-0 [&_.ProseMirror>table:first-child]:mt-0",
|
|
30
|
+
"[&_td:last-child>p[data-size=small][data-align=right]]:whitespace-nowrap",
|
|
31
|
+
)
|
|
32
|
+
: "[&_table]:my-2";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The PDF prints cells top-aligned, header like body text and no rules unless the layout sets a
|
|
36
|
+
// table style; the dashed outline only marks the cells while editing, like the frame outline.
|
|
37
|
+
function cellClasses(canvas: boolean, print: DocumentPrintMode): string {
|
|
38
|
+
return cn(
|
|
39
|
+
print !== "none"
|
|
40
|
+
? cn(
|
|
41
|
+
"[&_td]:align-top [&_th]:align-top [&_th]:font-bold",
|
|
42
|
+
"[&_td]:outline-dashed [&_td]:outline-1 [&_td]:-outline-offset-1 [&_td]:outline-border [&_th]:outline-dashed [&_th]:outline-1 [&_th]:-outline-offset-1 [&_th]:outline-border",
|
|
43
|
+
)
|
|
44
|
+
: "[&_td]:border-b [&_td]:border-border [&_th]:border-b [&_th]:border-border [&_th]:text-xs [&_th]:text-muted-foreground",
|
|
45
|
+
canvas ? CANVAS_CELL_PADDING_CLASS : "[&_td]:px-2 [&_td]:py-1.5 [&_th]:px-2 [&_th]:py-1.5",
|
|
46
|
+
print === "none" && (canvas ? "[&_th]:font-bold" : "[&_th]:font-medium"),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function renderEditorContent(
|
|
51
|
+
editor: Editor,
|
|
52
|
+
canvas: boolean,
|
|
53
|
+
hosted: boolean,
|
|
54
|
+
print: DocumentPrintMode,
|
|
55
|
+
mailSpacing = false,
|
|
56
|
+
): ReactNode {
|
|
57
|
+
const page = print === "page";
|
|
7
58
|
return (
|
|
8
59
|
<EditorContent
|
|
9
60
|
editor={editor}
|
|
@@ -14,16 +65,28 @@ export function renderEditorContent(editor: Editor, canvas: boolean, hosted: boo
|
|
|
14
65
|
hosted
|
|
15
66
|
? "[&_.ProseMirror]:outline-none"
|
|
16
67
|
: "[&_.ProseMirror]:min-h-40 [&_.ProseMirror]:outline-none",
|
|
68
|
+
// Frames are placed against the paper, so the editor root must not become their containing block.
|
|
69
|
+
// Important: prosemirror's own unlayered `.ProseMirror{position:relative}` beats the utilities layer.
|
|
70
|
+
print === "page" && "[&_.ProseMirror]:static!",
|
|
71
|
+
// The PDF gives every body paragraph this spacing (see PRINT_CSS); cells and list items stay flush.
|
|
72
|
+
page &&
|
|
73
|
+
"[&_p]:mb-(--doc-line) [&_ul]:mb-(--doc-line) [&_ol]:mb-(--doc-line) [&_td>p]:mb-0 [&_th>p]:mb-0 [&_li>p]:mb-0 [&_td>:last-child]:mb-0 [&_th>:last-child]:mb-0 [&_li>:last-child]:mb-0 [&_.ProseMirror>:last-child]:mb-0",
|
|
74
|
+
// Preflight strips paragraph and list margins; a mail body in a form field needs them back.
|
|
75
|
+
mailSpacing &&
|
|
76
|
+
"[&_p]:my-3 [&_ul]:my-3 [&_ol]:my-3 [&_li>p]:my-0 [&_.ProseMirror>:first-child]:mt-0 [&_.ProseMirror>:last-child]:mb-0",
|
|
77
|
+
print !== "none" &&
|
|
78
|
+
"[&_td]:relative [&_th]:relative [&_.column-resize-handle]:pointer-events-none [&_.column-resize-handle]:absolute [&_.column-resize-handle]:-right-0.5 [&_.column-resize-handle]:bottom-0 [&_.column-resize-handle]:top-0 [&_.column-resize-handle]:w-1 [&_.column-resize-handle]:bg-primary",
|
|
79
|
+
"[&_[data-borders=none]_td]:border-transparent [&_[data-borders=none]_th]:border-transparent",
|
|
17
80
|
"[&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-6 [&_ol]:pl-6",
|
|
18
|
-
|
|
81
|
+
headingClasses(canvas, page),
|
|
19
82
|
"[&_a]:underline [&_a]:text-primary",
|
|
20
83
|
"[&_strong]:font-bold [&_em]:italic [&_u]:underline",
|
|
21
|
-
canvas
|
|
22
|
-
|
|
23
|
-
|
|
84
|
+
tableClasses(canvas, page),
|
|
85
|
+
// A layout region has no content below its table; margins there only inflate the region box.
|
|
86
|
+
hosted && "[&_td>div]:my-0 [&_.ProseMirror>.tableWrapper:last-child_table]:mb-0",
|
|
24
87
|
"[&_table]:w-full [&_table]:border-collapse",
|
|
25
|
-
"[&_td]:
|
|
26
|
-
|
|
88
|
+
"[&_td>p]:m-0 [&_th>p]:m-0 [&_th]:text-left",
|
|
89
|
+
cellClasses(canvas, print),
|
|
27
90
|
"[&_tr[data-each]>td]:bg-muted/50",
|
|
28
91
|
"[&_[data-align=left]]:text-left [&_[data-align=center]]:text-center [&_[data-align=right]]:text-right [&_[data-align=justify]]:text-justify",
|
|
29
92
|
"[&_p[data-size=small]]:text-xs [&_p[data-size=small]]:text-muted-foreground",
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import type { Translate } from "@cosmicdrift/kumiko-renderer/headless";
|
|
2
2
|
import type { Editor } from "@tiptap/core";
|
|
3
3
|
import type { Dispatch, SetStateAction } from "react";
|
|
4
|
+
import type { PrintDefaultLabels } from "./document-print-defaults.ts";
|
|
4
5
|
import {
|
|
5
6
|
type ActiveState,
|
|
6
7
|
BLOCK_PANEL,
|
|
7
8
|
HEADING_LEVELS,
|
|
9
|
+
insertPrintBlock,
|
|
8
10
|
isParagraphStyle,
|
|
9
11
|
type PanelKind,
|
|
10
12
|
type Primitives,
|
|
11
13
|
variableLabelOf,
|
|
12
14
|
} from "./document-tiptap-helpers.ts";
|
|
13
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
DocumentPrintBlock,
|
|
17
|
+
DocumentPrintMode,
|
|
18
|
+
DocumentToolbarBlock,
|
|
19
|
+
} from "./document-toolbar-blocks.ts";
|
|
14
20
|
import type { DocumentEditorLabels } from "./use-document-tiptap-model.ts";
|
|
15
21
|
|
|
16
22
|
export type TiptapContext = {
|
|
@@ -25,6 +31,8 @@ export type TiptapContext = {
|
|
|
25
31
|
readonly canvas: boolean;
|
|
26
32
|
readonly compact: boolean;
|
|
27
33
|
readonly hosted: boolean;
|
|
34
|
+
readonly print: DocumentPrintMode;
|
|
35
|
+
readonly printDefaults: PrintDefaultLabels;
|
|
28
36
|
readonly labels: DocumentEditorLabels;
|
|
29
37
|
readonly activeState: ActiveState | null;
|
|
30
38
|
readonly openPanel: PanelKind | null;
|
|
@@ -40,6 +48,7 @@ export type TiptapContext = {
|
|
|
40
48
|
readonly stableLabels: Readonly<Record<string, string>>;
|
|
41
49
|
readonly togglePanel: (kind: PanelKind) => void;
|
|
42
50
|
readonly runBlock: (block: DocumentToolbarBlock) => void;
|
|
51
|
+
readonly runPrintBlock: (block: DocumentPrintBlock) => void;
|
|
43
52
|
readonly setBlockStyle: (style: string) => void;
|
|
44
53
|
readonly repeatListLabel: string | undefined;
|
|
45
54
|
};
|
|
@@ -57,6 +66,8 @@ export type TiptapContextInput = Pick<
|
|
|
57
66
|
| "canvas"
|
|
58
67
|
| "compact"
|
|
59
68
|
| "hosted"
|
|
69
|
+
| "print"
|
|
70
|
+
| "printDefaults"
|
|
60
71
|
| "labels"
|
|
61
72
|
| "activeState"
|
|
62
73
|
| "openPanel"
|
|
@@ -112,6 +123,7 @@ export function buildTiptapContext(input: TiptapContextInput): TiptapContext {
|
|
|
112
123
|
...input,
|
|
113
124
|
togglePanel,
|
|
114
125
|
runBlock,
|
|
126
|
+
runPrintBlock: (block) => insertPrintBlock(editor, block),
|
|
115
127
|
setBlockStyle,
|
|
116
128
|
repeatListLabel: repeatListLabelOf(input.activeState, input.variableLabels),
|
|
117
129
|
};
|