@cosmicdrift/kumiko-samples 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/package.json +1 -1
- package/packages/bundled-features/package.json +6 -1
- package/packages/bundled-features/src/agent-tools/api-docs/schema-fields.ts +14 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/auth-email-password/index.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/signup-activation.ts +2 -5
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +0 -6
- package/packages/bundled-features/src/cap-counter/changes.json +6 -0
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +46 -13
- package/packages/bundled-features/src/channel-whatsapp/changes.json +1 -1
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +13 -1
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +23 -6
- package/packages/bundled-features/src/signature/README.md +4 -4
- package/packages/bundled-features/src/signature/changes.json +18 -0
- package/packages/bundled-features/src/signature/entity.ts +3 -1
- package/packages/bundled-features/src/signature/feature.ts +16 -3
- package/packages/bundled-features/src/signature/handlers/lifecycle.write.ts +33 -1
- package/packages/bundled-features/src/signature/i18n.ts +1 -0
- package/packages/bundled-features/src/signature/list-cursor-seal.ts +59 -0
- package/packages/bundled-features/src/signature/options.ts +2 -2
- package/packages/bundled-features/src/signature/payloads.ts +14 -2
- package/packages/bundled-features/src/signature/png.ts +25 -4
- package/packages/bundled-features/src/signature/subject-queries.ts +47 -7
- package/packages/bundled-features/src/signature/sweep.ts +32 -8
- package/packages/bundled-features/src/signature/web/constants.ts +12 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +1 -1
- package/packages/bundled-features/src/subscription-stripe/changes.json +6 -0
- package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +2 -0
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +21 -16
- package/packages/bundled-features/src/template-resolver/changes.json +38 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +3 -8
- package/packages/bundled-features/src/template-resolver/compile-document-styles.ts +102 -0
- package/packages/bundled-features/src/template-resolver/document-frames.ts +25 -0
- package/packages/bundled-features/src/template-resolver/document-op-blocks.ts +568 -0
- package/packages/bundled-features/src/template-resolver/document-ops.ts +136 -126
- package/packages/bundled-features/src/template-resolver/document-print-only.ts +41 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +41 -19
- package/packages/bundled-features/src/template-resolver/feature.ts +15 -0
- package/packages/bundled-features/src/template-resolver/handlers/apply-layout.write.ts +137 -0
- package/packages/bundled-features/src/template-resolver/handlers/create-layout.write.ts +87 -0
- package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +2 -2
- package/packages/bundled-features/src/template-resolver/handlers/document-blocks.query.ts +13 -8
- package/packages/bundled-features/src/template-resolver/handlers/document-region.ts +47 -0
- package/packages/bundled-features/src/template-resolver/handlers/failure-reason.ts +13 -0
- package/packages/bundled-features/src/template-resolver/handlers/import-bundle-system.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/handlers/layout-source.query.ts +17 -5
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +16 -4
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +19 -6
- package/packages/bundled-features/src/template-resolver/handlers/publish-templates.write.ts +69 -0
- package/packages/bundled-features/src/template-resolver/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/template-resolver/handlers/template-write.ts +15 -3
- package/packages/bundled-features/src/template-resolver/handlers/tenant-settings.ts +122 -0
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +25 -10
- package/packages/bundled-features/src/template-resolver/handlers/upsert-system.write.ts +7 -3
- package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +131 -18
- package/packages/bundled-features/src/template-resolver/handlers/validate.query.ts +10 -0
- package/packages/bundled-features/src/template-resolver/i18n.ts +3 -0
- package/packages/bundled-features/src/template-resolver/index.ts +29 -0
- package/packages/bundled-features/src/template-resolver/layout-regions.ts +54 -16
- package/packages/bundled-features/src/template-resolver/print-document.ts +3 -1
- package/packages/bundled-features/src/template-resolver/seeding.ts +4 -0
- package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +11 -1
- package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +37 -1
- package/packages/bundled-features/src/template-resolver/template-meta.ts +25 -6
- package/packages/bundled-features/src/template-resolver/template-preview.ts +6 -7
- package/packages/bundled-features/src/template-resolver/template-validation.ts +10 -3
- package/packages/bundled-features/src/template-resolver/web/constants.ts +29 -0
- package/packages/bundled-features/src/template-resolver/web/document-blocks.ts +5 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +34 -2
- package/packages/bundled-features/src/template-resolver/web/document-editor-fonts.ts +13 -0
- package/packages/bundled-features/src/template-resolver/web/document-fonts.ts +21 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-control.ts +428 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-node-view.tsx +207 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-decorations.ts +196 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-defaults.ts +59 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-style.ts +246 -0
- package/packages/bundled-features/src/template-resolver/web/document-repeat-strip.ts +104 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +29 -9
- package/packages/bundled-features/src/template-resolver/web/document-style-css.ts +107 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +24 -2
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +66 -7
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +13 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +24 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +149 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +290 -10
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +90 -8
- package/packages/bundled-features/src/template-resolver/web/document-toolbar-blocks.ts +20 -0
- package/packages/bundled-features/src/template-resolver/web/fontsource-css.d.ts +2 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +28 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +34 -0
- package/packages/bundled-features/src/template-resolver/web/pdf-constants.ts +6 -0
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +74 -5
- package/packages/bundled-features/src/tenant/company-config.ts +48 -0
- package/packages/bundled-features/src/tenant/feature.ts +11 -0
- package/packages/bundled-features/src/tenant/i18n.ts +14 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +7 -3
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +90 -42
- package/samples/apps/ui-walkthrough/src/app/auth-constants.ts +51 -0
- package/samples/apps/ui-walkthrough/src/app/seed-print-editor-tenants.ts +118 -0
- package/samples/apps/ui-walkthrough/src/app/seed-templates.ts +2 -0
- package/samples/apps/ui-walkthrough/src/app/server.ts +9 -1
- package/samples/apps/ui-walkthrough/src/app/template-seed-data.ts +27 -1
- package/samples/apps/ui-walkthrough/src/run-config.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +238 -1
- package/samples/recipes/crypto-shredding-hr/README.md +1 -1
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +1 -1
- package/samples/recipes/list-table-options/README.md +9 -3
- package/samples/recipes/list-table-options/src/feature.ts +123 -3
- package/samples/recipes/pdf-letterhead/README.md +23 -0
- package/samples/recipes/pdf-letterhead/package.json +12 -0
- package/samples/recipes/pdf-letterhead/src/letterhead.ts +92 -0
|
@@ -39,6 +39,7 @@ import { evaluateTemplateWrite } from "./handlers/template-gates.ts";
|
|
|
39
39
|
import { type TemplateResourceRow, templateResourcesTable } from "./table.ts";
|
|
40
40
|
import type { TemplateBundle } from "./template-bundle.ts";
|
|
41
41
|
import { activeStampChanges, servedStampChanges } from "./template-draft.ts";
|
|
42
|
+
import { refuseReservedLayoutSlug } from "./template-edit-policy.ts";
|
|
42
43
|
import { templateSlugSchema } from "./template-meta.ts";
|
|
43
44
|
import { variablesFromSchema } from "./template-validation.ts";
|
|
44
45
|
import { type ContentFormat, TEXT_BLOCK_KIND, type UpsertKind } from "./web/constants.ts";
|
|
@@ -123,6 +124,9 @@ export async function seedSystemTemplate(
|
|
|
123
124
|
const label = `seedSystemTemplate ${opts.slug}/${opts.kind}/${opts.locale}`;
|
|
124
125
|
const slug = templateSlugSchema.safeParse(opts.slug);
|
|
125
126
|
if (!slug.success) throw new Error(`${label} rejected: ${slug.error.issues[0]?.message}`);
|
|
127
|
+
if (refuseReservedLayoutSlug({ slug: opts.slug, kind: opts.kind }, "slug") !== null) {
|
|
128
|
+
throw new Error(`${label} rejected: reserved_layout_slug`);
|
|
129
|
+
}
|
|
126
130
|
const title = seedTitleColumn(opts, label);
|
|
127
131
|
const evaluated = evaluateTemplateWrite({
|
|
128
132
|
kind: opts.kind,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { isPlainObject, propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
3
|
-
import { SYSTEM_TENANT_ID } from "./web/constants.ts";
|
|
3
|
+
import { SYSTEM_TENANT_ID, TENANT_LAYOUT_SLUG_PREFIX } from "./web/constants.ts";
|
|
4
4
|
import { TEMPLATE_RESOLVER_FEATURE } from "./web/qualified-names.ts";
|
|
5
5
|
|
|
6
6
|
type DeliveryTarget = { readonly kind: string; readonly slug: string };
|
|
@@ -15,12 +15,22 @@ export type TemplateDeliveryPolicy = {
|
|
|
15
15
|
|
|
16
16
|
const NOTHING_UNLOCKED: TemplateDeliveryPolicy = { tenantEditable: [], collectionKinds: [] };
|
|
17
17
|
|
|
18
|
+
// Tenant-created layouts have no entry of their own: they are served and edited once the app unlocks any PDF template.
|
|
19
|
+
export function isTenantLayout(target: DeliveryTarget): boolean {
|
|
20
|
+
return target.kind === "pdf-layout" && target.slug.startsWith(TENANT_LAYOUT_SLUG_PREFIX);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function unlocksTenantLayouts(policy: TemplateDeliveryPolicy): boolean {
|
|
24
|
+
return policy.tenantEditable.some((entry) => entry.kind === "document-pdf");
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export function isTenantOverrideServed(
|
|
19
28
|
policy: TemplateDeliveryPolicy,
|
|
20
29
|
target: DeliveryTarget,
|
|
21
30
|
): boolean {
|
|
22
31
|
return (
|
|
23
32
|
policy.collectionKinds.includes(target.kind) ||
|
|
33
|
+
(isTenantLayout(target) && unlocksTenantLayouts(policy)) ||
|
|
24
34
|
policy.tenantEditable.some((entry) => entry.kind === target.kind && entry.slug === target.slug)
|
|
25
35
|
);
|
|
26
36
|
}
|
|
@@ -7,12 +7,15 @@ import {
|
|
|
7
7
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
8
|
import {
|
|
9
9
|
AccessDeniedError,
|
|
10
|
+
ValidationError,
|
|
10
11
|
type WriteFailure,
|
|
11
12
|
writeFailure,
|
|
12
13
|
} from "@cosmicdrift/kumiko-framework/errors";
|
|
14
|
+
import type { TemplateWriteScope } from "./layout-regions.ts";
|
|
13
15
|
import { type TemplateResourceRow, templateResourcesTable } from "./table.ts";
|
|
16
|
+
import { isTenantLayout } from "./template-delivery-policy.ts";
|
|
14
17
|
import { isSystemAdmin } from "./template-draft.ts";
|
|
15
|
-
import type
|
|
18
|
+
import { TENANT_LAYOUT_SLUG_PREFIX, type TemplateKind } from "./web/constants.ts";
|
|
16
19
|
import { TemplateResolverErrors } from "./web/qualified-names.ts";
|
|
17
20
|
|
|
18
21
|
export type TenantEditableTemplate = {
|
|
@@ -44,6 +47,7 @@ export function mayEditTemplate(
|
|
|
44
47
|
target: EditTarget,
|
|
45
48
|
): boolean {
|
|
46
49
|
if (isSystemAdmin(user)) return true;
|
|
50
|
+
if (isTenantLayout(target)) return mayEditTenantLayouts(policy, user);
|
|
47
51
|
const entry = policy.tenantEditable.find(
|
|
48
52
|
(candidate) => candidate.slug === target.slug && candidate.kind === target.kind,
|
|
49
53
|
);
|
|
@@ -89,3 +93,35 @@ export async function refuseTemplateEditById(
|
|
|
89
93
|
? refuseMissingTemplate(policy, user)
|
|
90
94
|
: refuseTemplateEdit(policy, user, row);
|
|
91
95
|
}
|
|
96
|
+
|
|
97
|
+
// A tenant layout reaches every template that names it, so building one needs the right on all PDF
|
|
98
|
+
// templates (and at least one must exist: every() on an empty list is true).
|
|
99
|
+
export function mayEditTenantLayouts(policy: TemplateEditPolicy, user: EditUser): boolean {
|
|
100
|
+
const pdfEntries = policy.tenantEditable.filter((entry) => entry.kind === "document-pdf");
|
|
101
|
+
return pdfEntries.length > 0 && pdfEntries.every((entry) => hasAccess(user, entry.access));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function refuseReservedSystemLayoutSlug(
|
|
105
|
+
scope: TemplateWriteScope,
|
|
106
|
+
target: EditTarget,
|
|
107
|
+
path: string,
|
|
108
|
+
): WriteFailure | null {
|
|
109
|
+
return scope === "system" ? refuseReservedLayoutSlug(target, path) : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// System layouts must not take a slug from the tenant namespace.
|
|
113
|
+
export function refuseReservedLayoutSlug(target: EditTarget, path: string): WriteFailure | null {
|
|
114
|
+
if (!isTenantLayout(target)) return null;
|
|
115
|
+
return writeFailure(
|
|
116
|
+
new ValidationError({
|
|
117
|
+
fields: [
|
|
118
|
+
{
|
|
119
|
+
path,
|
|
120
|
+
code: "reserved_layout_slug",
|
|
121
|
+
i18nKey: "templateResolver.errors.template.reservedLayoutSlug",
|
|
122
|
+
params: { prefix: TENANT_LAYOUT_SLUG_PREFIX },
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
PDF_PAGE_FORMATS,
|
|
6
6
|
type TemplateKind,
|
|
7
7
|
} from "./web/constants.ts";
|
|
8
|
+
import { DOCUMENT_FONTS } from "./web/document-fonts.ts";
|
|
8
9
|
import { MAIL_TONES, type MailTone } from "./web/mail-constants.ts";
|
|
9
10
|
import {
|
|
10
11
|
MAIL_LAYOUT_ACCENT_LINES,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
MAIL_LAYOUT_FONTS,
|
|
13
14
|
MAIL_LAYOUT_WIDTHS,
|
|
14
15
|
} from "./web/mail-layout-constants.ts";
|
|
16
|
+
import { PDF_TABLE_STYLES } from "./web/pdf-constants.ts";
|
|
15
17
|
|
|
16
18
|
// One or more kebab segments joined by ":" — notification templates are seeded
|
|
17
19
|
// under their qualified name `feature:notify:name`.
|
|
@@ -63,6 +65,9 @@ const mailMetaSchema = z.preprocess(
|
|
|
63
65
|
);
|
|
64
66
|
|
|
65
67
|
const marginMm = z.number().finite().min(0).max(100).optional();
|
|
68
|
+
const pdfMargins = z
|
|
69
|
+
.object({ top: marginMm, right: marginMm, bottom: marginMm, left: marginMm })
|
|
70
|
+
.strict();
|
|
66
71
|
|
|
67
72
|
// The file name ends up in a Content-Disposition header and on disk.
|
|
68
73
|
const FORBIDDEN_FILE_NAME = /[/\\";]|\.\./;
|
|
@@ -80,10 +85,7 @@ const pdfMetaSchema = z
|
|
|
80
85
|
orientation: z.enum(PDF_ORIENTATIONS).optional(),
|
|
81
86
|
printBackground: z.boolean().optional(),
|
|
82
87
|
layoutHeaderFooter: z.boolean().optional(),
|
|
83
|
-
margins:
|
|
84
|
-
.object({ top: marginMm, right: marginMm, bottom: marginMm, left: marginMm })
|
|
85
|
-
.strict()
|
|
86
|
-
.optional(),
|
|
88
|
+
margins: pdfMargins.optional(),
|
|
87
89
|
fileName: singleLine(200)
|
|
88
90
|
.min(1)
|
|
89
91
|
.refine((value) => !FORBIDDEN_FILE_NAME.test(value), 'must not contain / \\ " ; or ..')
|
|
@@ -111,12 +113,24 @@ const mailLayoutMetaSchema = z
|
|
|
111
113
|
})
|
|
112
114
|
.strict();
|
|
113
115
|
|
|
114
|
-
const
|
|
116
|
+
const hexColor = z.string().regex(HEX_COLOR_PATTERN, "must be a #rrggbb color");
|
|
117
|
+
|
|
118
|
+
const pdfLayoutMetaSchema = z
|
|
119
|
+
.object({
|
|
120
|
+
margins: pdfMargins.optional(),
|
|
121
|
+
fontFamily: z.enum(DOCUMENT_FONTS).optional(),
|
|
122
|
+
fontSizePt: z.number().finite().min(6).max(24).optional(),
|
|
123
|
+
textColor: hexColor.optional(),
|
|
124
|
+
tableStyle: z.enum(PDF_TABLE_STYLES).optional(),
|
|
125
|
+
tableHeaderBackground: hexColor.optional(),
|
|
126
|
+
})
|
|
127
|
+
.strict();
|
|
115
128
|
|
|
116
129
|
export type MailTemplateMeta = z.infer<typeof mailMetaSchema>;
|
|
117
130
|
export type PdfTemplateMeta = z.infer<typeof pdfMetaSchema>;
|
|
118
131
|
export type MailLayoutMeta = z.infer<typeof mailLayoutMetaSchema>;
|
|
119
|
-
export type
|
|
132
|
+
export type PdfLayoutMeta = z.infer<typeof pdfLayoutMetaSchema>;
|
|
133
|
+
export type LayoutTemplateMeta = MailLayoutMeta | PdfLayoutMeta;
|
|
120
134
|
export type TemplateMeta = MailTemplateMeta | PdfTemplateMeta | LayoutTemplateMeta;
|
|
121
135
|
|
|
122
136
|
export function isMailTemplateMeta(meta: TemplateMeta | null): meta is MailTemplateMeta {
|
|
@@ -133,6 +147,11 @@ export function readMailLayoutMeta(meta: unknown): MailLayoutMeta {
|
|
|
133
147
|
return parsed.success ? parsed.data : {};
|
|
134
148
|
}
|
|
135
149
|
|
|
150
|
+
export function readPdfLayoutMeta(meta: unknown): PdfLayoutMeta {
|
|
151
|
+
const parsed = pdfLayoutMetaSchema.safeParse(meta ?? {});
|
|
152
|
+
return parsed.success ? parsed.data : {};
|
|
153
|
+
}
|
|
154
|
+
|
|
136
155
|
export type TemplateMetaIssue = {
|
|
137
156
|
readonly path: string;
|
|
138
157
|
/** The setting the issue is about (`subject`), `meta` when it concerns the object as a whole. */
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from "./api.ts";
|
|
38
38
|
import { collectDocumentResourceKeys } from "./compile-document-body.ts";
|
|
39
39
|
import { parseStoredJson } from "./handlers/template-gates.ts";
|
|
40
|
+
import { defaultPdfLayoutSlug } from "./handlers/tenant-settings.ts";
|
|
40
41
|
import { validateTemplateDraft } from "./handlers/validate.query.ts";
|
|
41
42
|
import {
|
|
42
43
|
type LayoutRegions,
|
|
@@ -57,7 +58,6 @@ import {
|
|
|
57
58
|
} from "./template-meta.ts";
|
|
58
59
|
import {
|
|
59
60
|
DEFAULT_MAIL_LAYOUT_SLUG,
|
|
60
|
-
DEFAULT_PDF_LAYOUT_SLUG,
|
|
61
61
|
MAIL_PREVIEW_MAX_BYTES,
|
|
62
62
|
SYSTEM_TENANT_ID,
|
|
63
63
|
type TemplateScope,
|
|
@@ -121,11 +121,10 @@ function sampleRow(
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
function sampleList(def: TemplateListVariableDef, labelText: LabelText): Record<string, unknown>[] {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return rows;
|
|
124
|
+
const declared = (def.example ?? []).slice(0, SAMPLE_LIST_ROWS);
|
|
125
|
+
// Declared rows are the whole sample: padding them shows rows the data does not have.
|
|
126
|
+
if (declared.length > 0) return declared.map((given) => sampleRow(def.item, labelText, given));
|
|
127
|
+
return Array.from({ length: SAMPLE_LIST_ROWS }, () => sampleRow(def.item, labelText));
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
function sampleValueFor(name: string, def: TemplateVariableDef, labelText: LabelText): unknown {
|
|
@@ -458,7 +457,7 @@ async function renderDocumentPreview(
|
|
|
458
457
|
layout: await resolvePdfLayout(
|
|
459
458
|
ctx,
|
|
460
459
|
user,
|
|
461
|
-
pdfMeta?.layoutSlug ??
|
|
460
|
+
pdfMeta?.layoutSlug ?? (await defaultPdfLayoutSlug(ctx, user.tenantId, input.locale)),
|
|
462
461
|
input.locale,
|
|
463
462
|
),
|
|
464
463
|
sampleValues,
|
|
@@ -8,6 +8,7 @@ import type { Element as ScanElement } from "happy-dom";
|
|
|
8
8
|
import * as z from "zod";
|
|
9
9
|
import { conditionScopeElement, withParsedDocument } from "./document-sanitizer.ts";
|
|
10
10
|
import type { TemplateMeta } from "./template-meta.ts";
|
|
11
|
+
import { COMPANY_PLACEHOLDERS } from "./web/constants.ts";
|
|
11
12
|
import {
|
|
12
13
|
DOCUMENT_CONDITION_ATTRIBUTE,
|
|
13
14
|
isDocumentPlaceholderHref,
|
|
@@ -24,10 +25,16 @@ export const SYSTEM_PLACEHOLDERS: ReadonlySet<string> = new Set([
|
|
|
24
25
|
const PAGE_PLACEHOLDERS = ["page", "pages"] as const;
|
|
25
26
|
const PAGED_KINDS: ReadonlySet<string> = new Set(["document-pdf", "pdf-layout"]);
|
|
26
27
|
|
|
28
|
+
// A PDF has no signature or imprint block, so both stay empty there and are not offered.
|
|
29
|
+
const PDF_EMPTY_PLACEHOLDERS: ReadonlySet<string> = new Set(["signature", "imprint"]);
|
|
30
|
+
|
|
27
31
|
export function systemPlaceholdersFor(kind: string): ReadonlySet<string> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
if (!PAGED_KINDS.has(kind)) return SYSTEM_PLACEHOLDERS;
|
|
33
|
+
return new Set([
|
|
34
|
+
...[...SYSTEM_PLACEHOLDERS].filter((name) => !PDF_EMPTY_PLACEHOLDERS.has(name)),
|
|
35
|
+
...PAGE_PLACEHOLDERS,
|
|
36
|
+
...COMPANY_PLACEHOLDERS,
|
|
37
|
+
]);
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
const BASE_RESOURCE_KEYS = ["logo"] as const;
|
|
@@ -14,6 +14,10 @@ export type RenderKind = (typeof RENDER_KINDS)[number];
|
|
|
14
14
|
export const DOCUMENT_HTML_KINDS = ["mail", "document-pdf"] as const;
|
|
15
15
|
export type DocumentHtmlKind = (typeof DOCUMENT_HTML_KINDS)[number];
|
|
16
16
|
|
|
17
|
+
// Kinds structured document ops can edit: the two document kinds plus the regions of a PDF layout.
|
|
18
|
+
export const DOCUMENT_OPS_KINDS = [...DOCUMENT_HTML_KINDS, "pdf-layout"] as const;
|
|
19
|
+
export type DocumentOpsKind = (typeof DOCUMENT_OPS_KINDS)[number];
|
|
20
|
+
|
|
17
21
|
// Kinds without a renderer plugin: `notification` is the retired sections-JSON
|
|
18
22
|
// notification kind, kept so rows stored before mails moved to `mail` stay
|
|
19
23
|
// valid on replay; nothing writes or renders it any more. `text-block` is the Markdown text store
|
|
@@ -82,18 +86,40 @@ export const ACTIVE_TEMPLATE_STATUS = "active" satisfies TemplateStatus;
|
|
|
82
86
|
|
|
83
87
|
export { HEX_COLOR_PATTERN } from "./mail-layout-constants.ts";
|
|
84
88
|
export {
|
|
89
|
+
PDF_DEFAULT_FONT_SIZE_PT,
|
|
85
90
|
PDF_DEFAULT_MARGIN_MM,
|
|
86
91
|
PDF_FOOTER_MARGIN_MM,
|
|
87
92
|
PDF_HEADER_MARGIN_MM,
|
|
88
93
|
PDF_ORIENTATIONS,
|
|
89
94
|
PDF_PAGE_FORMATS,
|
|
95
|
+
PDF_TABLE_STYLES,
|
|
90
96
|
type PdfOrientation,
|
|
91
97
|
type PdfPageFormat,
|
|
98
|
+
type PdfTableStyle,
|
|
92
99
|
} from "./pdf-constants.ts";
|
|
93
100
|
|
|
94
101
|
export const DEFAULT_MAIL_LAYOUT_SLUG = "default";
|
|
95
102
|
export const DEFAULT_PDF_LAYOUT_SLUG = "default";
|
|
96
103
|
|
|
104
|
+
// Same names as the tenant feature's company config keys: the placeholder is the key name.
|
|
105
|
+
export const COMPANY_PLACEHOLDERS = [
|
|
106
|
+
"companyAddress",
|
|
107
|
+
"companyPhone",
|
|
108
|
+
"companyEmail",
|
|
109
|
+
"companyWebsite",
|
|
110
|
+
"companyRegister",
|
|
111
|
+
"companyVatId",
|
|
112
|
+
"companyManagement",
|
|
113
|
+
"companyBank",
|
|
114
|
+
"companyIban",
|
|
115
|
+
"companyBic",
|
|
116
|
+
] as const;
|
|
117
|
+
export const MAX_SELECTED_TEMPLATES = 200;
|
|
118
|
+
|
|
119
|
+
// Tenant setting that picks the layout of PDF templates which name none.
|
|
120
|
+
export const DEFAULT_PDF_LAYOUT_SLUG_CONFIG_KEY =
|
|
121
|
+
"template-resolver:config:default-pdf-layout-slug";
|
|
122
|
+
|
|
97
123
|
// The mail transport enforces no size limit of its own; 10 MiB is a common provider ceiling.
|
|
98
124
|
export const MAIL_PREVIEW_MAX_BYTES = 10 * 1024 * 1024;
|
|
99
125
|
|
|
@@ -111,3 +137,6 @@ export const FALLBACK_LOCALE = "de";
|
|
|
111
137
|
|
|
112
138
|
// A collection mounted without `access` is maintained by the platform only; TenantAdmin access is an explicit mount decision.
|
|
113
139
|
export const DEFAULT_COLLECTION_ACCESS = { roles: ["SystemAdmin"] } as const;
|
|
140
|
+
|
|
141
|
+
// Tenant-created PDF layouts live under this slug prefix; system layouts may not use it, so the two namespaces never meet.
|
|
142
|
+
export const TENANT_LAYOUT_SLUG_PREFIX = "tenant-layout-";
|
|
@@ -29,6 +29,11 @@ export const PDF_DOCUMENT_BLOCKS = [
|
|
|
29
29
|
"pageBreak",
|
|
30
30
|
] as const satisfies readonly DocumentToolbarBlock[];
|
|
31
31
|
|
|
32
|
+
// A layout region has no per-document variables, so a steps block there could never show a stage and an images block no photos.
|
|
33
|
+
export const PDF_LAYOUT_DOCUMENT_BLOCKS = PDF_DOCUMENT_BLOCKS.filter(
|
|
34
|
+
(block) => block !== "steps" && block !== "images",
|
|
35
|
+
);
|
|
36
|
+
|
|
32
37
|
/** Block set for a template-resource kind; every kind except "document-pdf" gets the mail set. */
|
|
33
38
|
export function documentBlocksForKind(kind: string | undefined): readonly DocumentToolbarBlock[] {
|
|
34
39
|
return kind === "document-pdf" ? PDF_DOCUMENT_BLOCKS : MAIL_DOCUMENT_BLOCKS;
|
|
@@ -2,17 +2,23 @@ import type { Extensions, NodeViewRenderer } from "@tiptap/core";
|
|
|
2
2
|
import { ListKeymap } from "@tiptap/extension-list";
|
|
3
3
|
import { Dropcursor, Gapcursor, Placeholder, UndoRedo } from "@tiptap/extensions";
|
|
4
4
|
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|
5
|
+
import type { DocumentFrameControl } from "./document-frame-control.ts";
|
|
6
|
+
import { createFrameView, type FrameViewLabels } from "./document-frame-node-view.tsx";
|
|
7
|
+
import { DocumentPrintEditing, loadDocumentEditorFonts } from "./document-print-decorations.ts";
|
|
8
|
+
import { DocumentFrame } from "./document-print-style.ts";
|
|
9
|
+
import type { RepeatStripOptions } from "./document-repeat-strip.ts";
|
|
5
10
|
import {
|
|
6
11
|
DocumentButton,
|
|
7
12
|
DocumentImages,
|
|
8
13
|
DocumentPageBreak,
|
|
9
14
|
DocumentResource,
|
|
10
15
|
DocumentSteps,
|
|
16
|
+
DocumentTable,
|
|
11
17
|
DocumentVariable,
|
|
12
18
|
documentExtensions,
|
|
13
19
|
} from "./document-schema.ts";
|
|
14
20
|
import { readDocumentStepsAttribute } from "./document-steps.ts";
|
|
15
|
-
import type { DocumentResourcePreview } from "./document-toolbar-blocks.ts";
|
|
21
|
+
import type { DocumentPrintMode, DocumentResourcePreview } from "./document-toolbar-blocks.ts";
|
|
16
22
|
|
|
17
23
|
const DOCUMENT_RESOURCE_SIZE_TOKEN = "{size}";
|
|
18
24
|
export const DOCUMENT_BLOCK_ATTRIBUTE = "data-document-block";
|
|
@@ -31,6 +37,11 @@ export type DocumentEditorLabels = {
|
|
|
31
37
|
readonly resourcePreviews?: Readonly<Record<string, DocumentResourcePreview>>;
|
|
32
38
|
/** Canvas chrome labels every block with its type. */
|
|
33
39
|
readonly blockLabels?: boolean;
|
|
40
|
+
readonly print?: DocumentPrintMode;
|
|
41
|
+
/** Tag text per frame kind; frames render as movable boxes only with these. */
|
|
42
|
+
readonly frameLabels?: FrameViewLabels;
|
|
43
|
+
readonly reportFrameControl?: (control: DocumentFrameControl | null) => void;
|
|
44
|
+
readonly repeatStrip?: RepeatStripOptions;
|
|
34
45
|
};
|
|
35
46
|
|
|
36
47
|
function createElementWithClass<K extends keyof HTMLElementTagNameMap>(
|
|
@@ -44,7 +55,7 @@ function createElementWithClass<K extends keyof HTMLElementTagNameMap>(
|
|
|
44
55
|
return element;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
const CHIP_CLASS = "mx-0.5 inline-flex items-center gap-1 rounded border px-1.5
|
|
58
|
+
const CHIP_CLASS = "mx-0.5 inline-flex items-center gap-1 rounded border px-1.5 text-[0.9em]";
|
|
48
59
|
const USER_CHIP_CLASS = `${CHIP_CLASS} border-primary/30 bg-primary/10 text-primary`;
|
|
49
60
|
const SYSTEM_CHIP_CLASS = `${CHIP_CLASS} border-input bg-muted text-muted-foreground`;
|
|
50
61
|
|
|
@@ -252,6 +263,16 @@ export function createDocumentEditorExtensions(labels: DocumentEditorLabels): Ex
|
|
|
252
263
|
return DocumentSteps.extend({ addNodeView: () => createStepsView(labels) });
|
|
253
264
|
case DocumentImages.name:
|
|
254
265
|
return DocumentImages.extend({ addNodeView: () => createImagesView(labels) });
|
|
266
|
+
case DocumentTable.name:
|
|
267
|
+
return labels.print !== undefined && labels.print !== "none"
|
|
268
|
+
? DocumentTable.configure({ resizable: true })
|
|
269
|
+
: extension;
|
|
270
|
+
case DocumentFrame.name: {
|
|
271
|
+
const { frameLabels } = labels;
|
|
272
|
+
return frameLabels === undefined
|
|
273
|
+
? extension
|
|
274
|
+
: DocumentFrame.extend({ addNodeView: () => createFrameView(frameLabels) });
|
|
275
|
+
}
|
|
255
276
|
case DocumentPageBreak.name:
|
|
256
277
|
return DocumentPageBreak.extend({
|
|
257
278
|
addNodeView: () => createPageBreakView(labels.pageBreak),
|
|
@@ -260,9 +281,20 @@ export function createDocumentEditorExtensions(labels: DocumentEditorLabels): Ex
|
|
|
260
281
|
return extension;
|
|
261
282
|
}
|
|
262
283
|
});
|
|
284
|
+
const print = labels.print ?? "none";
|
|
285
|
+
if (print !== "none") void loadDocumentEditorFonts();
|
|
263
286
|
// No TrailingNode: it appends an empty paragraph that breaks the HTML roundtrip.
|
|
264
287
|
return [
|
|
265
288
|
...base,
|
|
289
|
+
...(print === "none"
|
|
290
|
+
? []
|
|
291
|
+
: [
|
|
292
|
+
DocumentPrintEditing.configure({
|
|
293
|
+
frames: print === "page",
|
|
294
|
+
reportFrameControl: labels.reportFrameControl ?? null,
|
|
295
|
+
repeatStrip: labels.repeatStrip ?? null,
|
|
296
|
+
}),
|
|
297
|
+
]),
|
|
266
298
|
UndoRedo,
|
|
267
299
|
Gapcursor,
|
|
268
300
|
Dropcursor,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference path="./fontsource-css.d.ts" />
|
|
2
|
+
// Loaded only through loadDocumentEditorFonts (a dynamic import), so the font CSS stays out of the
|
|
3
|
+
// main bundle and is evaluated once per session.
|
|
4
|
+
import "@fontsource/arimo/latin-400.css";
|
|
5
|
+
import "@fontsource/arimo/latin-700.css";
|
|
6
|
+
import "@fontsource/tinos/latin-400.css";
|
|
7
|
+
import "@fontsource/tinos/latin-700.css";
|
|
8
|
+
import "@fontsource/cousine/latin-400.css";
|
|
9
|
+
import "@fontsource/cousine/latin-700.css";
|
|
10
|
+
import "@fontsource/carlito/latin-400.css";
|
|
11
|
+
import "@fontsource/carlito/latin-700.css";
|
|
12
|
+
import "@fontsource/caladea/latin-400.css";
|
|
13
|
+
import "@fontsource/caladea/latin-700.css";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const DOCUMENT_FONTS = ["arial", "times", "courier", "calibri", "cambria"] as const;
|
|
2
|
+
export type DocumentFont = (typeof DOCUMENT_FONTS)[number];
|
|
3
|
+
|
|
4
|
+
export const DOCUMENT_FONT_LABELS: Readonly<Record<DocumentFont, string>> = {
|
|
5
|
+
arial: "Arial",
|
|
6
|
+
times: "Times New Roman",
|
|
7
|
+
courier: "Courier New",
|
|
8
|
+
calibri: "Calibri",
|
|
9
|
+
cambria: "Cambria",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// The first family is the metric-compatible font installed in the print service, so the PDF
|
|
13
|
+
// wraps lines like the Office font the author picked.
|
|
14
|
+
// Single quotes only: the stacks land in double-quoted style attributes, where a double quote ends the attribute.
|
|
15
|
+
export const DOCUMENT_FONT_PRINT_STACKS: Readonly<Record<DocumentFont, string>> = {
|
|
16
|
+
arial: "'Liberation Sans',Arial,sans-serif",
|
|
17
|
+
times: "'Liberation Serif','Times New Roman',serif",
|
|
18
|
+
courier: "'Liberation Mono','Courier New',monospace",
|
|
19
|
+
calibri: "Carlito,Calibri,sans-serif",
|
|
20
|
+
cambria: "Caladea,Cambria,serif",
|
|
21
|
+
};
|