@cosmicdrift/kumiko-samples 0.419.0 → 0.421.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 +6 -1
- package/packages/bundled-features/src/auth-email-password/seeding.ts +29 -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 +24 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +7 -1
- package/packages/bundled-features/src/template-resolver/compile-document-styles.ts +70 -2
- package/packages/bundled-features/src/template-resolver/document-frames.ts +43 -0
- package/packages/bundled-features/src/template-resolver/document-op-blocks.ts +135 -21
- package/packages/bundled-features/src/template-resolver/document-ops.ts +35 -3
- package/packages/bundled-features/src/template-resolver/document-print-only.ts +24 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +13 -1
- package/packages/bundled-features/src/template-resolver/handlers/create-layout.write.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +2 -1
- package/packages/bundled-features/src/template-resolver/handlers/tenant-settings.ts +51 -14
- package/packages/bundled-features/src/template-resolver/index.ts +11 -1
- package/packages/bundled-features/src/template-resolver/template-meta.ts +7 -1
- package/packages/bundled-features/src/template-resolver/template-preview.ts +25 -4
- package/packages/bundled-features/src/template-resolver/web/constants.ts +4 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +60 -24
- package/packages/bundled-features/src/template-resolver/web/document-editor.tsx +4 -1
- package/packages/bundled-features/src/template-resolver/web/document-print-decorations.ts +55 -5
- package/packages/bundled-features/src/template-resolver/web/document-print-style.ts +137 -2
- package/packages/bundled-features/src/template-resolver/web/document-repeat-strip.ts +2 -26
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +61 -13
- package/packages/bundled-features/src/template-resolver/web/document-style-css.ts +109 -2
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +161 -14
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +4 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +2 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +132 -24
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +160 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +18 -9
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +4 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +4 -0
- package/packages/bundled-features/src/template-resolver/web/pdf-constants.ts +10 -0
- package/packages/bundled-features/src/template-resolver/web/placeholder-text.ts +6 -3
- package/packages/bundled-features/src/tenant/seeding.ts +70 -0
- 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/recipes/prod-boot-options/README.md +8 -1
- package/samples/recipes/prod-boot-options/src/app.ts +3 -1
|
@@ -17,8 +17,15 @@ import {
|
|
|
17
17
|
DocumentBlockStyleAttributes,
|
|
18
18
|
DocumentFrame,
|
|
19
19
|
DocumentTextStyleMark,
|
|
20
|
+
dividerPrintHtmlAttributes,
|
|
20
21
|
documentCellPrintAttributes,
|
|
21
|
-
|
|
22
|
+
documentRowLineAttributes,
|
|
23
|
+
documentTablePrintAttributes,
|
|
24
|
+
imagePrintHtmlAttributes,
|
|
25
|
+
readDividerColor,
|
|
26
|
+
readDividerWeightPt,
|
|
27
|
+
readImageAlign,
|
|
28
|
+
readImageWidthMm,
|
|
22
29
|
} from "./document-print-style.ts";
|
|
23
30
|
import { isDocumentReferenceName } from "./document-reference-name.ts";
|
|
24
31
|
import { createDocumentStepsNode } from "./document-steps.ts";
|
|
@@ -47,26 +54,46 @@ export const DOCUMENT_NODE_NAMES = [
|
|
|
47
54
|
"images",
|
|
48
55
|
] as const;
|
|
49
56
|
|
|
57
|
+
// "long" is what a date placeholder prints without a style, "short" is the numeric 15.01.2026.
|
|
58
|
+
export const DOCUMENT_DATE_STYLES = ["short", "long"] as const;
|
|
59
|
+
export type DocumentDateStyle = (typeof DOCUMENT_DATE_STYLES)[number];
|
|
60
|
+
|
|
61
|
+
export function readDocumentDateStyle(element: {
|
|
62
|
+
getAttribute(name: string): string | null;
|
|
63
|
+
}): DocumentDateStyle | null {
|
|
64
|
+
const style = element.getAttribute("data-date-style");
|
|
65
|
+
return isOneOf(DOCUMENT_DATE_STYLES, style) ? style : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
50
68
|
export const DocumentVariable = Node.create({
|
|
51
69
|
name: "variable",
|
|
52
70
|
group: "inline",
|
|
53
71
|
inline: true,
|
|
54
72
|
atom: true,
|
|
55
73
|
addAttributes() {
|
|
56
|
-
return { name: { default: null } };
|
|
74
|
+
return { name: { default: null }, dateStyle: { default: null } };
|
|
57
75
|
},
|
|
58
76
|
parseHTML() {
|
|
59
77
|
return [
|
|
60
|
-
|
|
78
|
+
{
|
|
61
79
|
tag: "span[data-variable]",
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
getAttrs: (element) => {
|
|
81
|
+
const name = element.getAttribute("data-variable");
|
|
82
|
+
if (name === null || !isDocumentReferenceName(name)) return false;
|
|
83
|
+
return { name, dateStyle: readDocumentDateStyle(element) };
|
|
84
|
+
},
|
|
85
|
+
},
|
|
66
86
|
];
|
|
67
87
|
},
|
|
68
88
|
renderHTML({ node }) {
|
|
69
|
-
|
|
89
|
+
const style: unknown = node.attrs["dateStyle"];
|
|
90
|
+
return [
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
"data-variable": node.attrs["name"],
|
|
94
|
+
...(isOneOf(DOCUMENT_DATE_STYLES, style) ? { "data-date-style": style } : {}),
|
|
95
|
+
},
|
|
96
|
+
];
|
|
70
97
|
},
|
|
71
98
|
});
|
|
72
99
|
|
|
@@ -75,7 +102,13 @@ export const DocumentResource = Node.create({
|
|
|
75
102
|
group: "block",
|
|
76
103
|
atom: true,
|
|
77
104
|
addAttributes() {
|
|
78
|
-
return {
|
|
105
|
+
return {
|
|
106
|
+
resource: { default: null },
|
|
107
|
+
alt: { default: null },
|
|
108
|
+
bleed: { default: false },
|
|
109
|
+
widthMm: { default: null },
|
|
110
|
+
align: { default: null },
|
|
111
|
+
};
|
|
79
112
|
},
|
|
80
113
|
parseHTML() {
|
|
81
114
|
return [
|
|
@@ -88,6 +121,8 @@ export const DocumentResource = Node.create({
|
|
|
88
121
|
resource,
|
|
89
122
|
alt: element.getAttribute("alt"),
|
|
90
123
|
bleed: element.hasAttribute("data-bleed"),
|
|
124
|
+
widthMm: readImageWidthMm(element),
|
|
125
|
+
align: readImageAlign(element),
|
|
91
126
|
};
|
|
92
127
|
},
|
|
93
128
|
},
|
|
@@ -102,6 +137,7 @@ export const DocumentResource = Node.create({
|
|
|
102
137
|
"data-resource": node.attrs["resource"],
|
|
103
138
|
...(alt === null || alt === undefined ? {} : { alt }),
|
|
104
139
|
...(node.attrs["bleed"] === true ? { "data-bleed": "" } : {}),
|
|
140
|
+
...imagePrintHtmlAttributes(node.attrs),
|
|
105
141
|
},
|
|
106
142
|
];
|
|
107
143
|
},
|
|
@@ -138,11 +174,22 @@ export const DocumentDivider = Node.create({
|
|
|
138
174
|
name: "divider",
|
|
139
175
|
group: "block",
|
|
140
176
|
atom: true,
|
|
177
|
+
addAttributes() {
|
|
178
|
+
return { color: { default: null }, weightPt: { default: null } };
|
|
179
|
+
},
|
|
141
180
|
parseHTML() {
|
|
142
|
-
return [
|
|
181
|
+
return [
|
|
182
|
+
{
|
|
183
|
+
tag: "hr",
|
|
184
|
+
getAttrs: (element) => ({
|
|
185
|
+
color: readDividerColor(element),
|
|
186
|
+
weightPt: readDividerWeightPt(element),
|
|
187
|
+
}),
|
|
188
|
+
},
|
|
189
|
+
];
|
|
143
190
|
},
|
|
144
|
-
renderHTML() {
|
|
145
|
-
return ["hr"];
|
|
191
|
+
renderHTML({ node }) {
|
|
192
|
+
return ["hr", dividerPrintHtmlAttributes(node.attrs)];
|
|
146
193
|
},
|
|
147
194
|
});
|
|
148
195
|
|
|
@@ -184,13 +231,14 @@ export const DocumentTableRow = TableRow.extend({
|
|
|
184
231
|
renderHTML: (attributes) =>
|
|
185
232
|
attributes["repeatHeader"] ? { "data-repeat-header": "" } : {},
|
|
186
233
|
},
|
|
234
|
+
...documentRowLineAttributes,
|
|
187
235
|
};
|
|
188
236
|
},
|
|
189
237
|
});
|
|
190
238
|
|
|
191
239
|
export const DocumentTable = Table.extend({
|
|
192
240
|
addAttributes() {
|
|
193
|
-
return { ...(this.parent?.() ?? {}), ...
|
|
241
|
+
return { ...(this.parent?.() ?? {}), ...documentTablePrintAttributes };
|
|
194
242
|
},
|
|
195
243
|
renderHTML({ HTMLAttributes }) {
|
|
196
244
|
return ["table", HTMLAttributes, ["tbody", 0]];
|
|
@@ -64,8 +64,115 @@ export function documentFrameCss(frame: DocumentFrameBox): string {
|
|
|
64
64
|
]);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export
|
|
68
|
-
|
|
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
|
+
]);
|
|
69
176
|
}
|
|
70
177
|
|
|
71
178
|
// Gap between the bottom of a flow-reserving frame and the first flowing line, shared by the
|
|
@@ -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,143 @@ 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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
196
|
+
<strong>{c.variableLabels[selectedBlock.detail] ?? selectedBlock.detail}</strong>
|
|
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")}
|
|
86
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)}
|
|
87
232
|
{selectedBlock.type === "resource" && c.hosted && c.print === "flow" && (
|
|
88
233
|
<Button
|
|
89
234
|
type="button"
|
|
@@ -150,7 +295,7 @@ export function renderBubbleMenu(c: TiptapContext): ReactNode {
|
|
|
150
295
|
editor={editor}
|
|
151
296
|
options={{
|
|
152
297
|
strategy: "fixed",
|
|
153
|
-
placement: "top-end",
|
|
298
|
+
placement: selectedBlock?.type === "resource" ? "top-start" : "top-end",
|
|
154
299
|
offset: bubbleOffset(editor),
|
|
155
300
|
scrollTarget: c.canvasScroller ?? window,
|
|
156
301
|
onShow: () => requestAnimationFrame(() => repositionBubble(editor)),
|
|
@@ -161,6 +306,8 @@ export function renderBubbleMenu(c: TiptapContext): ReactNode {
|
|
|
161
306
|
(e.isFocused || element.contains(document.activeElement)) &&
|
|
162
307
|
(e.isActive("resource") ||
|
|
163
308
|
e.isActive("button") ||
|
|
309
|
+
e.isActive("variable") ||
|
|
310
|
+
(c.print !== "none" && e.isActive("divider")) ||
|
|
164
311
|
(c.print === "none" && findRepeatTable(e) !== null))
|
|
165
312
|
}
|
|
166
313
|
>
|
|
@@ -52,6 +52,7 @@ export function renderEditorContent(
|
|
|
52
52
|
canvas: boolean,
|
|
53
53
|
hosted: boolean,
|
|
54
54
|
print: DocumentPrintMode,
|
|
55
|
+
mailSpacing = false,
|
|
55
56
|
): ReactNode {
|
|
56
57
|
const page = print === "page";
|
|
57
58
|
return (
|
|
@@ -70,6 +71,9 @@ export function renderEditorContent(
|
|
|
70
71
|
// The PDF gives every body paragraph this spacing (see PRINT_CSS); cells and list items stay flush.
|
|
71
72
|
page &&
|
|
72
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",
|
|
73
77
|
print !== "none" &&
|
|
74
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",
|
|
75
79
|
"[&_[data-borders=none]_td]:border-transparent [&_[data-borders=none]_th]:border-transparent",
|
|
@@ -43,6 +43,7 @@ export default function DocumentTiptapEditor({
|
|
|
43
43
|
toolbarHost,
|
|
44
44
|
onEditorReady,
|
|
45
45
|
onFrameControlChange,
|
|
46
|
+
formatting,
|
|
46
47
|
}: DocumentEditorProps): ReactNode {
|
|
47
48
|
const t = useTranslation();
|
|
48
49
|
const locale = useLocale().locale();
|
|
@@ -128,7 +129,7 @@ export default function DocumentTiptapEditor({
|
|
|
128
129
|
variableLabels,
|
|
129
130
|
stableLabels: model.stableLabels,
|
|
130
131
|
});
|
|
131
|
-
const editorContent = renderEditorContent(editor, canvas, hosted, print);
|
|
132
|
+
const editorContent = renderEditorContent(editor, canvas, hosted, print, formatting === "text");
|
|
132
133
|
|
|
133
134
|
if (hosted) return renderHostedEditor(context, toolbarHost, editorContent);
|
|
134
135
|
|