@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.
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/shared/tenant-scoped-subject.d.ts +11 -0
- package/dist/shared/tenant-scoped-subject.js +18 -0
- package/dist/signature/feature.js +1 -1
- package/dist/signature/grant.d.ts +1 -1
- package/dist/signature/grant.js +7 -12
- package/dist/signature/png.js +35 -10
- package/dist/template-resolver/api.d.ts +2 -0
- package/dist/template-resolver/api.js +11 -7
- package/dist/template-resolver/compile-document-body.js +6 -5
- package/dist/template-resolver/compile-document-styles.js +42 -4
- package/dist/template-resolver/document-frames.d.ts +1 -0
- package/dist/template-resolver/document-frames.js +39 -2
- package/dist/template-resolver/document-op-blocks.d.ts +258 -24
- package/dist/template-resolver/document-op-blocks.js +111 -20
- package/dist/template-resolver/document-ops.d.ts +1030 -96
- package/dist/template-resolver/document-ops.js +32 -3
- package/dist/template-resolver/document-print-only.d.ts +2 -1
- package/dist/template-resolver/document-print-only.js +23 -0
- package/dist/template-resolver/document-sanitizer.d.ts +1 -1
- package/dist/template-resolver/document-sanitizer.js +6 -1
- package/dist/template-resolver/handlers/create-layout.write.js +1 -1
- package/dist/template-resolver/handlers/patch-draft.write.d.ts +512 -48
- package/dist/template-resolver/handlers/patch-draft.write.js +2 -1
- package/dist/template-resolver/handlers/tenant-settings.d.ts +7 -1
- package/dist/template-resolver/handlers/tenant-settings.js +25 -15
- package/dist/template-resolver/index.d.ts +3 -3
- package/dist/template-resolver/index.js +3 -3
- package/dist/template-resolver/template-meta.d.ts +10 -0
- package/dist/template-resolver/template-meta.js +7 -1
- package/dist/template-resolver/template-preview.js +16 -4
- package/dist/template-resolver/web/constants.d.ts +1 -1
- package/dist/template-resolver/web/constants.js +1 -1
- package/dist/template-resolver/web/document-editor-extensions.js +44 -19
- package/dist/template-resolver/web/document-editor.js +3 -1
- package/dist/template-resolver/web/document-print-decorations.js +53 -6
- package/dist/template-resolver/web/document-print-style.d.ts +81 -2
- package/dist/template-resolver/web/document-print-style.js +114 -2
- package/dist/template-resolver/web/document-repeat-strip.js +2 -26
- package/dist/template-resolver/web/document-schema.d.ts +5 -0
- package/dist/template-resolver/web/document-schema.js +50 -13
- package/dist/template-resolver/web/document-style-css.d.ts +35 -2
- package/dist/template-resolver/web/document-style-css.js +65 -1
- package/dist/template-resolver/web/document-tiptap-bubble.js +71 -8
- package/dist/template-resolver/web/document-tiptap-content.d.ts +1 -1
- package/dist/template-resolver/web/document-tiptap-content.js +5 -2
- package/dist/template-resolver/web/document-tiptap-editor.d.ts +1 -1
- package/dist/template-resolver/web/document-tiptap-editor.js +2 -2
- package/dist/template-resolver/web/document-tiptap-helpers.d.ts +32 -2
- package/dist/template-resolver/web/document-tiptap-helpers.js +99 -24
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.d.ts +11 -0
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.js +41 -3
- package/dist/template-resolver/web/document-tiptap-toolbar.js +13 -8
- package/dist/template-resolver/web/i18n.js +2 -0
- package/dist/template-resolver/web/index.d.ts +1 -1
- package/dist/template-resolver/web/index.js +1 -1
- package/dist/template-resolver/web/pdf-constants.d.ts +5 -0
- package/dist/template-resolver/web/pdf-constants.js +6 -0
- package/dist/template-resolver/web/placeholder-text.d.ts +2 -1
- package/dist/template-resolver/web/placeholder-text.js +5 -2
- package/package.json +19 -11
- package/src/signature/changes.json +6 -0
- package/src/template-resolver/changes.json +24 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import { documentBlocksForKind, PDF_LAYOUT_DOCUMENT_BLOCKS, } from "./web/document-blocks.js";
|
|
3
3
|
import { DOCUMENT_FONTS } from "./web/document-fonts.js";
|
|
4
|
-
import { COLWIDTH_PX_RANGE, FRAME_MM_RANGE, FRAME_PRESETS, LINE_HEIGHT_RANGE, PARAGRAPH_SPACE_PT_RANGE, TEXT_SIZE_PT_RANGE, } from "./web/document-print-style.js";
|
|
5
|
-
import { DOCUMENT_TEXT_ALIGNMENTS, isDocumentPlaceholderHref, isDocumentReferenceName, isDocumentResourceKey, } from "./web/document-schema.js";
|
|
4
|
+
import { CELL_PADDING_MM_RANGE, COLWIDTH_PX_RANGE, DIVIDER_WEIGHT_PT_RANGE, DOCUMENT_IMAGE_ALIGNMENTS, DOCUMENT_TABLE_ALIGNMENTS, FRAME_MM_RANGE, FRAME_PRESETS, IMAGE_WIDTH_MM_RANGE, LINE_HEIGHT_RANGE, PARAGRAPH_SPACE_PT_RANGE, TABLE_WIDTH_MM_RANGE, TEXT_SIZE_PT_RANGE, } from "./web/document-print-style.js";
|
|
5
|
+
import { DOCUMENT_DATE_STYLES, DOCUMENT_TEXT_ALIGNMENTS, isDocumentPlaceholderHref, isDocumentReferenceName, isDocumentResourceKey, } from "./web/document-schema.js";
|
|
6
6
|
import { HEX_COLOR_PATTERN } from "./web/mail-layout-constants.js";
|
|
7
7
|
import { lineToContent, singleLine } from "./web/placeholder-text.js";
|
|
8
8
|
export const MAX_BODY_BLOCKS = 300;
|
|
@@ -63,8 +63,14 @@ const runSchema = textStyleSchema.extend({
|
|
|
63
63
|
bold: z.boolean().optional(),
|
|
64
64
|
italic: z.boolean().optional(),
|
|
65
65
|
underline: z.boolean().optional(),
|
|
66
|
+
dateStyle: z.enum(DOCUMENT_DATE_STYLES).optional(),
|
|
66
67
|
});
|
|
67
|
-
|
|
68
|
+
// A line break inside a paragraph or table cell; the lines around it keep their own formatting.
|
|
69
|
+
const hardBreakSchema = z.object({ hardBreak: z.literal(true) });
|
|
70
|
+
const runsSchema = z
|
|
71
|
+
.array(z.union([runSchema, hardBreakSchema]))
|
|
72
|
+
.min(1)
|
|
73
|
+
.max(50);
|
|
68
74
|
const blockStyleSchema = z.object({
|
|
69
75
|
lineHeight: rangeNumber(LINE_HEIGHT_RANGE).optional(),
|
|
70
76
|
spaceBeforePt: rangeNumber(PARAGRAPH_SPACE_PT_RANGE).optional(),
|
|
@@ -82,7 +88,16 @@ const cellSchema = z.object({
|
|
|
82
88
|
background: hexColor.optional(),
|
|
83
89
|
align: alignSchema.optional(),
|
|
84
90
|
});
|
|
85
|
-
|
|
91
|
+
// A rule over or under a row, e.g. the dark line under a table header or above a total.
|
|
92
|
+
const rowLineSchema = z.object({
|
|
93
|
+
color: hexColor,
|
|
94
|
+
weightPt: rangeNumber(DIVIDER_WEIGHT_PT_RANGE),
|
|
95
|
+
});
|
|
96
|
+
const rowSchema = z.object({
|
|
97
|
+
cells: z.array(cellSchema).min(1).max(20),
|
|
98
|
+
lineAbove: rowLineSchema.optional(),
|
|
99
|
+
lineBelow: rowLineSchema.optional(),
|
|
100
|
+
});
|
|
86
101
|
const paragraphSchema = z.object({
|
|
87
102
|
type: z.literal("paragraph"),
|
|
88
103
|
...inlineShape,
|
|
@@ -106,15 +121,27 @@ const listSchema = z.object({
|
|
|
106
121
|
const tableSchema = z.object({
|
|
107
122
|
type: z.literal("table"),
|
|
108
123
|
borders: z.literal("none").optional(),
|
|
124
|
+
cellPaddingMm: rangeNumber(CELL_PADDING_MM_RANGE).optional(),
|
|
125
|
+
widthMm: rangeNumber(TABLE_WIDTH_MM_RANGE).optional(),
|
|
126
|
+
align: z.enum(DOCUMENT_TABLE_ALIGNMENTS).optional(),
|
|
109
127
|
columnWidthsPx: z.array(rangeNumber(COLWIDTH_PX_RANGE)).min(1).max(20).optional(),
|
|
110
128
|
header: rowSchema.optional(),
|
|
111
129
|
rows: z.array(rowSchema).max(100),
|
|
112
130
|
repeat: z.object({ each: z.string().min(1).max(100), row: rowSchema }).optional(),
|
|
131
|
+
rowsAfterRepeat: z.array(rowSchema).max(100).optional(),
|
|
113
132
|
});
|
|
114
133
|
const imageSchema = z.object({
|
|
115
134
|
type: z.literal("image"),
|
|
116
135
|
resource: z.string().min(1).max(200),
|
|
117
136
|
alt: z.string().max(500).optional(),
|
|
137
|
+
widthMm: rangeNumber(IMAGE_WIDTH_MM_RANGE).optional(),
|
|
138
|
+
align: z.enum(DOCUMENT_IMAGE_ALIGNMENTS).optional(),
|
|
139
|
+
bleed: z.boolean().optional(),
|
|
140
|
+
});
|
|
141
|
+
const dividerSchema = z.object({
|
|
142
|
+
type: z.literal("divider"),
|
|
143
|
+
color: hexColor.optional(),
|
|
144
|
+
weightPt: rangeNumber(DIVIDER_WEIGHT_PT_RANGE).optional(),
|
|
118
145
|
});
|
|
119
146
|
const frameSchema = z.object({
|
|
120
147
|
type: z.literal("frame"),
|
|
@@ -143,7 +170,7 @@ export const blockInputSchema = z.discriminatedUnion("type", [
|
|
|
143
170
|
frameSchema,
|
|
144
171
|
imageSchema,
|
|
145
172
|
z.object({ type: z.literal("button"), text: singleLineText, href: z.string().max(300) }),
|
|
146
|
-
|
|
173
|
+
dividerSchema,
|
|
147
174
|
z.object({ type: z.literal("pageBreak") }),
|
|
148
175
|
]);
|
|
149
176
|
export const blockFormatSchema = z.object(textFormatShape);
|
|
@@ -195,10 +222,12 @@ function inlineNodes(ctx, path, source, blockStyle) {
|
|
|
195
222
|
if (runs === undefined) {
|
|
196
223
|
return withMarks(lineToContent(singleLine(text ?? "")), textStyleMarks(base));
|
|
197
224
|
}
|
|
198
|
-
return runs.flatMap((run) =>
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
return runs.flatMap((run) => "hardBreak" in run
|
|
226
|
+
? [{ type: "hardBreak" }]
|
|
227
|
+
: withMarks(lineToContent(singleLine(run.text), run.dateStyle), [
|
|
228
|
+
...runMarks(run),
|
|
229
|
+
...textStyleMarks({ ...base, ...definedStyle(run) }),
|
|
230
|
+
]));
|
|
202
231
|
}
|
|
203
232
|
function formatAttributes(ctx, path, format) {
|
|
204
233
|
if (format.align !== undefined && !allowedBlocksFor(ctx.kind).includes("align")) {
|
|
@@ -241,9 +270,14 @@ function rowNode(ctx, path, row, options) {
|
|
|
241
270
|
problem: "columnWidthsPx must match the cells per row",
|
|
242
271
|
});
|
|
243
272
|
}
|
|
273
|
+
const attrs = {
|
|
274
|
+
...options.attrs,
|
|
275
|
+
...(row.lineAbove === undefined ? {} : { lineAbove: row.lineAbove }),
|
|
276
|
+
...(row.lineBelow === undefined ? {} : { lineBelow: row.lineBelow }),
|
|
277
|
+
};
|
|
244
278
|
return {
|
|
245
279
|
type: "tableRow",
|
|
246
|
-
...(
|
|
280
|
+
...(Object.keys(attrs).length === 0 ? {} : { attrs }),
|
|
247
281
|
content: row.cells.map((cell, index) => {
|
|
248
282
|
const width = options.widths?.[index];
|
|
249
283
|
const attrs = {
|
|
@@ -259,17 +293,33 @@ function rowNode(ctx, path, row, options) {
|
|
|
259
293
|
}),
|
|
260
294
|
};
|
|
261
295
|
}
|
|
296
|
+
function reportInvalidRepeat(ctx, path, repeat) {
|
|
297
|
+
if (repeat === undefined)
|
|
298
|
+
return;
|
|
299
|
+
if (!isDocumentReferenceName(repeat.each)) {
|
|
300
|
+
report(ctx, `${path}.repeat.each`, "invalid_repeat_variable", { each: repeat.each });
|
|
301
|
+
}
|
|
302
|
+
if (!allowedBlocksFor(ctx.kind).includes("repeat")) {
|
|
303
|
+
report(ctx, `${path}.repeat`, "block_not_allowed", { type: "repeat", kind: ctx.kind });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function tableAttrsOf(block) {
|
|
307
|
+
return {
|
|
308
|
+
...(block.borders === undefined ? {} : { borders: block.borders }),
|
|
309
|
+
...(block.cellPaddingMm === undefined ? {} : { cellPaddingMm: block.cellPaddingMm }),
|
|
310
|
+
...(block.widthMm === undefined ? {} : { widthMm: block.widthMm }),
|
|
311
|
+
...(block.align === undefined ? {} : { align: block.align }),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
262
314
|
function tableNode(ctx, path, block) {
|
|
263
315
|
const widths = block.columnWidthsPx;
|
|
264
|
-
const { header, repeat } = block;
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
if (!allowedBlocksFor(ctx.kind).includes("repeat")) {
|
|
270
|
-
report(ctx, `${path}.repeat`, "block_not_allowed", { type: "repeat", kind: ctx.kind });
|
|
271
|
-
}
|
|
316
|
+
const { header, repeat, rowsAfterRepeat } = block;
|
|
317
|
+
if (rowsAfterRepeat !== undefined && repeat === undefined) {
|
|
318
|
+
report(ctx, `${path}.rowsAfterRepeat`, "invalid_table", {
|
|
319
|
+
problem: "rowsAfterRepeat needs a repeat row to follow",
|
|
320
|
+
});
|
|
272
321
|
}
|
|
322
|
+
reportInvalidRepeat(ctx, path, repeat);
|
|
273
323
|
const rows = [
|
|
274
324
|
...(header === undefined
|
|
275
325
|
? []
|
|
@@ -290,6 +340,7 @@ function tableNode(ctx, path, block) {
|
|
|
290
340
|
attrs: { each: repeat.each },
|
|
291
341
|
}),
|
|
292
342
|
]),
|
|
343
|
+
...(rowsAfterRepeat ?? []).map((row, index) => rowNode(ctx, `${path}.rowsAfterRepeat.${index}`, row, { header: false, widths })),
|
|
293
344
|
];
|
|
294
345
|
const cellCounts = new Set(rows.map((row) => row.content?.length ?? 0));
|
|
295
346
|
if (rows.length === 0 || cellCounts.size > 1) {
|
|
@@ -297,9 +348,10 @@ function tableNode(ctx, path, block) {
|
|
|
297
348
|
problem: "needs a row and the same number of cells in every row",
|
|
298
349
|
});
|
|
299
350
|
}
|
|
351
|
+
const tableAttrs = tableAttrsOf(block);
|
|
300
352
|
return {
|
|
301
353
|
type: "table",
|
|
302
|
-
...(
|
|
354
|
+
...(Object.keys(tableAttrs).length === 0 ? {} : { attrs: tableAttrs }),
|
|
303
355
|
content: rows,
|
|
304
356
|
};
|
|
305
357
|
}
|
|
@@ -317,11 +369,34 @@ function frameNode(ctx, path, input) {
|
|
|
317
369
|
content: input.blocks.map((inner, index) => blockNode(ctx, `${path}.blocks.${index}`, inner)),
|
|
318
370
|
};
|
|
319
371
|
}
|
|
372
|
+
// Only the header and footer print outside the page margins, so only they can reach the paper edge.
|
|
373
|
+
function isBleedRegion(region) {
|
|
374
|
+
return region === "header" || region === "footer";
|
|
375
|
+
}
|
|
376
|
+
function dividerNode(input) {
|
|
377
|
+
const attrs = {
|
|
378
|
+
...(input.color === undefined ? {} : { color: input.color }),
|
|
379
|
+
...(input.weightPt === undefined ? {} : { weightPt: input.weightPt }),
|
|
380
|
+
};
|
|
381
|
+
return { type: "divider", ...(Object.keys(attrs).length === 0 ? {} : { attrs }) };
|
|
382
|
+
}
|
|
320
383
|
function imageNode(ctx, path, input) {
|
|
321
384
|
if (!isDocumentResourceKey(input.resource)) {
|
|
322
385
|
report(ctx, `${path}.resource`, "invalid_resource_key", { resource: input.resource });
|
|
323
386
|
}
|
|
324
|
-
|
|
387
|
+
if (input.bleed === true && !(ctx.kind === "pdf-layout" && isBleedRegion(ctx.region))) {
|
|
388
|
+
report(ctx, `${path}.bleed`, "bleed_not_allowed", { kind: ctx.kind });
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
type: "resource",
|
|
392
|
+
attrs: {
|
|
393
|
+
resource: input.resource,
|
|
394
|
+
alt: input.alt ?? null,
|
|
395
|
+
...(input.widthMm === undefined ? {} : { widthMm: input.widthMm }),
|
|
396
|
+
...(input.align === undefined ? {} : { align: input.align }),
|
|
397
|
+
...(input.bleed === true ? { bleed: true } : {}),
|
|
398
|
+
},
|
|
399
|
+
};
|
|
325
400
|
}
|
|
326
401
|
function buttonNode(ctx, path, input) {
|
|
327
402
|
if (!isDocumentPlaceholderHref(input.href)) {
|
|
@@ -353,6 +428,7 @@ export function blockNode(ctx, path, input) {
|
|
|
353
428
|
case "button":
|
|
354
429
|
return buttonNode(ctx, path, input);
|
|
355
430
|
case "divider":
|
|
431
|
+
return dividerNode(input);
|
|
356
432
|
case "pageBreak":
|
|
357
433
|
return { type: input.type };
|
|
358
434
|
}
|
|
@@ -364,16 +440,31 @@ const PRINT_ATTRIBUTES = [
|
|
|
364
440
|
"background",
|
|
365
441
|
"colwidth",
|
|
366
442
|
"borders",
|
|
443
|
+
"cellPaddingMm",
|
|
444
|
+
"lineAbove",
|
|
445
|
+
"lineBelow",
|
|
367
446
|
];
|
|
368
447
|
function isPresent(value) {
|
|
369
448
|
return value !== undefined && value !== null;
|
|
370
449
|
}
|
|
450
|
+
// An image's bleed defaults to false, so a present attribute alone says nothing there.
|
|
451
|
+
function hasPrintOnlyBoxAttributes(node) {
|
|
452
|
+
const attrs = node.attrs;
|
|
453
|
+
if (node.type === "resource") {
|
|
454
|
+
return (attrs?.["bleed"] === true || isPresent(attrs?.["widthMm"]) || isPresent(attrs?.["align"]));
|
|
455
|
+
}
|
|
456
|
+
if (node.type === "table")
|
|
457
|
+
return isPresent(attrs?.["widthMm"]) || isPresent(attrs?.["align"]);
|
|
458
|
+
return node.type === "divider" && (isPresent(attrs?.["color"]) || isPresent(attrs?.["weightPt"]));
|
|
459
|
+
}
|
|
371
460
|
// Frames are refused as blocks, so only the styling that would ride along in other blocks counts here.
|
|
372
461
|
export function usesPrintStyling(node) {
|
|
373
462
|
if (node.marks?.some((mark) => mark.type === "documentTextStyle"))
|
|
374
463
|
return true;
|
|
375
464
|
if (PRINT_ATTRIBUTES.some((name) => isPresent(node.attrs?.[name])))
|
|
376
465
|
return true;
|
|
466
|
+
if (hasPrintOnlyBoxAttributes(node))
|
|
467
|
+
return true;
|
|
377
468
|
return (node.content ?? []).some(usesPrintStyling);
|
|
378
469
|
}
|
|
379
470
|
// Only a PDF applies print styling; a mail would keep it through the rebuild and the sanitizer refuses it on write.
|