@cosmicdrift/kumiko-bundled-features 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/dist/auth-email-password/seeding.d.ts +11 -0
- package/dist/auth-email-password/seeding.js +17 -2
- 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/dist/tenant/seeding.d.ts +14 -0
- package/dist/tenant/seeding.js +44 -0
- package/package.json +19 -11
- package/src/signature/changes.json +6 -0
- package/src/template-resolver/changes.json +24 -0
|
@@ -42,9 +42,15 @@ function eachOf(table) {
|
|
|
42
42
|
}
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
45
|
+
// A line break reads back as "\n"; writing text collapses it again, so a break is set with runs.
|
|
46
|
+
function lineWithBreaks(content) {
|
|
47
|
+
return (content ?? [])
|
|
48
|
+
.map((node) => (node.type === "hardBreak" ? "\n" : contentToLine([node])))
|
|
49
|
+
.join("");
|
|
50
|
+
}
|
|
45
51
|
function textLinesOf(node) {
|
|
46
52
|
if (TEXT_BLOCK_TYPES.has(node.type ?? ""))
|
|
47
|
-
return [
|
|
53
|
+
return [lineWithBreaks(node.content)];
|
|
48
54
|
return (node.content ?? []).flatMap(textLinesOf);
|
|
49
55
|
}
|
|
50
56
|
const NON_TEXT_BLOCK_TYPES = new Set([
|
|
@@ -61,6 +67,24 @@ function setOptionalAttrs(block, node) {
|
|
|
61
67
|
if (showIf !== undefined)
|
|
62
68
|
block.showIf = showIf;
|
|
63
69
|
}
|
|
70
|
+
function setImagePrintAttrs(block, node) {
|
|
71
|
+
const widthMm = node.attrs?.["widthMm"];
|
|
72
|
+
if (typeof widthMm === "number")
|
|
73
|
+
block.widthMm = widthMm;
|
|
74
|
+
if (node.attrs?.["bleed"] === true)
|
|
75
|
+
block.bleed = true;
|
|
76
|
+
const align = stringAttr(node, "align");
|
|
77
|
+
if (align !== undefined)
|
|
78
|
+
block.align = align;
|
|
79
|
+
}
|
|
80
|
+
function setDividerAttrs(block, node) {
|
|
81
|
+
const color = stringAttr(node, "color");
|
|
82
|
+
if (color !== undefined)
|
|
83
|
+
block.color = color;
|
|
84
|
+
const weightPt = node.attrs?.["weightPt"];
|
|
85
|
+
if (typeof weightPt === "number")
|
|
86
|
+
block.weightPt = weightPt;
|
|
87
|
+
}
|
|
64
88
|
function setTypeSpecificAttrs(block, node) {
|
|
65
89
|
const level = node.attrs?.["level"];
|
|
66
90
|
if (block.type === "heading" && typeof level === "number")
|
|
@@ -71,6 +95,10 @@ function setTypeSpecificAttrs(block, node) {
|
|
|
71
95
|
const alt = stringAttr(node, "alt");
|
|
72
96
|
if (block.type === "image" && alt !== undefined)
|
|
73
97
|
block.alt = alt;
|
|
98
|
+
if (block.type === "image")
|
|
99
|
+
setImagePrintAttrs(block, node);
|
|
100
|
+
if (block.type === "divider")
|
|
101
|
+
setDividerAttrs(block, node);
|
|
74
102
|
const href = stringAttr(node, "href");
|
|
75
103
|
if (block.type === "button" && href !== undefined)
|
|
76
104
|
block.href = href;
|
|
@@ -199,7 +227,7 @@ function lookupEntry(state, blockId, fieldPath) {
|
|
|
199
227
|
return { entry };
|
|
200
228
|
}
|
|
201
229
|
function buildBlocks(state, blocks, pathOf) {
|
|
202
|
-
const ctx = { kind: state.kind, issues: [] };
|
|
230
|
+
const ctx = { kind: state.kind, region: state.region, issues: [] };
|
|
203
231
|
const nodes = blocks.map((block, index) => blockNode(ctx, pathOf(index), block));
|
|
204
232
|
nodes.forEach((node, index) => {
|
|
205
233
|
const refused = refusePrintStyling(state.kind, node, pathOf(index));
|
|
@@ -311,7 +339,7 @@ function setResourceOp(state, op, path) {
|
|
|
311
339
|
return patchIssue(`${path}.resource`, "invalid_resource_key", { resource: op.resource });
|
|
312
340
|
}
|
|
313
341
|
const alt = op.alt === undefined ? (entry.node.attrs?.["alt"] ?? null) : op.alt;
|
|
314
|
-
entry.node = { ...entry.node, attrs: { resource: op.resource, alt } };
|
|
342
|
+
entry.node = { ...entry.node, attrs: { ...entry.node.attrs, resource: op.resource, alt } };
|
|
315
343
|
return null;
|
|
316
344
|
}
|
|
317
345
|
function setMetaOp(state, op, path) {
|
|
@@ -378,6 +406,7 @@ export function applyDocumentOps(input) {
|
|
|
378
406
|
});
|
|
379
407
|
const state = {
|
|
380
408
|
kind: input.kind,
|
|
409
|
+
region: input.region,
|
|
381
410
|
replacement: null,
|
|
382
411
|
entries,
|
|
383
412
|
insertedAtStart: [],
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Element as ScanElement } from "happy-dom";
|
|
2
2
|
export declare const IMAGES_BLOCK_SELECTOR = "div[data-images]";
|
|
3
|
-
export declare const PRINT_STYLE_SELECTORS: readonly ["div[data-frame]", "span[data-text-style]", "[data-line-height]", "[data-space-before]", "[data-space-after]", "table[data-borders]", "[data-background]", "[data-colwidth]", "img[data-bleed]"];
|
|
3
|
+
export declare const PRINT_STYLE_SELECTORS: readonly ["div[data-frame]", "span[data-text-style]", "[data-line-height]", "[data-space-before]", "[data-space-after]", "table[data-borders]", "table[data-cell-padding-mm]", "table[data-table-width-mm]", "table[data-table-align]", "tr[data-line-above]", "tr[data-line-below]", "[data-background]", "[data-colwidth]", "img[data-bleed]", "img[data-width-mm]", "img[data-align]", "hr[data-color]", "hr[data-weight-pt]"];
|
|
4
4
|
export type PrintOnlyFeatures = {
|
|
5
5
|
readonly hasImagesBlock: boolean;
|
|
6
6
|
readonly printStyleSelectors: readonly string[];
|
|
7
7
|
};
|
|
8
8
|
export declare function scanPrintOnlyFeatures(body: ScanElement): PrintOnlyFeatures;
|
|
9
9
|
export declare function hasNestedFrame(body: ScanElement): boolean;
|
|
10
|
+
export declare function framesOutsidePage(body: ScanElement): string[];
|
|
10
11
|
export declare function hasFrame(body: ScanElement): boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readFrameAttributes } from "./web/document-print-style.js";
|
|
2
|
+
import { PDF_MAX_PAGE_EDGE_MM } from "./web/pdf-constants.js";
|
|
1
3
|
export const IMAGES_BLOCK_SELECTOR = "div[data-images]";
|
|
2
4
|
export const PRINT_STYLE_SELECTORS = [
|
|
3
5
|
"div[data-frame]",
|
|
@@ -6,9 +8,18 @@ export const PRINT_STYLE_SELECTORS = [
|
|
|
6
8
|
"[data-space-before]",
|
|
7
9
|
"[data-space-after]",
|
|
8
10
|
"table[data-borders]",
|
|
11
|
+
"table[data-cell-padding-mm]",
|
|
12
|
+
"table[data-table-width-mm]",
|
|
13
|
+
"table[data-table-align]",
|
|
14
|
+
"tr[data-line-above]",
|
|
15
|
+
"tr[data-line-below]",
|
|
9
16
|
"[data-background]",
|
|
10
17
|
"[data-colwidth]",
|
|
11
18
|
"img[data-bleed]",
|
|
19
|
+
"img[data-width-mm]",
|
|
20
|
+
"img[data-align]",
|
|
21
|
+
"hr[data-color]",
|
|
22
|
+
"hr[data-weight-pt]",
|
|
12
23
|
];
|
|
13
24
|
export function scanPrintOnlyFeatures(body) {
|
|
14
25
|
return {
|
|
@@ -19,6 +30,18 @@ export function scanPrintOnlyFeatures(body) {
|
|
|
19
30
|
export function hasNestedFrame(body) {
|
|
20
31
|
return Array.from(body.querySelectorAll("div[data-frame]")).some((frame) => frame.parentElement !== body);
|
|
21
32
|
}
|
|
33
|
+
export function framesOutsidePage(body) {
|
|
34
|
+
return Array.from(body.querySelectorAll("div[data-frame]")).flatMap((element) => {
|
|
35
|
+
const frame = readFrameAttributes(element);
|
|
36
|
+
if (frame === null)
|
|
37
|
+
return [];
|
|
38
|
+
const overshootsPage = frame.xMm + frame.widthMm > PDF_MAX_PAGE_EDGE_MM ||
|
|
39
|
+
frame.yMm + frame.heightMm > PDF_MAX_PAGE_EDGE_MM;
|
|
40
|
+
return overshootsPage
|
|
41
|
+
? [`${frame.xMm}/${frame.yMm} ${frame.widthMm}x${frame.heightMm} mm`]
|
|
42
|
+
: [];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
22
45
|
export function hasFrame(body) {
|
|
23
46
|
return body.querySelector("div[data-frame]") !== null;
|
|
24
47
|
}
|
|
@@ -2,7 +2,7 @@ import type { FieldIssue } from "@cosmicdrift/kumiko-framework/errors";
|
|
|
2
2
|
import type { JSONContent } from "@tiptap/core";
|
|
3
3
|
import { type Element as ScanElement } from "happy-dom";
|
|
4
4
|
import type { ContentFormat } from "./web/constants.ts";
|
|
5
|
-
export type DocumentViolationCode = "script_element" | "event_handler_attribute" | "disallowed_link_href" | "relative_link_without_base" | "external_image_source" | "image_without_resource" | "invalid_reference_name" | "embedded_content" | "unsafe_attribute_value" | "images_block_pdf_only" | "print_style_pdf_only" | "frame_not_top_level" | "button_href_not_placeholder" | "document_requires_html_format" | "layout_requires_mjml_format" | "layout_invalid_structure" | "layout_missing_content_slot" | "layout_source_system_only";
|
|
5
|
+
export type DocumentViolationCode = "script_element" | "event_handler_attribute" | "disallowed_link_href" | "relative_link_without_base" | "external_image_source" | "image_without_resource" | "invalid_reference_name" | "embedded_content" | "unsafe_attribute_value" | "images_block_pdf_only" | "print_style_pdf_only" | "frame_not_top_level" | "frame_outside_page" | "button_href_not_placeholder" | "document_requires_html_format" | "layout_requires_mjml_format" | "layout_invalid_structure" | "layout_missing_content_slot" | "layout_source_system_only";
|
|
6
6
|
export type DocumentViolation = {
|
|
7
7
|
readonly code: DocumentViolationCode;
|
|
8
8
|
readonly detail: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
2
2
|
import { generateHTML, generateJSON } from "@tiptap/html/server";
|
|
3
3
|
import { Window } from "happy-dom";
|
|
4
|
-
import { hasNestedFrame, scanPrintOnlyFeatures } from "./document-print-only.js";
|
|
4
|
+
import { framesOutsidePage, hasNestedFrame, scanPrintOnlyFeatures } from "./document-print-only.js";
|
|
5
5
|
import { DOCUMENT_HTML_KINDS } from "./web/constants.js";
|
|
6
6
|
import { DOCUMENT_CONDITION_ATTRIBUTE, documentExtensions, isAllowedDocumentLinkHref, isAllowedDocumentUrlHref, isDocumentPlaceholderHref, isDocumentReferenceName, isDocumentResourceKey, } from "./web/document-schema.js";
|
|
7
7
|
import { isDocumentStepKey } from "./web/document-steps.js";
|
|
8
|
+
import { PDF_MAX_PAGE_EDGE_MM } from "./web/pdf-constants.js";
|
|
8
9
|
export function violation(code, detail, message) {
|
|
9
10
|
return { code, detail, message };
|
|
10
11
|
}
|
|
@@ -147,6 +148,9 @@ function scanDocumentHtml(html) {
|
|
|
147
148
|
if (hasNestedFrame(body)) {
|
|
148
149
|
violations.push(violation("frame_not_top_level", "div[data-frame]", "A frame must sit directly in the document body, not inside another block"));
|
|
149
150
|
}
|
|
151
|
+
for (const box of framesOutsidePage(body)) {
|
|
152
|
+
violations.push(violation("frame_outside_page", box, `A frame (${box}) must lie within the largest supported paper size (${PDF_MAX_PAGE_EDGE_MM} mm)`));
|
|
153
|
+
}
|
|
150
154
|
});
|
|
151
155
|
return violations;
|
|
152
156
|
}
|
|
@@ -254,6 +258,7 @@ const VIOLATION_I18N_KEYS = {
|
|
|
254
258
|
images_block_pdf_only: "templateResolver.errors.document.imagesBlockPdfOnly",
|
|
255
259
|
print_style_pdf_only: "templateResolver.errors.document.printStylePdfOnly",
|
|
256
260
|
frame_not_top_level: "templateResolver.errors.document.frameNotTopLevel",
|
|
261
|
+
frame_outside_page: "templateResolver.errors.document.frameOutsidePage",
|
|
257
262
|
button_href_not_placeholder: "templateResolver.errors.document.buttonHrefNotPlaceholder",
|
|
258
263
|
document_requires_html_format: "templateResolver.errors.document.documentRequiresHtmlFormat",
|
|
259
264
|
layout_requires_mjml_format: "templateResolver.errors.document.layoutRequiresMjmlFormat",
|
|
@@ -22,7 +22,7 @@ export function makeCreateLayoutWrite(policy) {
|
|
|
22
22
|
schema: z.object({ name: slugSchema, title: titleSchema, locale: localeSchema }),
|
|
23
23
|
access: templateEditAccess(policy.tenantEditable),
|
|
24
24
|
agent: { risk: "low", effect: "proposal" },
|
|
25
|
-
description: "Creates a new PDF layout of the caller's tenant as a draft under the slug tenant-layout-<name> (name is kebab-case) with empty header, signature and footer regions and the standard look (font, size, table style); it fails with layout_exists when the tenant already has that layout. A TenantAdmin may create layouts as soon as they may edit any PDF template; every other caller is refused. Returns the full slug, locale, kind and base ({scope, version}) for the next call. Next steps: fill the regions with patch-draft (kind pdf-layout, the returned slug, region header, signature or footer; setMeta changes margins, fontFamily, fontSizePt, textColor, tableStyle, tableHeaderBackground), then let a person publish the layout and point a PDF template at it with patch-draft setMeta {layoutSlug: <returned slug>}.",
|
|
25
|
+
description: "Creates a new PDF layout of the caller's tenant as a draft under the slug tenant-layout-<name> (name is kebab-case) with empty header, signature and footer regions and the standard look (font, size, table style); it fails with layout_exists when the tenant already has that layout. A TenantAdmin may create layouts as soon as they may edit any PDF template; every other caller is refused. Returns the full slug, locale, kind and base ({scope, version}) for the next call. Next steps: fill the regions with patch-draft (kind pdf-layout, the returned slug, region header, signature or footer; setMeta changes margins {top,right,bottom,left in mm}, fontFamily, fontSizePt, textColor, tableStyle, tableHeaderBackground, tableLineColor (#rrggbb, line color of the table style, default #bbb), foldMarks (none|din-a|din-b: DIN 5008 fold and punch marks at the left paper edge on every page, form A folds at 87 and 192 mm, form B at 105 and 210 mm), cornerMarks (boolean, default false; angles of 5 mm legs, 0.5 pt, 10 mm from the paper edge in all four corners of every page), paperColor (#rrggbb when the whole page has a tinted paper background, margins, header and footer included; default white), headerOnFirstPage and footerOnFirstPage (booleans, default true; false prints the header or footer only from page 2, margins stay the same)), then let a person publish the layout and point a PDF template at it with patch-draft setMeta {layoutSlug: <returned slug>}.",
|
|
26
26
|
handler: async (event, ctx) => {
|
|
27
27
|
const { name, title, locale } = event.payload;
|
|
28
28
|
const slug = `${TENANT_LAYOUT_SLUG_PREFIX}${name}`;
|