@cosmicdrift/kumiko-bundled-features 0.417.0 → 0.419.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-tools/api-docs/schema-fields.js +9 -0
- package/dist/auth-email-password/index.d.ts +2 -1
- package/dist/auth-email-password/index.js +2 -1
- package/dist/auth-email-password/signup-activation.js +2 -1
- package/dist/auth-email-password/signup-token-store.d.ts +1 -6
- package/dist/auth-email-password/signup-token-store.js +0 -5
- package/dist/cap-counter/stock-cap-guard.d.ts +9 -2
- package/dist/cap-counter/stock-cap-guard.js +9 -11
- package/dist/document-ingest-foundation/feature.js +5 -1
- package/dist/document-ingest-foundation/report-ingest-progress.js +19 -6
- package/dist/signature/entity.d.ts +8 -6
- package/dist/signature/entity.js +3 -1
- package/dist/signature/feature.js +11 -4
- package/dist/signature/handlers/lifecycle.write.d.ts +9 -0
- package/dist/signature/handlers/lifecycle.write.js +23 -1
- package/dist/signature/handlers/request.write.d.ts +1 -1
- package/dist/signature/i18n.js +1 -0
- package/dist/signature/list-cursor-seal.d.ts +3 -0
- package/dist/signature/list-cursor-seal.js +44 -0
- package/dist/signature/options.d.ts +2 -2
- package/dist/signature/payloads.d.ts +17 -1
- package/dist/signature/payloads.js +11 -2
- package/dist/signature/png.js +23 -3
- package/dist/signature/subject-queries.d.ts +1 -1
- package/dist/signature/subject-queries.js +30 -8
- package/dist/signature/sweep.js +26 -9
- package/dist/signature/web/constants.d.ts +9 -0
- package/dist/signature/web/constants.js +8 -0
- package/dist/subscription-stripe/plugin-methods.js +2 -0
- package/dist/subscription-stripe/verify-webhook.js +17 -16
- package/dist/template-resolver/compile-document-body.js +3 -6
- package/dist/template-resolver/compile-document-styles.d.ts +3 -0
- package/dist/template-resolver/compile-document-styles.js +84 -0
- package/dist/template-resolver/document-frames.d.ts +3 -0
- package/dist/template-resolver/document-frames.js +19 -0
- package/dist/template-resolver/document-op-blocks.d.ts +495 -0
- package/dist/template-resolver/document-op-blocks.js +430 -0
- package/dist/template-resolver/document-ops.d.ts +1809 -37
- package/dist/template-resolver/document-ops.js +97 -104
- package/dist/template-resolver/document-print-only.d.ts +10 -0
- package/dist/template-resolver/document-print-only.js +24 -0
- package/dist/template-resolver/document-sanitizer.d.ts +1 -1
- package/dist/template-resolver/document-sanitizer.js +24 -13
- package/dist/template-resolver/feature.d.ts +3 -0
- package/dist/template-resolver/feature.js +14 -1
- package/dist/template-resolver/handlers/apply-layout.write.d.ts +29 -0
- package/dist/template-resolver/handlers/apply-layout.write.js +118 -0
- package/dist/template-resolver/handlers/create-layout.write.d.ts +15 -0
- package/dist/template-resolver/handlers/create-layout.write.js +78 -0
- package/dist/template-resolver/handlers/document-base.d.ts +2 -2
- package/dist/template-resolver/handlers/document-blocks.query.d.ts +10 -3
- package/dist/template-resolver/handlers/document-blocks.query.js +13 -8
- package/dist/template-resolver/handlers/document-region.d.ts +19 -0
- package/dist/template-resolver/handlers/document-region.js +27 -0
- package/dist/template-resolver/handlers/failure-reason.d.ts +2 -0
- package/dist/template-resolver/handlers/failure-reason.js +12 -0
- package/dist/template-resolver/handlers/import-bundle-system.write.js +4 -0
- package/dist/template-resolver/handlers/layout-source.query.d.ts +3 -3
- package/dist/template-resolver/handlers/layout-source.query.js +6 -2
- package/dist/template-resolver/handlers/overview.query.d.ts +8 -0
- package/dist/template-resolver/handlers/overview.query.js +12 -6
- package/dist/template-resolver/handlers/patch-draft.write.d.ts +905 -4
- package/dist/template-resolver/handlers/patch-draft.write.js +10 -6
- package/dist/template-resolver/handlers/publish-templates.write.d.ts +40 -0
- package/dist/template-resolver/handlers/publish-templates.write.js +61 -0
- package/dist/template-resolver/handlers/set.write.js +4 -1
- package/dist/template-resolver/handlers/template-write.js +7 -2
- package/dist/template-resolver/handlers/tenant-settings.d.ts +17 -0
- package/dist/template-resolver/handlers/tenant-settings.js +91 -0
- package/dist/template-resolver/handlers/toggle-status.write.d.ts +14 -9
- package/dist/template-resolver/handlers/toggle-status.write.js +11 -7
- package/dist/template-resolver/handlers/upsert-system.write.js +15 -9
- package/dist/template-resolver/handlers/usage.query.d.ts +14 -0
- package/dist/template-resolver/handlers/usage.query.js +80 -12
- package/dist/template-resolver/handlers/validate.query.d.ts +2 -0
- package/dist/template-resolver/handlers/validate.query.js +10 -0
- package/dist/template-resolver/i18n.js +3 -0
- package/dist/template-resolver/index.d.ts +7 -2
- package/dist/template-resolver/index.js +6 -2
- package/dist/template-resolver/layout-regions.d.ts +4 -5
- package/dist/template-resolver/layout-regions.js +38 -11
- package/dist/template-resolver/print-document.js +3 -1
- package/dist/template-resolver/seeding.js +4 -0
- package/dist/template-resolver/template-delivery-policy.d.ts +1 -0
- package/dist/template-resolver/template-delivery-policy.js +9 -1
- package/dist/template-resolver/template-edit-policy.d.ts +5 -1
- package/dist/template-resolver/template-edit-policy.js +29 -1
- package/dist/template-resolver/template-meta.d.ts +27 -2
- package/dist/template-resolver/template-meta.js +21 -5
- package/dist/template-resolver/template-preview.js +8 -8
- package/dist/template-resolver/template-validation.js +10 -3
- package/dist/template-resolver/web/constants.d.ts +7 -1
- package/dist/template-resolver/web/constants.js +21 -1
- package/dist/template-resolver/web/document-blocks.d.ts +1 -0
- package/dist/template-resolver/web/document-blocks.js +2 -0
- package/dist/template-resolver/web/document-editor-extensions.d.ts +9 -1
- package/dist/template-resolver/web/document-editor-extensions.js +27 -2
- package/dist/template-resolver/web/document-editor-fonts.d.ts +10 -0
- package/dist/template-resolver/web/document-editor-fonts.js +13 -0
- package/dist/template-resolver/web/document-fonts.d.ts +4 -0
- package/dist/template-resolver/web/document-fonts.js +18 -0
- package/dist/template-resolver/web/document-frame-control.d.ts +61 -0
- package/dist/template-resolver/web/document-frame-control.js +329 -0
- package/dist/template-resolver/web/document-frame-node-view.d.ts +4 -0
- package/dist/template-resolver/web/document-frame-node-view.js +173 -0
- package/dist/template-resolver/web/document-print-decorations.d.ts +12 -0
- package/dist/template-resolver/web/document-print-decorations.js +147 -0
- package/dist/template-resolver/web/document-print-defaults.d.ts +14 -0
- package/dist/template-resolver/web/document-print-defaults.js +25 -0
- package/dist/template-resolver/web/document-print-style.d.ts +71 -0
- package/dist/template-resolver/web/document-print-style.js +199 -0
- package/dist/template-resolver/web/document-repeat-strip.d.ts +8 -0
- package/dist/template-resolver/web/document-repeat-strip.js +78 -0
- package/dist/template-resolver/web/document-schema.js +23 -9
- package/dist/template-resolver/web/document-style-css.d.ts +29 -0
- package/dist/template-resolver/web/document-style-css.js +76 -0
- package/dist/template-resolver/web/document-tiptap-bubble.js +13 -3
- package/dist/template-resolver/web/document-tiptap-content.d.ts +2 -1
- package/dist/template-resolver/web/document-tiptap-content.js +36 -4
- package/dist/template-resolver/web/document-tiptap-context.d.ts +6 -2
- package/dist/template-resolver/web/document-tiptap-context.js +2 -1
- package/dist/template-resolver/web/document-tiptap-editor.d.ts +1 -1
- package/dist/template-resolver/web/document-tiptap-editor.js +13 -5
- package/dist/template-resolver/web/document-tiptap-helpers.d.ts +30 -1
- package/dist/template-resolver/web/document-tiptap-helpers.js +103 -2
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.d.ts +5 -0
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.js +89 -6
- package/dist/template-resolver/web/document-tiptap-toolbar.js +45 -8
- package/dist/template-resolver/web/document-toolbar-blocks.d.ts +17 -0
- package/dist/template-resolver/web/i18n.js +19 -0
- package/dist/template-resolver/web/index.d.ts +8 -2
- package/dist/template-resolver/web/index.js +6 -1
- package/dist/template-resolver/web/pdf-constants.d.ts +3 -0
- package/dist/template-resolver/web/pdf-constants.js +3 -0
- package/dist/template-resolver/web/qualified-names.d.ts +7 -0
- package/dist/template-resolver/web/qualified-names.js +6 -0
- package/dist/template-resolver/web/use-document-tiptap-model.d.ts +6 -2
- package/dist/template-resolver/web/use-document-tiptap-model.js +38 -3
- package/dist/tenant/company-config.d.ts +6 -0
- package/dist/tenant/company-config.js +41 -0
- package/dist/tenant/feature.js +11 -0
- package/dist/tenant/i18n.js +14 -0
- package/dist/tenant-inactivity/handlers/keep-account.write.js +5 -2
- package/dist/tenant-lifecycle/run-tenant-destroy.js +65 -33
- package/package.json +16 -11
- package/src/agent-tools/changes.json +6 -0
- package/src/cap-counter/changes.json +6 -0
- package/src/channel-whatsapp/changes.json +1 -1
- package/src/document-ingest-foundation/changes.json +6 -0
- package/src/signature/changes.json +18 -0
- package/src/subscription-paddle/changes.json +1 -1
- package/src/subscription-stripe/changes.json +6 -0
- package/src/template-resolver/changes.json +38 -0
- package/src/tenant-lifecycle/changes.json +6 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { documentBlocksForKind, PDF_LAYOUT_DOCUMENT_BLOCKS, } from "./web/document-blocks.js";
|
|
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";
|
|
6
|
+
import { HEX_COLOR_PATTERN } from "./web/mail-layout-constants.js";
|
|
7
|
+
import { lineToContent, singleLine } from "./web/placeholder-text.js";
|
|
8
|
+
export const MAX_BODY_BLOCKS = 300;
|
|
9
|
+
export const DOCUMENT_BLOCK_INPUT_TYPES = [
|
|
10
|
+
"paragraph",
|
|
11
|
+
"heading",
|
|
12
|
+
"list",
|
|
13
|
+
"table",
|
|
14
|
+
"frame",
|
|
15
|
+
"image",
|
|
16
|
+
"button",
|
|
17
|
+
"divider",
|
|
18
|
+
"pageBreak",
|
|
19
|
+
];
|
|
20
|
+
// Text blocks and lists exist in every kind; every other input type needs its block in the kind's set.
|
|
21
|
+
const REQUIRED_BLOCK = {
|
|
22
|
+
paragraph: null,
|
|
23
|
+
heading: null,
|
|
24
|
+
list: null,
|
|
25
|
+
table: "table",
|
|
26
|
+
frame: "frame",
|
|
27
|
+
image: "image",
|
|
28
|
+
button: "button",
|
|
29
|
+
divider: "divider",
|
|
30
|
+
pageBreak: "pageBreak",
|
|
31
|
+
};
|
|
32
|
+
// A frame sits on the page of a PDF body; layout regions and mails have none.
|
|
33
|
+
export function allowedBlocksFor(kind) {
|
|
34
|
+
if (kind === "pdf-layout")
|
|
35
|
+
return PDF_LAYOUT_DOCUMENT_BLOCKS;
|
|
36
|
+
const blocks = documentBlocksForKind(kind);
|
|
37
|
+
return kind === "document-pdf" ? [...blocks, "frame"] : blocks;
|
|
38
|
+
}
|
|
39
|
+
function isBlockTypeAllowed(type, kind) {
|
|
40
|
+
const required = REQUIRED_BLOCK[type];
|
|
41
|
+
return required === null || allowedBlocksFor(kind).includes(required);
|
|
42
|
+
}
|
|
43
|
+
export function patchIssue(path, code, params) {
|
|
44
|
+
const camel = code.replace(/_([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
45
|
+
return {
|
|
46
|
+
path,
|
|
47
|
+
code,
|
|
48
|
+
i18nKey: `templateResolver.errors.patch.${camel}`,
|
|
49
|
+
...(params === undefined ? {} : { params }),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const singleLineText = z.string().max(2000);
|
|
53
|
+
const hexColor = z.string().regex(HEX_COLOR_PATTERN, "must be a #rrggbb color");
|
|
54
|
+
const rangeNumber = (range) => z.number().min(range.min).max(range.max);
|
|
55
|
+
const alignSchema = z.enum(DOCUMENT_TEXT_ALIGNMENTS);
|
|
56
|
+
const textStyleSchema = z.object({
|
|
57
|
+
font: z.enum(DOCUMENT_FONTS).optional(),
|
|
58
|
+
sizePt: rangeNumber(TEXT_SIZE_PT_RANGE).optional(),
|
|
59
|
+
color: hexColor.optional(),
|
|
60
|
+
});
|
|
61
|
+
const runSchema = textStyleSchema.extend({
|
|
62
|
+
text: singleLineText,
|
|
63
|
+
bold: z.boolean().optional(),
|
|
64
|
+
italic: z.boolean().optional(),
|
|
65
|
+
underline: z.boolean().optional(),
|
|
66
|
+
});
|
|
67
|
+
const runsSchema = z.array(runSchema).min(1).max(50);
|
|
68
|
+
const blockStyleSchema = z.object({
|
|
69
|
+
lineHeight: rangeNumber(LINE_HEIGHT_RANGE).optional(),
|
|
70
|
+
spaceBeforePt: rangeNumber(PARAGRAPH_SPACE_PT_RANGE).optional(),
|
|
71
|
+
spaceAfterPt: rangeNumber(PARAGRAPH_SPACE_PT_RANGE).optional(),
|
|
72
|
+
});
|
|
73
|
+
const textFormatShape = {
|
|
74
|
+
align: alignSchema.optional(),
|
|
75
|
+
style: blockStyleSchema.optional(),
|
|
76
|
+
textStyle: textStyleSchema.optional(),
|
|
77
|
+
};
|
|
78
|
+
// Either text or runs; the pair is checked when the node is built, because a refinement would hide the shape from a tool schema.
|
|
79
|
+
const inlineShape = { text: singleLineText.optional(), runs: runsSchema.optional() };
|
|
80
|
+
const cellSchema = z.object({
|
|
81
|
+
...inlineShape,
|
|
82
|
+
background: hexColor.optional(),
|
|
83
|
+
align: alignSchema.optional(),
|
|
84
|
+
});
|
|
85
|
+
const rowSchema = z.object({ cells: z.array(cellSchema).min(1).max(20) });
|
|
86
|
+
const paragraphSchema = z.object({
|
|
87
|
+
type: z.literal("paragraph"),
|
|
88
|
+
...inlineShape,
|
|
89
|
+
...textFormatShape,
|
|
90
|
+
});
|
|
91
|
+
const headingSchema = z.object({
|
|
92
|
+
type: z.literal("heading"),
|
|
93
|
+
level: z.number().int().min(1).max(3),
|
|
94
|
+
...inlineShape,
|
|
95
|
+
...textFormatShape,
|
|
96
|
+
});
|
|
97
|
+
const listSchema = z.object({
|
|
98
|
+
type: z.literal("list"),
|
|
99
|
+
ordered: z.boolean(),
|
|
100
|
+
items: z
|
|
101
|
+
.array(z.union([singleLineText, runsSchema]))
|
|
102
|
+
.min(1)
|
|
103
|
+
.max(100),
|
|
104
|
+
...textFormatShape,
|
|
105
|
+
});
|
|
106
|
+
const tableSchema = z.object({
|
|
107
|
+
type: z.literal("table"),
|
|
108
|
+
borders: z.literal("none").optional(),
|
|
109
|
+
columnWidthsPx: z.array(rangeNumber(COLWIDTH_PX_RANGE)).min(1).max(20).optional(),
|
|
110
|
+
header: rowSchema.optional(),
|
|
111
|
+
rows: z.array(rowSchema).max(100),
|
|
112
|
+
repeat: z.object({ each: z.string().min(1).max(100), row: rowSchema }).optional(),
|
|
113
|
+
});
|
|
114
|
+
const imageSchema = z.object({
|
|
115
|
+
type: z.literal("image"),
|
|
116
|
+
resource: z.string().min(1).max(200),
|
|
117
|
+
alt: z.string().max(500).optional(),
|
|
118
|
+
});
|
|
119
|
+
const frameSchema = z.object({
|
|
120
|
+
type: z.literal("frame"),
|
|
121
|
+
xMm: rangeNumber(FRAME_MM_RANGE),
|
|
122
|
+
yMm: rangeNumber(FRAME_MM_RANGE),
|
|
123
|
+
widthMm: rangeNumber(FRAME_MM_RANGE),
|
|
124
|
+
heightMm: rangeNumber(FRAME_MM_RANGE),
|
|
125
|
+
preset: z.enum(FRAME_PRESETS).optional(),
|
|
126
|
+
reserveFlow: z.boolean().optional(),
|
|
127
|
+
blocks: z
|
|
128
|
+
.array(z.discriminatedUnion("type", [
|
|
129
|
+
paragraphSchema,
|
|
130
|
+
headingSchema,
|
|
131
|
+
listSchema,
|
|
132
|
+
tableSchema,
|
|
133
|
+
imageSchema,
|
|
134
|
+
]))
|
|
135
|
+
.min(1)
|
|
136
|
+
.max(30),
|
|
137
|
+
});
|
|
138
|
+
export const blockInputSchema = z.discriminatedUnion("type", [
|
|
139
|
+
paragraphSchema,
|
|
140
|
+
headingSchema,
|
|
141
|
+
listSchema,
|
|
142
|
+
tableSchema,
|
|
143
|
+
frameSchema,
|
|
144
|
+
imageSchema,
|
|
145
|
+
z.object({ type: z.literal("button"), text: singleLineText, href: z.string().max(300) }),
|
|
146
|
+
z.object({ type: z.literal("divider") }),
|
|
147
|
+
z.object({ type: z.literal("pageBreak") }),
|
|
148
|
+
]);
|
|
149
|
+
export const blockFormatSchema = z.object(textFormatShape);
|
|
150
|
+
function report(ctx, path, code, params) {
|
|
151
|
+
ctx.issues.push(patchIssue(path, code, params));
|
|
152
|
+
}
|
|
153
|
+
export function countBlocks(blocks) {
|
|
154
|
+
return blocks.reduce((sum, block) => sum + 1 + (block.type === "frame" ? block.blocks.length : 0), 0);
|
|
155
|
+
}
|
|
156
|
+
function isTextStyleSet(style) {
|
|
157
|
+
return style.font !== undefined || style.sizePt !== undefined || style.color !== undefined;
|
|
158
|
+
}
|
|
159
|
+
function textStyleMarks(style) {
|
|
160
|
+
if (!isTextStyleSet(style))
|
|
161
|
+
return [];
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
type: "documentTextStyle",
|
|
165
|
+
attrs: { color: style.color ?? null, font: style.font ?? null, sizePt: style.sizePt ?? null },
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
function runMarks(run) {
|
|
170
|
+
return [
|
|
171
|
+
...(run.bold === true ? [{ type: "bold" }] : []),
|
|
172
|
+
...(run.italic === true ? [{ type: "italic" }] : []),
|
|
173
|
+
...(run.underline === true ? [{ type: "underline" }] : []),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
function withMarks(nodes, marks) {
|
|
177
|
+
return marks.length === 0
|
|
178
|
+
? nodes
|
|
179
|
+
: nodes.map((node) => ({ ...node, marks: [...(node.marks ?? []), ...marks] }));
|
|
180
|
+
}
|
|
181
|
+
function definedStyle(style) {
|
|
182
|
+
return {
|
|
183
|
+
...(style.font === undefined ? {} : { font: style.font }),
|
|
184
|
+
...(style.sizePt === undefined ? {} : { sizePt: style.sizePt }),
|
|
185
|
+
...(style.color === undefined ? {} : { color: style.color }),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function inlineNodes(ctx, path, source, blockStyle) {
|
|
189
|
+
const { text, runs } = source;
|
|
190
|
+
if ((text === undefined) === (runs === undefined)) {
|
|
191
|
+
report(ctx, path, "text_or_runs_required");
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
const base = blockStyle === undefined ? {} : definedStyle(blockStyle);
|
|
195
|
+
if (runs === undefined) {
|
|
196
|
+
return withMarks(lineToContent(singleLine(text ?? "")), textStyleMarks(base));
|
|
197
|
+
}
|
|
198
|
+
return runs.flatMap((run) => withMarks(lineToContent(singleLine(run.text)), [
|
|
199
|
+
...runMarks(run),
|
|
200
|
+
...textStyleMarks({ ...base, ...definedStyle(run) }),
|
|
201
|
+
]));
|
|
202
|
+
}
|
|
203
|
+
function formatAttributes(ctx, path, format) {
|
|
204
|
+
if (format.align !== undefined && !allowedBlocksFor(ctx.kind).includes("align")) {
|
|
205
|
+
report(ctx, `${path}.align`, "block_not_allowed", { type: "align", kind: ctx.kind });
|
|
206
|
+
}
|
|
207
|
+
const { style } = format;
|
|
208
|
+
return {
|
|
209
|
+
...(format.align === undefined ? {} : { textAlign: format.align }),
|
|
210
|
+
...(style?.lineHeight === undefined ? {} : { lineHeight: style.lineHeight }),
|
|
211
|
+
...(style?.spaceBeforePt === undefined ? {} : { spaceBeforePt: style.spaceBeforePt }),
|
|
212
|
+
...(style?.spaceAfterPt === undefined ? {} : { spaceAfterPt: style.spaceAfterPt }),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function textBlockNode(ctx, path, type, source, format, level) {
|
|
216
|
+
const attrs = {
|
|
217
|
+
...(level === undefined ? {} : { level }),
|
|
218
|
+
...formatAttributes(ctx, path, format),
|
|
219
|
+
};
|
|
220
|
+
return {
|
|
221
|
+
type,
|
|
222
|
+
...(Object.keys(attrs).length === 0 ? {} : { attrs }),
|
|
223
|
+
content: inlineNodes(ctx, path, source, format.textStyle),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function listNode(ctx, path, block) {
|
|
227
|
+
return {
|
|
228
|
+
type: block.ordered ? "orderedList" : "bulletList",
|
|
229
|
+
content: block.items.map((item, index) => {
|
|
230
|
+
const source = typeof item === "string" ? { text: item } : { runs: item };
|
|
231
|
+
return {
|
|
232
|
+
type: "listItem",
|
|
233
|
+
content: [textBlockNode(ctx, `${path}.items.${index}`, "paragraph", source, block)],
|
|
234
|
+
};
|
|
235
|
+
}),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function rowNode(ctx, path, row, options) {
|
|
239
|
+
if (options.widths !== undefined && options.widths.length !== row.cells.length) {
|
|
240
|
+
report(ctx, `${path}.cells`, "invalid_table", {
|
|
241
|
+
problem: "columnWidthsPx must match the cells per row",
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
type: "tableRow",
|
|
246
|
+
...(options.attrs === undefined ? {} : { attrs: options.attrs }),
|
|
247
|
+
content: row.cells.map((cell, index) => {
|
|
248
|
+
const width = options.widths?.[index];
|
|
249
|
+
const attrs = {
|
|
250
|
+
...(cell.background === undefined ? {} : { background: cell.background }),
|
|
251
|
+
...(width === undefined ? {} : { colwidth: [width] }),
|
|
252
|
+
};
|
|
253
|
+
const cellPath = `${path}.cells.${index}`;
|
|
254
|
+
return {
|
|
255
|
+
type: options.header ? "tableHeader" : "tableCell",
|
|
256
|
+
...(Object.keys(attrs).length === 0 ? {} : { attrs }),
|
|
257
|
+
content: [textBlockNode(ctx, cellPath, "paragraph", cell, { align: cell.align })],
|
|
258
|
+
};
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function tableNode(ctx, path, block) {
|
|
263
|
+
const widths = block.columnWidthsPx;
|
|
264
|
+
const { header, repeat } = block;
|
|
265
|
+
if (repeat !== undefined) {
|
|
266
|
+
if (!isDocumentReferenceName(repeat.each)) {
|
|
267
|
+
report(ctx, `${path}.repeat.each`, "invalid_repeat_variable", { each: repeat.each });
|
|
268
|
+
}
|
|
269
|
+
if (!allowedBlocksFor(ctx.kind).includes("repeat")) {
|
|
270
|
+
report(ctx, `${path}.repeat`, "block_not_allowed", { type: "repeat", kind: ctx.kind });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const rows = [
|
|
274
|
+
...(header === undefined
|
|
275
|
+
? []
|
|
276
|
+
: [
|
|
277
|
+
rowNode(ctx, `${path}.header`, header, {
|
|
278
|
+
header: true,
|
|
279
|
+
widths,
|
|
280
|
+
attrs: { repeatHeader: true },
|
|
281
|
+
}),
|
|
282
|
+
]),
|
|
283
|
+
...block.rows.map((row, index) => rowNode(ctx, `${path}.rows.${index}`, row, { header: false, widths })),
|
|
284
|
+
...(repeat === undefined
|
|
285
|
+
? []
|
|
286
|
+
: [
|
|
287
|
+
rowNode(ctx, `${path}.repeat.row`, repeat.row, {
|
|
288
|
+
header: false,
|
|
289
|
+
widths,
|
|
290
|
+
attrs: { each: repeat.each },
|
|
291
|
+
}),
|
|
292
|
+
]),
|
|
293
|
+
];
|
|
294
|
+
const cellCounts = new Set(rows.map((row) => row.content?.length ?? 0));
|
|
295
|
+
if (rows.length === 0 || cellCounts.size > 1) {
|
|
296
|
+
report(ctx, path, "invalid_table", {
|
|
297
|
+
problem: "needs a row and the same number of cells in every row",
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
type: "table",
|
|
302
|
+
...(block.borders === undefined ? {} : { attrs: { borders: block.borders } }),
|
|
303
|
+
content: rows,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function frameNode(ctx, path, input) {
|
|
307
|
+
return {
|
|
308
|
+
type: "documentFrame",
|
|
309
|
+
attrs: {
|
|
310
|
+
xMm: input.xMm,
|
|
311
|
+
yMm: input.yMm,
|
|
312
|
+
widthMm: input.widthMm,
|
|
313
|
+
heightMm: input.heightMm,
|
|
314
|
+
preset: input.preset ?? null,
|
|
315
|
+
reserveFlow: input.reserveFlow ?? true,
|
|
316
|
+
},
|
|
317
|
+
content: input.blocks.map((inner, index) => blockNode(ctx, `${path}.blocks.${index}`, inner)),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function imageNode(ctx, path, input) {
|
|
321
|
+
if (!isDocumentResourceKey(input.resource)) {
|
|
322
|
+
report(ctx, `${path}.resource`, "invalid_resource_key", { resource: input.resource });
|
|
323
|
+
}
|
|
324
|
+
return { type: "resource", attrs: { resource: input.resource, alt: input.alt ?? null } };
|
|
325
|
+
}
|
|
326
|
+
function buttonNode(ctx, path, input) {
|
|
327
|
+
if (!isDocumentPlaceholderHref(input.href)) {
|
|
328
|
+
report(ctx, `${path}.href`, "invalid_button_href", { href: input.href });
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
type: "button",
|
|
332
|
+
attrs: { href: input.href },
|
|
333
|
+
content: lineToContent(singleLine(input.text)),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
export function blockNode(ctx, path, input) {
|
|
337
|
+
if (!isBlockTypeAllowed(input.type, ctx.kind)) {
|
|
338
|
+
report(ctx, `${path}.type`, "block_not_allowed", { type: input.type, kind: ctx.kind });
|
|
339
|
+
}
|
|
340
|
+
switch (input.type) {
|
|
341
|
+
case "paragraph":
|
|
342
|
+
return textBlockNode(ctx, path, "paragraph", input, input);
|
|
343
|
+
case "heading":
|
|
344
|
+
return textBlockNode(ctx, path, "heading", input, input, input.level);
|
|
345
|
+
case "list":
|
|
346
|
+
return listNode(ctx, path, input);
|
|
347
|
+
case "table":
|
|
348
|
+
return tableNode(ctx, path, input);
|
|
349
|
+
case "frame":
|
|
350
|
+
return frameNode(ctx, path, input);
|
|
351
|
+
case "image":
|
|
352
|
+
return imageNode(ctx, path, input);
|
|
353
|
+
case "button":
|
|
354
|
+
return buttonNode(ctx, path, input);
|
|
355
|
+
case "divider":
|
|
356
|
+
case "pageBreak":
|
|
357
|
+
return { type: input.type };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const PRINT_ATTRIBUTES = [
|
|
361
|
+
"lineHeight",
|
|
362
|
+
"spaceBeforePt",
|
|
363
|
+
"spaceAfterPt",
|
|
364
|
+
"background",
|
|
365
|
+
"colwidth",
|
|
366
|
+
"borders",
|
|
367
|
+
];
|
|
368
|
+
function isPresent(value) {
|
|
369
|
+
return value !== undefined && value !== null;
|
|
370
|
+
}
|
|
371
|
+
// Frames are refused as blocks, so only the styling that would ride along in other blocks counts here.
|
|
372
|
+
export function usesPrintStyling(node) {
|
|
373
|
+
if (node.marks?.some((mark) => mark.type === "documentTextStyle"))
|
|
374
|
+
return true;
|
|
375
|
+
if (PRINT_ATTRIBUTES.some((name) => isPresent(node.attrs?.[name])))
|
|
376
|
+
return true;
|
|
377
|
+
return (node.content ?? []).some(usesPrintStyling);
|
|
378
|
+
}
|
|
379
|
+
// Only a PDF applies print styling; a mail would keep it through the rebuild and the sanitizer refuses it on write.
|
|
380
|
+
export function refusePrintStyling(kind, node, path) {
|
|
381
|
+
return kind === "mail" && usesPrintStyling(node)
|
|
382
|
+
? patchIssue(path, "print_style_not_allowed", { kind })
|
|
383
|
+
: null;
|
|
384
|
+
}
|
|
385
|
+
const TEXT_BLOCK_NODE_TYPES = new Set(["paragraph", "heading"]);
|
|
386
|
+
const INLINE_NODE_TYPES = new Set(["text", "variable"]);
|
|
387
|
+
function mergeTextStyleMark(node, style) {
|
|
388
|
+
const existing = node.marks?.find((mark) => mark.type === "documentTextStyle");
|
|
389
|
+
const merged = {
|
|
390
|
+
color: null,
|
|
391
|
+
font: null,
|
|
392
|
+
sizePt: null,
|
|
393
|
+
...existing?.attrs,
|
|
394
|
+
...definedStyle(style),
|
|
395
|
+
};
|
|
396
|
+
return {
|
|
397
|
+
...node,
|
|
398
|
+
marks: [
|
|
399
|
+
...(node.marks ?? []).filter((mark) => mark.type !== "documentTextStyle"),
|
|
400
|
+
{ type: "documentTextStyle", attrs: merged },
|
|
401
|
+
],
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function applyTextStyle(node, style) {
|
|
405
|
+
if (INLINE_NODE_TYPES.has(node.type ?? ""))
|
|
406
|
+
return mergeTextStyleMark(node, style);
|
|
407
|
+
return node.content === undefined
|
|
408
|
+
? node
|
|
409
|
+
: { ...node, content: node.content.map((child) => applyTextStyle(child, style)) };
|
|
410
|
+
}
|
|
411
|
+
function applyBlockAttributes(node, attrs) {
|
|
412
|
+
if (TEXT_BLOCK_NODE_TYPES.has(node.type ?? "")) {
|
|
413
|
+
return { ...node, attrs: { ...node.attrs, ...attrs } };
|
|
414
|
+
}
|
|
415
|
+
return node.content === undefined
|
|
416
|
+
? node
|
|
417
|
+
: { ...node, content: node.content.map((child) => applyBlockAttributes(child, attrs)) };
|
|
418
|
+
}
|
|
419
|
+
export const FORMATTABLE_NODE_TYPES = new Set([
|
|
420
|
+
"paragraph",
|
|
421
|
+
"heading",
|
|
422
|
+
"bulletList",
|
|
423
|
+
"orderedList",
|
|
424
|
+
]);
|
|
425
|
+
// Applies the given format to a paragraph, heading or list, keeping everything it does not mention.
|
|
426
|
+
export function formatNode(ctx, path, node, format) {
|
|
427
|
+
const attrs = formatAttributes(ctx, path, format);
|
|
428
|
+
const withAttrs = Object.keys(attrs).length === 0 ? node : applyBlockAttributes(node, attrs);
|
|
429
|
+
return format.textStyle === undefined ? withAttrs : applyTextStyle(withAttrs, format.textStyle);
|
|
430
|
+
}
|