@cosmicdrift/kumiko-bundled-features 0.419.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.
Files changed (64) hide show
  1. package/dist/shared/index.d.ts +1 -0
  2. package/dist/shared/index.js +1 -0
  3. package/dist/shared/tenant-scoped-subject.d.ts +11 -0
  4. package/dist/shared/tenant-scoped-subject.js +18 -0
  5. package/dist/signature/feature.js +1 -1
  6. package/dist/signature/grant.d.ts +1 -1
  7. package/dist/signature/grant.js +7 -12
  8. package/dist/signature/png.js +35 -10
  9. package/dist/template-resolver/api.d.ts +2 -0
  10. package/dist/template-resolver/api.js +11 -7
  11. package/dist/template-resolver/compile-document-body.js +6 -5
  12. package/dist/template-resolver/compile-document-styles.js +42 -4
  13. package/dist/template-resolver/document-frames.d.ts +1 -0
  14. package/dist/template-resolver/document-frames.js +39 -2
  15. package/dist/template-resolver/document-op-blocks.d.ts +258 -24
  16. package/dist/template-resolver/document-op-blocks.js +111 -20
  17. package/dist/template-resolver/document-ops.d.ts +1030 -96
  18. package/dist/template-resolver/document-ops.js +32 -3
  19. package/dist/template-resolver/document-print-only.d.ts +2 -1
  20. package/dist/template-resolver/document-print-only.js +23 -0
  21. package/dist/template-resolver/document-sanitizer.d.ts +1 -1
  22. package/dist/template-resolver/document-sanitizer.js +6 -1
  23. package/dist/template-resolver/handlers/create-layout.write.js +1 -1
  24. package/dist/template-resolver/handlers/patch-draft.write.d.ts +512 -48
  25. package/dist/template-resolver/handlers/patch-draft.write.js +2 -1
  26. package/dist/template-resolver/handlers/tenant-settings.d.ts +7 -1
  27. package/dist/template-resolver/handlers/tenant-settings.js +25 -15
  28. package/dist/template-resolver/index.d.ts +3 -3
  29. package/dist/template-resolver/index.js +3 -3
  30. package/dist/template-resolver/template-meta.d.ts +10 -0
  31. package/dist/template-resolver/template-meta.js +7 -1
  32. package/dist/template-resolver/template-preview.js +16 -4
  33. package/dist/template-resolver/web/constants.d.ts +1 -1
  34. package/dist/template-resolver/web/constants.js +1 -1
  35. package/dist/template-resolver/web/document-editor-extensions.js +44 -19
  36. package/dist/template-resolver/web/document-editor.js +3 -1
  37. package/dist/template-resolver/web/document-print-decorations.js +53 -6
  38. package/dist/template-resolver/web/document-print-style.d.ts +81 -2
  39. package/dist/template-resolver/web/document-print-style.js +114 -2
  40. package/dist/template-resolver/web/document-repeat-strip.js +2 -26
  41. package/dist/template-resolver/web/document-schema.d.ts +5 -0
  42. package/dist/template-resolver/web/document-schema.js +50 -13
  43. package/dist/template-resolver/web/document-style-css.d.ts +35 -2
  44. package/dist/template-resolver/web/document-style-css.js +65 -1
  45. package/dist/template-resolver/web/document-tiptap-bubble.js +71 -8
  46. package/dist/template-resolver/web/document-tiptap-content.d.ts +1 -1
  47. package/dist/template-resolver/web/document-tiptap-content.js +5 -2
  48. package/dist/template-resolver/web/document-tiptap-editor.d.ts +1 -1
  49. package/dist/template-resolver/web/document-tiptap-editor.js +2 -2
  50. package/dist/template-resolver/web/document-tiptap-helpers.d.ts +32 -2
  51. package/dist/template-resolver/web/document-tiptap-helpers.js +99 -24
  52. package/dist/template-resolver/web/document-tiptap-toolbar-groups.d.ts +11 -0
  53. package/dist/template-resolver/web/document-tiptap-toolbar-groups.js +41 -3
  54. package/dist/template-resolver/web/document-tiptap-toolbar.js +13 -8
  55. package/dist/template-resolver/web/i18n.js +2 -0
  56. package/dist/template-resolver/web/index.d.ts +1 -1
  57. package/dist/template-resolver/web/index.js +1 -1
  58. package/dist/template-resolver/web/pdf-constants.d.ts +5 -0
  59. package/dist/template-resolver/web/pdf-constants.js +6 -0
  60. package/dist/template-resolver/web/placeholder-text.d.ts +2 -1
  61. package/dist/template-resolver/web/placeholder-text.js +5 -2
  62. package/package.json +19 -11
  63. package/src/signature/changes.json +6 -0
  64. package/src/template-resolver/changes.json +24 -0
@@ -3,7 +3,7 @@
3
3
  // the sanitizer keeps its guarantee that no CSS comes from the input; compile-document-styles.ts
4
4
  // turns the validated values into CSS. The read* functions are the single place that validates a
5
5
  // raw attribute, used by the tiptap parse rules here and by the compile step.
6
- import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
6
+ import { isOneOf, isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
7
7
  import { Extension, Mark, mergeAttributes, Node } from "@tiptap/core";
8
8
  import { DOCUMENT_FONTS } from "./document-fonts.js";
9
9
  import { HEX_COLOR_PATTERN } from "./mail-layout-constants.js";
@@ -12,6 +12,12 @@ export const LINE_HEIGHT_RANGE = { min: 0.8, max: 3 };
12
12
  export const PARAGRAPH_SPACE_PT_RANGE = { min: 0, max: 200 };
13
13
  export const FRAME_MM_RANGE = { min: 0, max: 1000 };
14
14
  export const COLWIDTH_PX_RANGE = { min: 1, max: 5000 };
15
+ export const IMAGE_WIDTH_MM_RANGE = { min: 0.1, max: 210 };
16
+ export const DIVIDER_WEIGHT_PT_RANGE = { min: 0.25, max: 4 };
17
+ export const CELL_PADDING_MM_RANGE = { min: 0, max: 10 };
18
+ export const TABLE_WIDTH_MM_RANGE = IMAGE_WIDTH_MM_RANGE;
19
+ export const DOCUMENT_IMAGE_ALIGNMENTS = ["left", "center", "right"];
20
+ export const DOCUMENT_TABLE_ALIGNMENTS = DOCUMENT_IMAGE_ALIGNMENTS;
15
21
  export const FRAME_PRESETS = ["address", "text"];
16
22
  const PLAIN_DECIMAL = /^\d+(\.\d+)?$/;
17
23
  function readNumber(raw, range) {
@@ -57,6 +63,53 @@ export function readFrameAttributes(element) {
57
63
  reserveFlow: element.getAttribute("data-frame-flow") !== "over",
58
64
  };
59
65
  }
66
+ export function readImageWidthMm(element) {
67
+ return readNumber(element.getAttribute("data-width-mm"), IMAGE_WIDTH_MM_RANGE);
68
+ }
69
+ export function readImageAlign(element) {
70
+ const align = element.getAttribute("data-align");
71
+ return isOneOf(DOCUMENT_IMAGE_ALIGNMENTS, align) ? align : null;
72
+ }
73
+ export function readDividerColor(element) {
74
+ return readHexColor(element.getAttribute("data-color"));
75
+ }
76
+ export function readDividerWeightPt(element) {
77
+ return readNumber(element.getAttribute("data-weight-pt"), DIVIDER_WEIGHT_PT_RANGE);
78
+ }
79
+ export function readCellPaddingMm(element) {
80
+ return readNumber(element.getAttribute("data-cell-padding-mm"), CELL_PADDING_MM_RANGE);
81
+ }
82
+ export function readTableWidthMm(element) {
83
+ return readNumber(element.getAttribute("data-table-width-mm"), TABLE_WIDTH_MM_RANGE);
84
+ }
85
+ export function readTableAlign(element) {
86
+ const align = element.getAttribute("data-table-align");
87
+ return isOneOf(DOCUMENT_TABLE_ALIGNMENTS, align) ? align : null;
88
+ }
89
+ export const ROW_LINE_ABOVE_ATTRIBUTE = "data-line-above";
90
+ export const ROW_LINE_BELOW_ATTRIBUTE = "data-line-below";
91
+ // Serialized as "#rrggbb 0.75": one attribute per edge keeps the data-* allowlist small.
92
+ export function readRowLine(element, attribute) {
93
+ const raw = element.getAttribute(attribute);
94
+ if (raw === null)
95
+ return null;
96
+ const [color, weight, ...rest] = raw.split(" ");
97
+ const weightPt = readNumber(weight ?? null, DIVIDER_WEIGHT_PT_RANGE);
98
+ const hexColor = readHexColor(color ?? null);
99
+ return rest.length === 0 && hexColor !== null && weightPt !== null
100
+ ? { color: hexColor, weightPt }
101
+ : null;
102
+ }
103
+ function isRowLine(value) {
104
+ if (!isPlainObject(value))
105
+ return false;
106
+ const { color, weightPt } = value;
107
+ return (typeof color === "string" &&
108
+ HEX_COLOR_PATTERN.test(color) &&
109
+ typeof weightPt === "number" &&
110
+ weightPt >= DIVIDER_WEIGHT_PT_RANGE.min &&
111
+ weightPt <= DIVIDER_WEIGHT_PT_RANGE.max);
112
+ }
60
113
  export function readCellBackground(element) {
61
114
  return readHexColor(element.getAttribute("data-background"));
62
115
  }
@@ -130,13 +183,58 @@ export const DocumentBlockStyleAttributes = Extension.create({
130
183
  ];
131
184
  },
132
185
  });
133
- export const documentTableBordersAttribute = {
186
+ export const documentTablePrintAttributes = {
134
187
  borders: {
135
188
  default: null,
136
189
  parseHTML: (element) => element.getAttribute("data-borders") === "none" ? "none" : null,
137
190
  renderHTML: (attributes) => attributes["borders"] === "none" ? { "data-borders": "none" } : {},
138
191
  },
192
+ cellPaddingMm: {
193
+ default: null,
194
+ parseHTML: (element) => readCellPaddingMm(element),
195
+ renderHTML: (attributes) => {
196
+ const value = attributes["cellPaddingMm"];
197
+ return typeof value === "number" ? { "data-cell-padding-mm": String(value) } : {};
198
+ },
199
+ },
200
+ widthMm: {
201
+ default: null,
202
+ parseHTML: (element) => readTableWidthMm(element),
203
+ renderHTML: (attributes) => {
204
+ const value = attributes["widthMm"];
205
+ return typeof value === "number" ? { "data-table-width-mm": String(value) } : {};
206
+ },
207
+ },
208
+ align: {
209
+ default: null,
210
+ parseHTML: (element) => readTableAlign(element),
211
+ renderHTML: (attributes) => {
212
+ const value = attributes["align"];
213
+ return isOneOf(DOCUMENT_TABLE_ALIGNMENTS, value) ? { "data-table-align": value } : {};
214
+ },
215
+ },
216
+ };
217
+ function rowLineAttribute(attribute, key) {
218
+ return {
219
+ default: null,
220
+ parseHTML: (element) => readRowLine(element, attribute),
221
+ renderHTML: (attributes) => {
222
+ const line = attributes[key];
223
+ return isRowLine(line) ? { [attribute]: `${line.color} ${line.weightPt}` } : {};
224
+ },
225
+ };
226
+ }
227
+ export const documentRowLineAttributes = {
228
+ lineAbove: rowLineAttribute(ROW_LINE_ABOVE_ATTRIBUTE, "lineAbove"),
229
+ lineBelow: rowLineAttribute(ROW_LINE_BELOW_ATTRIBUTE, "lineBelow"),
139
230
  };
231
+ export function readRowLineAttributes(attrs) {
232
+ const { lineAbove, lineBelow } = attrs;
233
+ return {
234
+ lineAbove: isRowLine(lineAbove) ? lineAbove : null,
235
+ lineBelow: isRowLine(lineBelow) ? lineBelow : null,
236
+ };
237
+ }
140
238
  export const documentCellPrintAttributes = {
141
239
  background: {
142
240
  default: null,
@@ -159,6 +257,20 @@ export const documentCellPrintAttributes = {
159
257
  },
160
258
  },
161
259
  };
260
+ export function imagePrintHtmlAttributes(attrs) {
261
+ const { widthMm, align } = attrs;
262
+ return {
263
+ ...(typeof widthMm === "number" ? { "data-width-mm": String(widthMm) } : {}),
264
+ ...(isOneOf(DOCUMENT_IMAGE_ALIGNMENTS, align) ? { "data-align": align } : {}),
265
+ };
266
+ }
267
+ export function dividerPrintHtmlAttributes(attrs) {
268
+ const { color, weightPt } = attrs;
269
+ return {
270
+ ...(typeof color === "string" && HEX_COLOR_PATTERN.test(color) ? { "data-color": color } : {}),
271
+ ...(typeof weightPt === "number" ? { "data-weight-pt": String(weightPt) } : {}),
272
+ };
273
+ }
162
274
  export const DocumentFrame = Node.create({
163
275
  name: "documentFrame",
164
276
  group: "block",
@@ -1,4 +1,5 @@
1
1
  import { Decoration } from "@tiptap/pm/view";
2
+ import { repeatListsOf, toggleRepeatHeaderAt } from "./document-tiptap-helpers.js";
2
3
  // Table start + first row + first cell: the widget sits in front of the first cell's content.
3
4
  const FIRST_CELL_CONTENT_OFFSET = 3;
4
5
  const FIRST_ROW_OFFSET_FROM_WIDGET = FIRST_CELL_CONTENT_OFFSET - 1;
@@ -7,31 +8,6 @@ const STRIP_CLASS = "absolute bottom-full left-0 z-20 box-border flex h-[calc(va
7
8
  const BUTTON_CLASS = "cursor-pointer rounded-full border px-1.5 py-px text-[1em] font-medium leading-none normal-case tracking-normal";
8
9
  const BUTTON_OFF_CLASS = `${BUTTON_CLASS} border-input bg-card text-foreground`;
9
10
  const BUTTON_ON_CLASS = `${BUTTON_CLASS} border-foreground bg-card text-foreground`;
10
- function repeatListsOf(table) {
11
- const lists = [];
12
- table.forEach((row) => {
13
- const each = row.attrs["each"];
14
- if (typeof each === "string" && each !== "" && !lists.includes(each))
15
- lists.push(each);
16
- });
17
- return lists;
18
- }
19
- function toggleHeaderAt(editor, rowPos) {
20
- editor
21
- .chain()
22
- .focus()
23
- .command(({ tr }) => {
24
- const row = tr.doc.nodeAt(rowPos);
25
- if (row === null)
26
- return false;
27
- tr.setNodeMarkup(rowPos, undefined, {
28
- ...row.attrs,
29
- repeatHeader: row.attrs["repeatHeader"] !== true,
30
- });
31
- return true;
32
- })
33
- .run();
34
- }
35
11
  function createStrip(editor, label, headerLabel, headerRepeats, getPos) {
36
12
  const strip = document.createElement("div");
37
13
  strip.className = STRIP_CLASS;
@@ -49,7 +25,7 @@ function createStrip(editor, label, headerLabel, headerRepeats, getPos) {
49
25
  button.addEventListener("click", () => {
50
26
  const pos = getPos();
51
27
  if (pos !== undefined)
52
- toggleHeaderAt(editor, pos - FIRST_ROW_OFFSET_FROM_WIDGET);
28
+ toggleRepeatHeaderAt(editor, pos - FIRST_ROW_OFFSET_FROM_WIDGET);
53
29
  });
54
30
  strip.append(name, button);
55
31
  return strip;
@@ -4,6 +4,11 @@ import { isDocumentReferenceName } from "./document-reference-name.ts";
4
4
  export { isAllowedDocumentLinkHref, isAllowedDocumentUrlHref, isDocumentPlaceholderHref, isDocumentReferenceName, };
5
5
  export declare function isDocumentResourceKey(value: string): boolean;
6
6
  export declare const DOCUMENT_NODE_NAMES: readonly ["variable", "resource", "button", "divider", "pageBreak", "steps", "images"];
7
+ export declare const DOCUMENT_DATE_STYLES: readonly ["short", "long"];
8
+ export type DocumentDateStyle = (typeof DOCUMENT_DATE_STYLES)[number];
9
+ export declare function readDocumentDateStyle(element: {
10
+ getAttribute(name: string): string | null;
11
+ }): DocumentDateStyle | null;
7
12
  export declare const DocumentVariable: Node<any, any>;
8
13
  export declare const DocumentResource: Node<any, any>;
9
14
  export declare const DocumentButton: Node<any, any>;
@@ -9,7 +9,7 @@ import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table
9
9
  import StarterKit from "@tiptap/starter-kit";
10
10
  import { createDocumentImagesNode } from "./document-images.js";
11
11
  import { isAllowedDocumentLinkHref, isAllowedDocumentUrlHref, isDocumentPlaceholderHref, } from "./document-link-policy.js";
12
- import { DocumentBlockStyleAttributes, DocumentFrame, DocumentTextStyleMark, documentCellPrintAttributes, documentTableBordersAttribute, } from "./document-print-style.js";
12
+ import { DocumentBlockStyleAttributes, DocumentFrame, DocumentTextStyleMark, dividerPrintHtmlAttributes, documentCellPrintAttributes, documentRowLineAttributes, documentTablePrintAttributes, imagePrintHtmlAttributes, readDividerColor, readDividerWeightPt, readImageAlign, readImageWidthMm, } from "./document-print-style.js";
13
13
  import { isDocumentReferenceName } from "./document-reference-name.js";
14
14
  import { createDocumentStepsNode } from "./document-steps.js";
15
15
  import { attributeParseRule } from "./tiptap-attribute-parse-rule.js";
@@ -27,26 +27,42 @@ export const DOCUMENT_NODE_NAMES = [
27
27
  "steps",
28
28
  "images",
29
29
  ];
30
+ // "long" is what a date placeholder prints without a style, "short" is the numeric 15.01.2026.
31
+ export const DOCUMENT_DATE_STYLES = ["short", "long"];
32
+ export function readDocumentDateStyle(element) {
33
+ const style = element.getAttribute("data-date-style");
34
+ return isOneOf(DOCUMENT_DATE_STYLES, style) ? style : null;
35
+ }
30
36
  export const DocumentVariable = Node.create({
31
37
  name: "variable",
32
38
  group: "inline",
33
39
  inline: true,
34
40
  atom: true,
35
41
  addAttributes() {
36
- return { name: { default: null } };
42
+ return { name: { default: null }, dateStyle: { default: null } };
37
43
  },
38
44
  parseHTML() {
39
45
  return [
40
- attributeParseRule({
46
+ {
41
47
  tag: "span[data-variable]",
42
- attribute: "data-variable",
43
- key: "name",
44
- isValid: isDocumentReferenceName,
45
- }),
48
+ getAttrs: (element) => {
49
+ const name = element.getAttribute("data-variable");
50
+ if (name === null || !isDocumentReferenceName(name))
51
+ return false;
52
+ return { name, dateStyle: readDocumentDateStyle(element) };
53
+ },
54
+ },
46
55
  ];
47
56
  },
48
57
  renderHTML({ node }) {
49
- return ["span", { "data-variable": node.attrs["name"] }];
58
+ const style = node.attrs["dateStyle"];
59
+ return [
60
+ "span",
61
+ {
62
+ "data-variable": node.attrs["name"],
63
+ ...(isOneOf(DOCUMENT_DATE_STYLES, style) ? { "data-date-style": style } : {}),
64
+ },
65
+ ];
50
66
  },
51
67
  });
52
68
  export const DocumentResource = Node.create({
@@ -54,7 +70,13 @@ export const DocumentResource = Node.create({
54
70
  group: "block",
55
71
  atom: true,
56
72
  addAttributes() {
57
- return { resource: { default: null }, alt: { default: null }, bleed: { default: false } };
73
+ return {
74
+ resource: { default: null },
75
+ alt: { default: null },
76
+ bleed: { default: false },
77
+ widthMm: { default: null },
78
+ align: { default: null },
79
+ };
58
80
  },
59
81
  parseHTML() {
60
82
  return [
@@ -68,6 +90,8 @@ export const DocumentResource = Node.create({
68
90
  resource,
69
91
  alt: element.getAttribute("alt"),
70
92
  bleed: element.hasAttribute("data-bleed"),
93
+ widthMm: readImageWidthMm(element),
94
+ align: readImageAlign(element),
71
95
  };
72
96
  },
73
97
  },
@@ -82,6 +106,7 @@ export const DocumentResource = Node.create({
82
106
  "data-resource": node.attrs["resource"],
83
107
  ...(alt === null || alt === undefined ? {} : { alt }),
84
108
  ...(node.attrs["bleed"] === true ? { "data-bleed": "" } : {}),
109
+ ...imagePrintHtmlAttributes(node.attrs),
85
110
  },
86
111
  ];
87
112
  },
@@ -116,11 +141,22 @@ export const DocumentDivider = Node.create({
116
141
  name: "divider",
117
142
  group: "block",
118
143
  atom: true,
144
+ addAttributes() {
145
+ return { color: { default: null }, weightPt: { default: null } };
146
+ },
119
147
  parseHTML() {
120
- return [{ tag: "hr" }];
148
+ return [
149
+ {
150
+ tag: "hr",
151
+ getAttrs: (element) => ({
152
+ color: readDividerColor(element),
153
+ weightPt: readDividerWeightPt(element),
154
+ }),
155
+ },
156
+ ];
121
157
  },
122
- renderHTML() {
123
- return ["hr"];
158
+ renderHTML({ node }) {
159
+ return ["hr", dividerPrintHtmlAttributes(node.attrs)];
124
160
  },
125
161
  });
126
162
  export const DocumentPageBreak = Node.create({
@@ -157,12 +193,13 @@ export const DocumentTableRow = TableRow.extend({
157
193
  parseHTML: (element) => element.hasAttribute("data-repeat-header"),
158
194
  renderHTML: (attributes) => attributes["repeatHeader"] ? { "data-repeat-header": "" } : {},
159
195
  },
196
+ ...documentRowLineAttributes,
160
197
  };
161
198
  },
162
199
  });
163
200
  export const DocumentTable = Table.extend({
164
201
  addAttributes() {
165
- return { ...(this.parent?.() ?? {}), ...documentTableBordersAttribute };
202
+ return { ...(this.parent?.() ?? {}), ...documentTablePrintAttributes };
166
203
  },
167
204
  renderHTML({ HTMLAttributes }) {
168
205
  return ["table", HTMLAttributes, ["tbody", 0]];
@@ -18,9 +18,42 @@ export type DocumentFrameBox = {
18
18
  export declare function documentTextStyleCss(style: DocumentTextStyle): string;
19
19
  export declare function documentBlockStyleCss(style: DocumentBlockStyle): string;
20
20
  export declare function documentFrameCss(frame: DocumentFrameBox): string;
21
- export declare function documentCellStyleCss(style: {
22
- readonly background?: string | null;
21
+ export type DocumentImageStyle = {
22
+ readonly widthMm?: number | null;
23
+ readonly align?: "left" | "center" | "right" | null;
24
+ };
25
+ export declare function documentImageCss(style: DocumentImageStyle): string;
26
+ export declare function documentDividerCss(style: {
27
+ readonly color?: string | null;
28
+ readonly weightPt?: number | null;
23
29
  }): string;
30
+ export type DocumentRowLine = {
31
+ readonly color: string;
32
+ readonly weightPt: number;
33
+ };
34
+ export type DocumentRowEdges = {
35
+ readonly top: DocumentRowLine | null;
36
+ readonly bottom: DocumentRowLine | null;
37
+ };
38
+ export declare function resolveRowEdges(rows: ReadonlyArray<{
39
+ readonly lineAbove: DocumentRowLine | null;
40
+ readonly lineBelow: DocumentRowLine | null;
41
+ readonly repeats?: boolean;
42
+ }>): DocumentRowEdges[];
43
+ export type DocumentCellStyle = {
44
+ readonly background?: string | null;
45
+ readonly paddingMm?: number | null;
46
+ readonly isFirstInRow?: boolean;
47
+ readonly isLastInRow?: boolean;
48
+ readonly edges?: DocumentRowEdges | undefined;
49
+ };
50
+ export declare const FILLED_CELL_EDGE_INSET_MM = 1.5875;
51
+ export declare function documentCellStyleCss(style: DocumentCellStyle): string;
52
+ export type DocumentTableStyle = {
53
+ readonly widthMm?: number | null;
54
+ readonly align?: "left" | "center" | "right" | null;
55
+ };
56
+ export declare function documentTableCss(style: DocumentTableStyle): string;
24
57
  export declare const FRAME_FLOW_GAP_MM = 8;
25
58
  export declare const PARAGRAPH_DEFAULT_LINE_HEIGHT = 1.2;
26
59
  export declare function documentLinePt(fontSizePt: number): number;
@@ -38,8 +38,72 @@ export function documentFrameCss(frame) {
38
38
  `height:${mm(frame.heightMm)}`,
39
39
  ]);
40
40
  }
41
+ const IMAGE_ALIGN_MARGINS = {
42
+ left: "margin-left:0;margin-right:auto",
43
+ center: "margin-left:auto;margin-right:auto",
44
+ right: "margin-left:auto;margin-right:0",
45
+ };
46
+ // An explicit width replaces the region's height cap, so a layout logo can be as large as the author set it.
47
+ export function documentImageCss(style) {
48
+ return declarations([
49
+ style.widthMm == null
50
+ ? null
51
+ : `width:${mm(style.widthMm)};max-width:100%;height:auto;max-height:none`,
52
+ style.align == null ? null : `display:block;${IMAGE_ALIGN_MARGINS[style.align]}`,
53
+ ]);
54
+ }
55
+ const DIVIDER_DEFAULT_COLOR = "#bbb";
56
+ const DIVIDER_DEFAULT_WEIGHT_PT = 0.75;
57
+ export function documentDividerCss(style) {
58
+ if (style.color == null && style.weightPt == null)
59
+ return "";
60
+ return declarations([
61
+ "border:0",
62
+ `border-top:${pt(style.weightPt ?? DIVIDER_DEFAULT_WEIGHT_PT)} solid ${style.color ?? DIVIDER_DEFAULT_COLOR}`,
63
+ ]);
64
+ }
65
+ // The rule between two rows is one edge: a row's own line wins, otherwise it mirrors its
66
+ // neighbour's, so a thin dark rule is not outvoted by the table style's rule on the other cell.
67
+ // A repeat row expands into any number of rows at render time, so a neighbour's line cannot be
68
+ // mirrored onto it (it would hit every copy) and its own lines are never mirrored outward.
69
+ export function resolveRowEdges(rows) {
70
+ const mirrorable = (index) => rows[index]?.repeats !== true;
71
+ return rows.map((row, index) => {
72
+ const own = mirrorable(index);
73
+ return {
74
+ top: row.lineAbove ??
75
+ (own && mirrorable(index - 1) ? (rows[index - 1]?.lineBelow ?? null) : null),
76
+ bottom: row.lineBelow ??
77
+ (own && mirrorable(index + 1) ? (rows[index + 1]?.lineAbove ?? null) : null),
78
+ };
79
+ });
80
+ }
81
+ // 6px, the inset the layout's header background restores: a filled cell must not run flush against its text.
82
+ export const FILLED_CELL_EDGE_INSET_MM = 1.5875;
83
+ function ruleCss(side, line) {
84
+ return line == null ? null : `border-${side}:${pt(line.weightPt)} solid ${line.color}`;
85
+ }
86
+ // 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.
41
87
  export function documentCellStyleCss(style) {
42
- return style.background == null ? "" : `background-color:${style.background}`;
88
+ const hasBackground = style.background != null;
89
+ const padding = style.paddingMm ?? null;
90
+ const outerMm = hasBackground ? (padding ?? FILLED_CELL_EDGE_INSET_MM) : null;
91
+ const left = style.isFirstInRow === true ? outerMm : padding;
92
+ const right = style.isLastInRow === true ? outerMm : padding;
93
+ return declarations([
94
+ hasBackground ? `background-color:${style.background}` : null,
95
+ padding === null ? null : `padding-top:${mm(padding)};padding-bottom:${mm(padding)}`,
96
+ left === null ? null : `padding-left:${mm(left)}`,
97
+ right === null ? null : `padding-right:${mm(right)}`,
98
+ ruleCss("top", style.edges?.top),
99
+ ruleCss("bottom", style.edges?.bottom),
100
+ ]);
101
+ }
102
+ export function documentTableCss(style) {
103
+ return declarations([
104
+ style.widthMm == null ? null : `width:${mm(style.widthMm)};max-width:100%`,
105
+ style.align == null ? null : IMAGE_ALIGN_MARGINS[style.align],
106
+ ]);
43
107
  }
44
108
  // Gap between the bottom of a flow-reserving frame and the first flowing line, shared by the
45
109
  // editor's reserved area and the PDF's first-page spacer.
@@ -1,7 +1,11 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { NodeSelection } from "@tiptap/pm/state";
2
3
  import { BubbleMenu } from "@tiptap/react/menus";
3
4
  import { DOCUMENT_BLOCK_ATTRIBUTE } from "./document-editor-extensions.js";
5
+ import { DIVIDER_WEIGHT_PT_RANGE, DOCUMENT_IMAGE_ALIGNMENTS, IMAGE_WIDTH_MM_RANGE, } from "./document-print-style.js";
6
+ import { DOCUMENT_DATE_STYLES } from "./document-schema.js";
4
7
  import { buttonTargetLabel, findRepeatTable, toggleRepeatHeader, } from "./document-tiptap-helpers.js";
8
+ import { colorPicker, renderNumberField } from "./document-tiptap-toolbar-groups.js";
5
9
  // The bubble menu registers its plugin once per mount, so a rebuilt editor needs a fresh mount.
6
10
  const editorMountKeys = new WeakMap();
7
11
  let lastMountKey = 0;
@@ -26,9 +30,18 @@ function bubbleOffset(editor) {
26
30
  const BUBBLE_MENU_PLUGIN_KEY = "documentBlockOptions";
27
31
  // The options bar belongs to the block frame, not to the caret inside it.
28
32
  function selectedBlockReference(editor) {
29
- const { node } = editor.view.domAtPos(editor.state.selection.from);
30
- const start = node instanceof Element ? node : node.parentElement;
31
- const block = start?.closest(`[${DOCUMENT_BLOCK_ATTRIBUTE}], table`);
33
+ const { selection } = editor.state;
34
+ // A selected leaf (divider) is its own reference; domAtPos would point at its parent.
35
+ const selectedNode = selection instanceof NodeSelection ? editor.view.nodeDOM(selection.from) : null;
36
+ const { node } = editor.view.domAtPos(selection.from);
37
+ const start = selectedNode instanceof Element
38
+ ? selectedNode
39
+ : node instanceof Element
40
+ ? node
41
+ : node.parentElement;
42
+ const block = selectedNode instanceof Element
43
+ ? selectedNode
44
+ : start?.closest(`[${DOCUMENT_BLOCK_ATTRIBUTE}], table`);
32
45
  if (block === null || block === undefined)
33
46
  return null;
34
47
  return {
@@ -49,11 +62,59 @@ function repeatBarLabelOf(c) {
49
62
  ? t("template-resolver.documentEditor.repeat")
50
63
  : t("template-resolver.documentEditor.repeatBarList", { list: repeatListLabel });
51
64
  }
65
+ // The print attributes of the selected block; an empty field removes the attribute again.
66
+ function setBlockAttributes(editor, nodeName, attributes) {
67
+ editor.chain().focus().updateAttributes(nodeName, attributes).run();
68
+ }
69
+ function renderImagePrintControls(c, selectedBlock) {
70
+ const { t, Button, editor } = c;
71
+ return (_jsxs(_Fragment, { children: [renderNumberField(c, {
72
+ id: "document-image-width",
73
+ label: t("documentDesigner.editor.imageWidth"),
74
+ value: selectedBlock.widthMm,
75
+ range: IMAGE_WIDTH_MM_RANGE,
76
+ onChange: (widthMm) => setBlockAttributes(editor, "resource", { widthMm }),
77
+ }), DOCUMENT_IMAGE_ALIGNMENTS.map((align) => (_jsx(Button, { type: "button", size: "sm", variant: "secondary", pressed: selectedBlock.align === align, testId: `document-image-align-${align}`, onClick: () => setBlockAttributes(editor, "resource", {
78
+ align: selectedBlock.align === align ? null : align,
79
+ }), children: t(`documentDesigner.editor.imageAlign.${align}`) }, align)))] }));
80
+ }
81
+ function renderDividerControls(c, selectedBlock) {
82
+ const { t, editor } = c;
83
+ return (_jsxs(_Fragment, { children: [colorPicker(c, "document-divider-color", t("documentDesigner.editor.dividerColor"), selectedBlock.color, (color) => setBlockAttributes(editor, "divider", { color })), renderNumberField(c, {
84
+ id: "document-divider-weight",
85
+ label: t("documentDesigner.editor.dividerWeight"),
86
+ value: selectedBlock.weightPt,
87
+ range: DIVIDER_WEIGHT_PT_RANGE,
88
+ onChange: (weightPt) => setBlockAttributes(editor, "divider", { weightPt }),
89
+ })] }));
90
+ }
91
+ function renderDateStyleControls(c, selectedBlock) {
92
+ const { t, Button, editor } = c;
93
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-[10px] text-muted-foreground", children: t("documentDesigner.editor.dateFormat") }), DOCUMENT_DATE_STYLES.map((style) => (_jsx(Button, { type: "button", size: "sm", variant: "secondary", pressed: (selectedBlock.dateStyle ?? "long") === style, disabled: c.readOnly, testId: `document-date-style-${style}`, onClick: () => {
94
+ editor
95
+ .chain()
96
+ .focus()
97
+ .updateAttributes("variable", { dateStyle: style === "long" ? null : style })
98
+ .run();
99
+ }, children: t(`documentDesigner.editor.dateFormat.${style}`) }, style)))] }));
100
+ }
101
+ function blockOptionsTitle(c, selectedBlock) {
102
+ const { t } = c;
103
+ if (selectedBlock.type === "variable") {
104
+ return (_jsxs("span", { className: "px-1.5 text-[10px] text-muted-foreground", children: [t("documentDesigner.editor.placeholderTitle"), ": ", _jsx("strong", { children: c.variableLabels[selectedBlock.detail] ?? selectedBlock.detail })] }));
105
+ }
106
+ if (selectedBlock.type === "divider") {
107
+ return (_jsx("span", { className: "px-1.5 text-[10px] text-muted-foreground", children: t("documentDesigner.editor.divider") }));
108
+ }
109
+ return (_jsxs("span", { className: "px-1.5 text-[10px] text-muted-foreground", children: [selectedBlock.type === "resource"
110
+ ? t("template-resolver.documentEditor.resourceKey")
111
+ : t("template-resolver.documentEditor.buttonTarget"), ": ", selectedBlock.type === "button" ? (_jsx("strong", { children: buttonTargetLabel(selectedBlock.detail, c.variableLabels) })) : (_jsx("code", { children: selectedBlock.detail }))] }));
112
+ }
52
113
  function renderBlockOptionsBar(c, selectedBlock) {
53
114
  const { t, Button, editor } = c;
54
- return (_jsxs("div", { className: BUBBLE_BAR_CLASS, "data-testid": "document-block-options", children: [_jsxs("span", { className: "px-1.5 text-[10px] text-muted-foreground", children: [selectedBlock.type === "resource"
55
- ? t("template-resolver.documentEditor.resourceKey")
56
- : t("template-resolver.documentEditor.buttonTarget"), ": ", selectedBlock.type === "button" ? (_jsx("strong", { children: buttonTargetLabel(selectedBlock.detail, c.variableLabels) })) : (_jsx("code", { children: selectedBlock.detail }))] }), selectedBlock.type === "resource" && c.hosted && c.print === "flow" && (_jsx(Button, { type: "button", size: "sm", variant: "secondary", pressed: selectedBlock.bleed, testId: "document-image-bleed", onClick: () => {
115
+ return (_jsxs("div", { className: BUBBLE_BAR_CLASS, "data-testid": "document-block-options", children: [blockOptionsTitle(c, selectedBlock), selectedBlock.type === "resource" &&
116
+ c.print !== "none" &&
117
+ renderImagePrintControls(c, selectedBlock), selectedBlock.type === "divider" && renderDividerControls(c, selectedBlock), selectedBlock.type === "variable" && renderDateStyleControls(c, selectedBlock), selectedBlock.type === "resource" && c.hosted && c.print === "flow" && (_jsx(Button, { type: "button", size: "sm", variant: "secondary", pressed: selectedBlock.bleed, testId: "document-image-bleed", onClick: () => {
57
118
  editor
58
119
  .chain()
59
120
  .focus()
@@ -74,7 +135,7 @@ export function renderBubbleMenu(c) {
74
135
  const selectedBlock = c.activeState?.selectedBlock ?? null;
75
136
  return (_jsx(BubbleMenu, { pluginKey: BUBBLE_MENU_PLUGIN_KEY, editor: editor, options: {
76
137
  strategy: "fixed",
77
- placement: "top-end",
138
+ placement: selectedBlock?.type === "resource" ? "top-start" : "top-end",
78
139
  offset: bubbleOffset(editor),
79
140
  scrollTarget: c.canvasScroller ?? window,
80
141
  onShow: () => requestAnimationFrame(() => repositionBubble(editor)),
@@ -83,6 +144,8 @@ export function renderBubbleMenu(c) {
83
144
  (e.isFocused || element.contains(document.activeElement)) &&
84
145
  (e.isActive("resource") ||
85
146
  e.isActive("button") ||
147
+ e.isActive("variable") ||
148
+ (c.print !== "none" && e.isActive("divider")) ||
86
149
  (c.print === "none" && findRepeatTable(e) !== null)), children: selectedBlock !== null ? renderBlockOptionsBar(c, selectedBlock) : renderBubbleRepeatBar(c) }, mountKeyOf(editor)));
87
150
  }
88
151
  export function renderInlineRepeatBar(c) {
@@ -1,4 +1,4 @@
1
1
  import type { Editor } from "@tiptap/core";
2
2
  import type { ReactNode } from "react";
3
3
  import type { DocumentPrintMode } from "./document-toolbar-blocks.ts";
4
- export declare function renderEditorContent(editor: Editor, canvas: boolean, hosted: boolean, print: DocumentPrintMode): ReactNode;
4
+ export declare function renderEditorContent(editor: Editor, canvas: boolean, hosted: boolean, print: DocumentPrintMode, mailSpacing?: boolean): ReactNode;
@@ -25,7 +25,7 @@ function cellClasses(canvas, print) {
25
25
  ? cn("[&_td]:align-top [&_th]:align-top [&_th]:font-bold", "[&_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")
26
26
  : "[&_td]:border-b [&_td]:border-border [&_th]:border-b [&_th]:border-border [&_th]:text-xs [&_th]:text-muted-foreground", canvas ? CANVAS_CELL_PADDING_CLASS : "[&_td]:px-2 [&_td]:py-1.5 [&_th]:px-2 [&_th]:py-1.5", print === "none" && (canvas ? "[&_th]:font-bold" : "[&_th]:font-medium"));
27
27
  }
28
- export function renderEditorContent(editor, canvas, hosted, print) {
28
+ export function renderEditorContent(editor, canvas, hosted, print, mailSpacing = false) {
29
29
  const page = print === "page";
30
30
  return (_jsx(EditorContent, { editor: editor, className: cn(!canvas && "min-h-40 px-3 py-2 text-base outline-none md:text-sm", canvas && "text-sm", "[&_.ProseMirror-focused_.ProseMirror-selectednode]:ring-2 [&_.ProseMirror-focused_.ProseMirror-selectednode]:ring-primary", hosted
31
31
  ? "[&_.ProseMirror]:outline-none"
@@ -35,7 +35,10 @@ export function renderEditorContent(editor, canvas, hosted, print) {
35
35
  print === "page" && "[&_.ProseMirror]:static!",
36
36
  // The PDF gives every body paragraph this spacing (see PRINT_CSS); cells and list items stay flush.
37
37
  page &&
38
- "[&_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", print !== "none" &&
38
+ "[&_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",
39
+ // Preflight strips paragraph and list margins; a mail body in a form field needs them back.
40
+ mailSpacing &&
41
+ "[&_p]:my-3 [&_ul]:my-3 [&_ol]:my-3 [&_li>p]:my-0 [&_.ProseMirror>:first-child]:mt-0 [&_.ProseMirror>:last-child]:mb-0", print !== "none" &&
39
42
  "[&_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", "[&_[data-borders=none]_td]:border-transparent [&_[data-borders=none]_th]:border-transparent", "[&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-6 [&_ol]:pl-6", headingClasses(canvas, page), "[&_a]:underline [&_a]:text-primary", "[&_strong]:font-bold [&_em]:italic [&_u]:underline", tableClasses(canvas, page),
40
43
  // A layout region has no content below its table; margins there only inflate the region box.
41
44
  hosted && "[&_td>div]:my-0 [&_.ProseMirror>.tableWrapper:last-child_table]:mb-0", "[&_table]:w-full [&_table]:border-collapse", "[&_td>p]:m-0 [&_th>p]:m-0 [&_th]:text-left", cellClasses(canvas, print), "[&_tr[data-each]>td]:bg-muted/50", "[&_[data-align=left]]:text-left [&_[data-align=center]]:text-center [&_[data-align=right]]:text-right [&_[data-align=justify]]:text-justify", "[&_p[data-size=small]]:text-xs [&_p[data-size=small]]:text-muted-foreground", "[&_a[data-button]]:inline-block [&_a[data-button]]:rounded-full [&_a[data-button]]:bg-primary [&_a[data-button]]:px-4 [&_a[data-button]]:py-1.5 [&_a[data-button]]:text-primary-foreground [&_a[data-button]]:no-underline",
@@ -1,3 +1,3 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type DocumentEditorProps } from "./document-toolbar-blocks.ts";
3
- export default function DocumentTiptapEditor({ id, value, onChange, variables, readOnly, blocks: configuredBlocks, imageVariables, variableLabels, systemVariables, resourcePreviews, chrome, layoutValues, toolbar, renderPaper, toolbarHost, onEditorReady, onFrameControlChange, }: DocumentEditorProps): ReactNode;
3
+ export default function DocumentTiptapEditor({ id, value, onChange, variables, readOnly, blocks: configuredBlocks, imageVariables, variableLabels, systemVariables, resourcePreviews, chrome, layoutValues, toolbar, renderPaper, toolbarHost, onEditorReady, onFrameControlChange, formatting, }: DocumentEditorProps): ReactNode;
@@ -14,7 +14,7 @@ import { renderHostedEditor, renderInlineEditor } from "./document-tiptap-layout
14
14
  import { MAIL_DOCUMENT_BLOCKS, } from "./document-toolbar-blocks.js";
15
15
  import { useDocumentTiptapModel } from "./use-document-tiptap-model.js";
16
16
  const NO_LAYOUT_VALUES = {};
17
- export default function DocumentTiptapEditor({ id, value, onChange, variables, readOnly, blocks: configuredBlocks = MAIL_DOCUMENT_BLOCKS, imageVariables = NO_NAMES, variableLabels = NO_LABELS, systemVariables = NO_NAMES, resourcePreviews = NO_PREVIEWS, chrome = "default", layoutValues = NO_LAYOUT_VALUES, toolbar = "full", renderPaper, toolbarHost, onEditorReady, onFrameControlChange, }) {
17
+ export default function DocumentTiptapEditor({ id, value, onChange, variables, readOnly, blocks: configuredBlocks = MAIL_DOCUMENT_BLOCKS, imageVariables = NO_NAMES, variableLabels = NO_LABELS, systemVariables = NO_NAMES, resourcePreviews = NO_PREVIEWS, chrome = "default", layoutValues = NO_LAYOUT_VALUES, toolbar = "full", renderPaper, toolbarHost, onEditorReady, onFrameControlChange, formatting, }) {
18
18
  const t = useTranslation();
19
19
  const locale = useLocale().locale();
20
20
  const { ActionOverflowMenu, Button, Field, Input } = usePrimitives();
@@ -89,7 +89,7 @@ export default function DocumentTiptapEditor({ id, value, onChange, variables, r
89
89
  variableLabels,
90
90
  stableLabels: model.stableLabels,
91
91
  });
92
- const editorContent = renderEditorContent(editor, canvas, hosted, print);
92
+ const editorContent = renderEditorContent(editor, canvas, hosted, print, formatting === "text");
93
93
  if (hosted)
94
94
  return renderHostedEditor(context, toolbarHost, editorContent);
95
95
  return renderInlineEditor(context, canvas && renderPaper !== undefined ? renderPaper(editorContent) : editorContent);