@taprootio/site-authoring 0.62.0 → 0.64.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/README.md +63 -23
- package/package.json +2 -2
- package/src/api.js +149 -21
- package/src/appearance-contract.js +9 -0
- package/src/article-end-settings.js +295 -0
- package/src/changelog.json +39 -0
- package/src/chrome-input.js +1 -1
- package/src/cli.js +110 -26
- package/src/constants.js +7 -0
- package/src/content/components.js +130 -14
- package/src/content/cta-decoration-paint.js +321 -0
- package/src/content/form-placement-presentation.js +91 -0
- package/src/content/form-placement-presentation.json +6 -0
- package/src/content/free-form-section-registry.json +19 -1
- package/src/content/free-form-sections.js +64 -55
- package/src/content/markdown.js +13 -0
- package/src/content/tiptap-prosemirror.ts +72 -59
- package/src/content/validate-document.js +2 -0
- package/src/cta-artwork-warnings.js +164 -0
- package/src/errors.js +6 -0
- package/src/field-schema.json +6 -2
- package/src/field-validation.js +14 -5
- package/src/footer-workspace.js +7 -3
- package/src/form-references.js +71 -9
- package/src/forms-contract.js +3 -5
- package/src/heading-outline.js +7 -0
- package/src/output.js +2 -0
- package/src/page-article-end.js +66 -0
- package/src/page-block-catalog.js +54 -0
- package/src/page-form-presentation.js +104 -0
- package/src/page-structure-checks.js +7 -1
- package/src/placed-image-ids.js +15 -18
- package/src/presentation-reference.js +30 -52
- package/src/reference-help.js +97 -27
- package/src/reusable-blocks.js +429 -0
- package/src/reusable-placements.js +271 -0
- package/src/setting-reference.js +25 -1
- package/src/settings-catalog.js +1 -0
- package/src/site-check-findings.js +30 -2
- package/src/site-check-rules.json +1 -0
- package/src/site-checks.js +26 -2
- package/src/site-health-findings.js +25 -3
- package/src/site-health-image-checks.js +1 -1
- package/src/staging-check.js +108 -21
- package/src/staging-served.js +5 -49
- package/src/status-warning-paints.js +17 -0
- package/src/template-token-reach.json +14 -2
- package/src/theme-resolve.js +27 -0
- package/src/transport.js +41 -5
- package/src/typed-page-reference.js +55 -5
- package/src/typed-pages.js +27 -4
- package/src/verbs/approve.js +2 -1
- package/src/verbs/deploy.js +93 -15
- package/src/verbs/footer-push.js +4 -2
- package/src/verbs/forms-push.js +9 -0
- package/src/verbs/health.js +11 -6
- package/src/verbs/index.js +3 -0
- package/src/verbs/pages-blocks-pull.js +22 -0
- package/src/verbs/pages-push.js +89 -34
- package/src/verbs/plan.js +34 -5
- package/src/verbs/pull.js +213 -124
- package/src/verbs/status.js +20 -2
- package/src/verbs/theme-push.js +164 -14
- package/src/verbs/theme-resolve.js +114 -40
- package/src/verbs/validate.js +49 -18
- package/src/workspace-check.js +42 -5
- package/src/workspace-context-usage.js +54 -1
- package/src/workspace.js +37 -7
- package/test/fixtures/default-site-theme.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Generated from shared/form-placement-presentation.ts by scripts/sync-field-validation.mjs. Do not edit.
|
|
2
|
+
import { isSafeRootRelativeOrHttpsUrl } from "./cta-decoration-paint.js";
|
|
3
|
+
import limits from "./form-placement-presentation.json" with { type: "json" };
|
|
4
|
+
import registry from "./free-form-section-registry.json" with { type: "json" };
|
|
5
|
+
export const FORM_PLACEMENT_TEXT_LIMITS = Object.freeze(limits);
|
|
6
|
+
const contextPattern = new RegExp(registry.section.attrs.context.pattern, "u");
|
|
7
|
+
function isRecord(value) {
|
|
8
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function isContextName(value) {
|
|
11
|
+
return typeof value === "string" && value === value.trim() && contextPattern.test(value);
|
|
12
|
+
}
|
|
13
|
+
function isPlainText(value, maximum) {
|
|
14
|
+
if (typeof value !== "string" || /[\u0000\uD800-\uDFFF]/u.test(value) || /^\p{White_Space}*$/u.test(value)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
let length = 0;
|
|
18
|
+
for (const _ of value) {
|
|
19
|
+
if (++length > maximum)
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
export function isSafeFormPlacementLink(value) {
|
|
25
|
+
if (!isSafeRootRelativeOrHttpsUrl(value) || /[\u007F-\u009F\uD800-\uDFFF]/u.test(value))
|
|
26
|
+
return false;
|
|
27
|
+
return value.startsWith("/") || /^https:\/\/[^@/?#]+(?:[/?#]|$)/iu.test(value);
|
|
28
|
+
}
|
|
29
|
+
export function formPlacementPresentationIssues(value, contexts) {
|
|
30
|
+
if (!isRecord(value))
|
|
31
|
+
return [{ field: "presentation", message: "Enter form presentation fields as an object." }];
|
|
32
|
+
const issues = [];
|
|
33
|
+
checkText("heading", value.heading, limits.headingMaxScalars);
|
|
34
|
+
checkText("introduction", value.introduction, limits.introductionMaxScalars);
|
|
35
|
+
if (value.context != null && (!isContextName(value.context) || contexts && !contexts.has(value.context))) {
|
|
36
|
+
issues.push({ field: "context", message: "Choose a named theme context." });
|
|
37
|
+
}
|
|
38
|
+
if (value.finePrint != null) {
|
|
39
|
+
if (!isRecord(value.finePrint)
|
|
40
|
+
|| Object.keys(value.finePrint).some(key => !["text", "linkLabel", "linkUrl"].includes(key))) {
|
|
41
|
+
issues.push({ field: "finePrint", message: "Enter only supported fine print fields." });
|
|
42
|
+
return issues;
|
|
43
|
+
}
|
|
44
|
+
const { text, linkLabel, linkUrl } = value.finePrint;
|
|
45
|
+
checkText("finePrint.text", text, limits.finePrintTextMaxScalars);
|
|
46
|
+
checkText("finePrint.linkLabel", linkLabel, limits.finePrintLinkLabelMaxScalars);
|
|
47
|
+
if (linkUrl != null ? !isSafeFormPlacementLink(linkUrl) : linkLabel != null) {
|
|
48
|
+
issues.push({ field: "finePrint.linkUrl", message: "Enter a root-relative path or an HTTPS link." });
|
|
49
|
+
}
|
|
50
|
+
if (linkUrl != null && linkLabel == null) {
|
|
51
|
+
issues.push({ field: "finePrint.linkLabel", message: "Enter a link label." });
|
|
52
|
+
}
|
|
53
|
+
if (text == null && linkLabel == null && linkUrl == null) {
|
|
54
|
+
issues.push({ field: "finePrint", message: "Enter fine print or a link." });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return issues;
|
|
58
|
+
function checkText(field, text, maximum) {
|
|
59
|
+
if (text != null && !isPlainText(text, maximum)) {
|
|
60
|
+
issues.push({
|
|
61
|
+
field,
|
|
62
|
+
message: `Enter plain text of at most ${maximum} characters without unsupported characters.`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Resolve usable display values from a stored block, retaining text if a link is unusable. */
|
|
68
|
+
export function readFormPlacementPresentation(value) {
|
|
69
|
+
const resolved = {};
|
|
70
|
+
if (!isRecord(value))
|
|
71
|
+
return resolved;
|
|
72
|
+
if (isPlainText(value.heading, limits.headingMaxScalars))
|
|
73
|
+
resolved.heading = value.heading;
|
|
74
|
+
if (isPlainText(value.introduction, limits.introductionMaxScalars))
|
|
75
|
+
resolved.introduction = value.introduction;
|
|
76
|
+
if (isContextName(value.context))
|
|
77
|
+
resolved.context = value.context;
|
|
78
|
+
if (isRecord(value.finePrint)) {
|
|
79
|
+
const { text, linkLabel, linkUrl } = value.finePrint;
|
|
80
|
+
const finePrint = {};
|
|
81
|
+
if (isPlainText(text, limits.finePrintTextMaxScalars))
|
|
82
|
+
finePrint.text = text;
|
|
83
|
+
if (isPlainText(linkLabel, limits.finePrintLinkLabelMaxScalars) && isSafeFormPlacementLink(linkUrl)) {
|
|
84
|
+
finePrint.linkLabel = linkLabel;
|
|
85
|
+
finePrint.linkUrl = linkUrl;
|
|
86
|
+
}
|
|
87
|
+
if (Object.keys(finePrint).length > 0)
|
|
88
|
+
resolved.finePrint = finePrint;
|
|
89
|
+
}
|
|
90
|
+
return resolved;
|
|
91
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version":
|
|
2
|
+
"version": 19,
|
|
3
3
|
|
|
4
4
|
"imageDescription": {
|
|
5
5
|
"fields": {
|
|
@@ -49,6 +49,15 @@
|
|
|
49
49
|
"elevated"
|
|
50
50
|
]
|
|
51
51
|
},
|
|
52
|
+
"borderBlockStartWidth": {
|
|
53
|
+
"label": "Top border width",
|
|
54
|
+
"help": "Whole pixels from 0 to 20. The border uses the active theme context, and zero leaves it off.",
|
|
55
|
+
"type": "integer",
|
|
56
|
+
"required": false,
|
|
57
|
+
"default": 0,
|
|
58
|
+
"minimum": 0,
|
|
59
|
+
"maximum": 20
|
|
60
|
+
},
|
|
52
61
|
"entrance": {
|
|
53
62
|
"label": "Entrance",
|
|
54
63
|
"help": "Optional CSS-only reveal for the section content. Unsupported browsers render the content statically and reduced-motion preferences disable the effect.",
|
|
@@ -332,6 +341,15 @@
|
|
|
332
341
|
"repeat-y"
|
|
333
342
|
]
|
|
334
343
|
},
|
|
344
|
+
"sizeMode": {
|
|
345
|
+
"label": "Decoration size",
|
|
346
|
+
"help": "Use natural with a repeat keyword to keep the tile's intrinsic size. Leave both percentage sizes out.",
|
|
347
|
+
"type": "enum",
|
|
348
|
+
"required": false,
|
|
349
|
+
"values": [
|
|
350
|
+
"natural"
|
|
351
|
+
]
|
|
352
|
+
},
|
|
335
353
|
"opacity": {
|
|
336
354
|
"type": "number",
|
|
337
355
|
"required": false,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sharedDeclaredThemeContextNames } from "../theme-contexts.js";
|
|
2
2
|
import registry from "./free-form-section-registry.json" with { type: "json" };
|
|
3
|
+
import { isSafeDecorationUrl as decorationDeliveryUrlIsSafe } from "./cta-decoration-paint.js";
|
|
3
4
|
import { imageDescriptionIssues, pickImageDescriptionFields } from "./image-description-validation.js";
|
|
4
5
|
|
|
5
6
|
import {
|
|
@@ -20,6 +21,13 @@ function deepFreeze(value) {
|
|
|
20
21
|
|
|
21
22
|
export const FREE_FORM_SECTION_REGISTRY = deepFreeze(registry);
|
|
22
23
|
|
|
24
|
+
export function sectionBorderWidthProblem(value) {
|
|
25
|
+
const { minimum, maximum } = FREE_FORM_SECTION_REGISTRY.section.attrs.borderBlockStartWidth;
|
|
26
|
+
return value === undefined || (Number.isInteger(value) && value >= minimum && value <= maximum)
|
|
27
|
+
? null
|
|
28
|
+
: `an integer from ${minimum} through ${maximum}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
/**
|
|
24
32
|
* An image converted from a Markdown media path carries `"src": ""` and
|
|
25
33
|
* `"urls": []`, like body and component images: the API fills both from the
|
|
@@ -30,23 +38,6 @@ function isUnfilledDelivery(image) {
|
|
|
30
38
|
return image.src === "" && Array.isArray(image.urls) && image.urls.length === 0;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
function decorationDeliveryUrlIsSafe(value) {
|
|
34
|
-
if (typeof value !== "string" || value === "" || /[\u0000-\u0020\u007f]/u.test(value) || value.includes("\\")) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (value.startsWith("/")) return !value.startsWith("//");
|
|
38
|
-
if (!/^https:\/\//iu.test(value)) return false;
|
|
39
|
-
try {
|
|
40
|
-
const parsed = new URL(value);
|
|
41
|
-
return parsed.protocol === "https:"
|
|
42
|
-
&& parsed.hostname !== ""
|
|
43
|
-
&& parsed.username === ""
|
|
44
|
-
&& parsed.password === "";
|
|
45
|
-
} catch {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
41
|
function validateImageDescription(image, path, label, report) {
|
|
51
42
|
for (const issue of imageDescriptionIssues(image)) {
|
|
52
43
|
report(`${path}/${issue.field}`, CODES.attrInvalid, `${label} ${issue.field} must ${issue.expected}.`);
|
|
@@ -470,11 +461,54 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
470
461
|
validateImageDescription(image, imagePath, "Section decoration image", report);
|
|
471
462
|
}
|
|
472
463
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
464
|
+
const usesNaturalSize = validateSectionDecorationOptions(value, fields, path, report);
|
|
465
|
+
|
|
466
|
+
if (errors.length > 0 || !isPlainObject(image)) return finish(undefined);
|
|
467
|
+
const normalizedImage = {
|
|
468
|
+
imageId: image.imageId,
|
|
469
|
+
src: image.src,
|
|
470
|
+
urls: Object.freeze(image.urls.map((option) => Object.freeze({
|
|
471
|
+
minWidth: option.minWidth,
|
|
472
|
+
url: option.url,
|
|
473
|
+
...(option.type === undefined ? {} : { type: option.type }),
|
|
474
|
+
}))),
|
|
475
|
+
...(Object.hasOwn(image, "width") ? { width: image.width } : {}),
|
|
476
|
+
...(Object.hasOwn(image, "height") ? { height: image.height } : {}),
|
|
477
|
+
...(Object.hasOwn(image, "alt") ? { alt: image.alt } : {}),
|
|
478
|
+
...pickImageDescriptionFields(image),
|
|
479
|
+
};
|
|
480
|
+
const normalized = { image: Object.freeze(normalizedImage) };
|
|
481
|
+
for (const [name, definition] of Object.entries(fields)) {
|
|
482
|
+
if (name === "image") continue;
|
|
483
|
+
// A field with no default stays absent. The width default applies only without a height size
|
|
484
|
+
// or natural sizing (TR01416, TR01454).
|
|
485
|
+
const fallback = name === "inlineSizePercent" && (Object.hasOwn(value, "blockSizePercent") || usesNaturalSize)
|
|
486
|
+
? undefined
|
|
487
|
+
: definition.default;
|
|
488
|
+
const resolved = value[name] ?? fallback;
|
|
489
|
+
if (resolved !== undefined) normalized[name] = resolved;
|
|
490
|
+
}
|
|
491
|
+
return finish(Object.freeze(normalized));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** The Section paint fields also apply when a settings document stores only the image identity. */
|
|
495
|
+
export function sectionDecorationOptionProblems(value, path) {
|
|
496
|
+
const errors = [];
|
|
497
|
+
const report = (errorPath, code, message) => errors.push(contentError(errorPath, code, message));
|
|
498
|
+
validateSectionDecorationOptions(value, FREE_FORM_SECTION_REGISTRY.section.attrs.decoration.fields, path, report);
|
|
499
|
+
return errors;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function validateSectionDecorationOptions(value, fields, path, report) {
|
|
503
|
+
const naturalSize = value.sizeMode === "natural";
|
|
504
|
+
if (naturalSize && !fields.repeat.values.includes(value.repeat)) {
|
|
505
|
+
report(`${path}/sizeMode`, CODES.attrInvalid, "Section decoration natural size requires a repeat keyword.");
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Two-axis repeat uses natural sizing even when the mode is omitted (TR01416).
|
|
509
|
+
const usesNaturalSize = naturalSize || value.repeat === "repeat";
|
|
476
510
|
// TR01329: width and height sizes are exclusive, so one conflict replaces both range checks.
|
|
477
|
-
const sizeConflict = !
|
|
511
|
+
const sizeConflict = !usesNaturalSize && Object.hasOwn(value, "inlineSizePercent") && Object.hasOwn(value, "blockSizePercent");
|
|
478
512
|
if (sizeConflict) {
|
|
479
513
|
report(
|
|
480
514
|
`${path}/blockSizePercent`,
|
|
@@ -483,20 +517,21 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
483
517
|
);
|
|
484
518
|
}
|
|
485
519
|
|
|
486
|
-
if (
|
|
520
|
+
if (usesNaturalSize) {
|
|
521
|
+
const setting = naturalSize ? 'sizeMode "natural"' : 'repeat "repeat"';
|
|
487
522
|
for (const name of ["inlineSizePercent", "blockSizePercent"]) {
|
|
488
523
|
if (!Object.hasOwn(value, name)) continue;
|
|
489
524
|
report(
|
|
490
525
|
`${path}/${name}`,
|
|
491
526
|
CODES.attrInvalid,
|
|
492
|
-
`Section decoration ${name} cannot be combined with
|
|
527
|
+
`Section decoration ${name} cannot be combined with ${setting}. A repeating decoration tiles at the image's natural size, so leave the size out.`,
|
|
493
528
|
);
|
|
494
529
|
}
|
|
495
530
|
}
|
|
496
531
|
|
|
497
532
|
for (const [name, definition] of Object.entries(fields)) {
|
|
498
533
|
if (name === "image" || !Object.hasOwn(value, name)) continue;
|
|
499
|
-
if ((sizeConflict ||
|
|
534
|
+
if ((sizeConflict || usesNaturalSize) && (name === "inlineSizePercent" || name === "blockSizePercent")) continue;
|
|
500
535
|
const fieldPath = `${path}/${name}`;
|
|
501
536
|
const entry = value[name];
|
|
502
537
|
if (definition.type === "boolean") {
|
|
@@ -528,32 +563,7 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
528
563
|
}
|
|
529
564
|
}
|
|
530
565
|
|
|
531
|
-
|
|
532
|
-
const normalizedImage = {
|
|
533
|
-
imageId: image.imageId,
|
|
534
|
-
src: image.src,
|
|
535
|
-
urls: Object.freeze(image.urls.map((option) => Object.freeze({
|
|
536
|
-
minWidth: option.minWidth,
|
|
537
|
-
url: option.url,
|
|
538
|
-
...(option.type === undefined ? {} : { type: option.type }),
|
|
539
|
-
}))),
|
|
540
|
-
...(Object.hasOwn(image, "width") ? { width: image.width } : {}),
|
|
541
|
-
...(Object.hasOwn(image, "height") ? { height: image.height } : {}),
|
|
542
|
-
...(Object.hasOwn(image, "alt") ? { alt: image.alt } : {}),
|
|
543
|
-
...pickImageDescriptionFields(image),
|
|
544
|
-
};
|
|
545
|
-
const normalized = { image: Object.freeze(normalizedImage) };
|
|
546
|
-
for (const [name, definition] of Object.entries(fields)) {
|
|
547
|
-
if (name === "image") continue;
|
|
548
|
-
// A field with no default stays absent. The width default applies only without a height size
|
|
549
|
-
// or a tile (TR01416).
|
|
550
|
-
const fallback = name === "inlineSizePercent" && (Object.hasOwn(value, "blockSizePercent") || tiling)
|
|
551
|
-
? undefined
|
|
552
|
-
: definition.default;
|
|
553
|
-
const resolved = value[name] ?? fallback;
|
|
554
|
-
if (resolved !== undefined) normalized[name] = resolved;
|
|
555
|
-
}
|
|
556
|
-
return finish(Object.freeze(normalized));
|
|
566
|
+
return usesNaturalSize;
|
|
557
567
|
}
|
|
558
568
|
|
|
559
569
|
/** The exact, sorted context names present in both staged site themes. */
|
|
@@ -577,8 +587,7 @@ export function freeFormRootPresentation(node, source = FREE_FORM_SECTION_REGIST
|
|
|
577
587
|
}
|
|
578
588
|
|
|
579
589
|
/**
|
|
580
|
-
* The theme context a
|
|
581
|
-
* to action's `context` field inside its `componentData` JSON string (TR01413).
|
|
590
|
+
* The theme context a Section, CTA or Form names in its authored data.
|
|
582
591
|
* Returns the field's location relative to the node, or undefined.
|
|
583
592
|
*/
|
|
584
593
|
export function namedContext(node, source = FREE_FORM_SECTION_REGISTRY) {
|
|
@@ -588,7 +597,7 @@ export function namedContext(node, source = FREE_FORM_SECTION_REGISTRY) {
|
|
|
588
597
|
? { context: node.attrs.context, field: "/attrs/context" }
|
|
589
598
|
: undefined;
|
|
590
599
|
}
|
|
591
|
-
if (node.type !== "componentBlock" || node.attrs.componentType
|
|
600
|
+
if (node.type !== "componentBlock" || !["cta", "form"].includes(node.attrs.componentType)) return undefined;
|
|
592
601
|
if (typeof node.attrs.componentData !== "string") return undefined;
|
|
593
602
|
let data;
|
|
594
603
|
try {
|
|
@@ -597,7 +606,7 @@ export function namedContext(node, source = FREE_FORM_SECTION_REGISTRY) {
|
|
|
597
606
|
return undefined;
|
|
598
607
|
}
|
|
599
608
|
return isPlainObject(data) && typeof data.context === "string"
|
|
600
|
-
? { context: data.context, field: "/attrs/componentData" }
|
|
609
|
+
? { context: data.context, field: node.attrs.componentType === "form" ? "/attrs/componentData/context" : "/attrs/componentData" }
|
|
601
610
|
: undefined;
|
|
602
611
|
}
|
|
603
612
|
|
|
@@ -644,7 +653,7 @@ export function validateFreeFormSectionContexts(
|
|
|
644
653
|
if (named) {
|
|
645
654
|
const { context } = named;
|
|
646
655
|
if (!allowed.has(context)) {
|
|
647
|
-
const owner = node.type === source.section.nodeType ? "Section" : "Call to action";
|
|
656
|
+
const owner = node.type === source.section.nodeType ? "Section" : node.attrs.componentType === "form" ? "Form" : "Call to action";
|
|
648
657
|
errors.push(contentError(
|
|
649
658
|
`${path}${named.field}`,
|
|
650
659
|
CODES.sectionContextUnknown,
|
package/src/content/markdown.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
FREE_FORM_SECTION_REGISTRY,
|
|
14
14
|
normalizeFreeFormSectionBackground,
|
|
15
15
|
normalizeFreeFormSectionDecoration,
|
|
16
|
+
sectionBorderWidthProblem,
|
|
16
17
|
} from "./free-form-sections.js";
|
|
17
18
|
import { columnsAttributes, isColumnEligibleBlock, normalizeColumnsBody, validateColumnsBody } from "./free-form-columns.js";
|
|
18
19
|
import { normalizeInlineFactsItems } from "./inline-facts.js";
|
|
@@ -796,6 +797,17 @@ async function sectionHeaderAttrs(text, line, markdownContext) {
|
|
|
796
797
|
}
|
|
797
798
|
}
|
|
798
799
|
|
|
800
|
+
const borderBlockStartWidth = parsed.borderBlockStartWidth;
|
|
801
|
+
const borderWidthProblem = sectionBorderWidthProblem(borderBlockStartWidth);
|
|
802
|
+
if (borderWidthProblem !== null) {
|
|
803
|
+
throw fail(
|
|
804
|
+
CODES.attrInvalid,
|
|
805
|
+
"/attrs/borderBlockStartWidth",
|
|
806
|
+
`Section top border width must be ${borderWidthProblem}.`,
|
|
807
|
+
line.number,
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
|
|
799
811
|
const recover = markdownContext.sectionProblems;
|
|
800
812
|
const failedImages = new Set();
|
|
801
813
|
for (const [owner, field] of [["decoration", "image"], ["background", "image"], ["background", "portraitImage"]]) {
|
|
@@ -847,6 +859,7 @@ async function sectionHeaderAttrs(text, line, markdownContext) {
|
|
|
847
859
|
...(typeof context === "string" ? { context } : {}),
|
|
848
860
|
contentPadding: parsed.contentPadding ?? definitions.contentPadding.default,
|
|
849
861
|
surface: parsed.surface ?? definitions.surface.default,
|
|
862
|
+
...(borderBlockStartWidth === undefined ? {} : { borderBlockStartWidth }),
|
|
850
863
|
...(parsed.entrance === undefined ? {} : { entrance: parsed.entrance }),
|
|
851
864
|
...(parsed.entranceStagger === undefined ? {} : { entranceStagger: parsed.entranceStagger }),
|
|
852
865
|
...(normalizedBackground.background ? { background: normalizedBackground.background } : {}),
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { blockquoteCaptionParts, readBlockquoteMetadata } from "./blockquote-metadata.js";
|
|
11
|
+
import {
|
|
12
|
+
decorationPosition,
|
|
13
|
+
escapeCssString,
|
|
14
|
+
isSafeDecorationUrl as isSafeSectionImageUrl,
|
|
15
|
+
} from "./cta-decoration-paint.js";
|
|
11
16
|
import { columnsAttributes, isColumnEligibleBlock } from "./free-form-columns.js";
|
|
12
17
|
import freeFormSectionRegistry from "./free-form-section-registry.json" with { type: "json" };
|
|
13
18
|
import { imageDescriptionIssues } from "./image-description-validation.js";
|
|
@@ -90,9 +95,12 @@ export interface RenderProseMirrorOptions {
|
|
|
90
95
|
maxHeightVh?: TiptapImageMaxHeightVh | number | null;
|
|
91
96
|
};
|
|
92
97
|
headingSpacing?: { imagePlacement: unknown };
|
|
98
|
+
/** The published shell makes the preformatted region scroll and keeps its action in view. */
|
|
99
|
+
codeScrollRegion?: boolean;
|
|
93
100
|
/** Generator-only render hooks for structured nodes that need page context. */
|
|
94
101
|
nodeRenderers?: {
|
|
95
102
|
componentBlock?: (node: ProseMirrorNode, headingFlow: boolean) => string | undefined;
|
|
103
|
+
codeBlockDecoration?: (node: ProseMirrorNode) => string;
|
|
96
104
|
taprootImage?: (
|
|
97
105
|
node: ProseMirrorNode,
|
|
98
106
|
context: { groupColumns?: number; fullWidth: boolean },
|
|
@@ -502,9 +510,19 @@ function renderCodeBlock(node: ProseMirrorNode, options: RenderProseMirrorOption
|
|
|
502
510
|
const text = (node.content ?? [])
|
|
503
511
|
.map((child) => child.text ?? "")
|
|
504
512
|
.join("");
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
513
|
+
const preAttributes = withProseMeasure(
|
|
514
|
+
{
|
|
515
|
+
...headingNeighborAttrs("code", headingFlow),
|
|
516
|
+
...(options.codeScrollRegion
|
|
517
|
+
? { "data-code-scroll": "", role: "region", "aria-label": "Code block", tabindex: "0" }
|
|
518
|
+
: {}),
|
|
519
|
+
},
|
|
520
|
+
node.type,
|
|
521
|
+
options,
|
|
522
|
+
);
|
|
523
|
+
return `<pre${serializeAttributes(preAttributes)}><code${serializeAttributes(attrs)}>${escapeHtml(text)}</code>${
|
|
524
|
+
options.nodeRenderers?.codeBlockDecoration?.(node) ?? ""
|
|
525
|
+
}</pre>`;
|
|
508
526
|
}
|
|
509
527
|
|
|
510
528
|
type NormalizedTable = {
|
|
@@ -875,6 +893,19 @@ function renderSection(
|
|
|
875
893
|
? contextValue
|
|
876
894
|
: undefined;
|
|
877
895
|
const sectionStyleParts: string[] = [];
|
|
896
|
+
const borderWidth = attrs.borderBlockStartWidth;
|
|
897
|
+
if (
|
|
898
|
+
kind === "explicit"
|
|
899
|
+
&& isBoundedNumber(
|
|
900
|
+
borderWidth,
|
|
901
|
+
definitions.borderBlockStartWidth.minimum,
|
|
902
|
+
definitions.borderBlockStartWidth.maximum,
|
|
903
|
+
)
|
|
904
|
+
&& Number.isInteger(borderWidth)
|
|
905
|
+
&& borderWidth > 0
|
|
906
|
+
) {
|
|
907
|
+
sectionStyleParts.push(`border-block-start: ${borderWidth}px solid var(--esp-color-border)`);
|
|
908
|
+
}
|
|
878
909
|
if (contentPadding === "none") {
|
|
879
910
|
sectionStyleParts.push(
|
|
880
911
|
"--esp-section-max-width: none",
|
|
@@ -1146,21 +1177,6 @@ function sectionImageSrcset(image: NormalizedSectionImage): string {
|
|
|
1146
1177
|
return image.urls.map((candidate) => `${candidate.url} ${candidate.minWidth}w`).join(", ");
|
|
1147
1178
|
}
|
|
1148
1179
|
|
|
1149
|
-
function isSafeSectionImageUrl(value: string): boolean {
|
|
1150
|
-
if (value === "" || /[\u0000-\u0020\u007f]/u.test(value) || value.includes("\\")) return false;
|
|
1151
|
-
if (value.startsWith("/")) return !value.startsWith("//");
|
|
1152
|
-
if (!/^https:\/\//iu.test(value)) return false;
|
|
1153
|
-
try {
|
|
1154
|
-
const parsed = new URL(value);
|
|
1155
|
-
return parsed.protocol === "https:"
|
|
1156
|
-
&& parsed.hostname !== ""
|
|
1157
|
-
&& parsed.username === ""
|
|
1158
|
-
&& parsed.password === "";
|
|
1159
|
-
} catch {
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
1180
|
type NormalizedSectionDecoration = {
|
|
1165
1181
|
imageUrl: string;
|
|
1166
1182
|
anchor: string;
|
|
@@ -1178,7 +1194,9 @@ function normalizedSectionDecorationStyle(value: unknown): string[] | undefined
|
|
|
1178
1194
|
return [
|
|
1179
1195
|
`--esp-section-decoration-image: url("${escapeCssString(decoration.imageUrl)}")`,
|
|
1180
1196
|
`--esp-section-decoration-color: var(${decoration.tintToken})`,
|
|
1181
|
-
`--esp-section-decoration-position: ${
|
|
1197
|
+
`--esp-section-decoration-position: ${
|
|
1198
|
+
decorationPosition(decoration.anchor, decoration.inlineOffsetPercent, decoration.blockOffsetPercent)
|
|
1199
|
+
}`,
|
|
1182
1200
|
`--esp-section-decoration-size: ${decoration.size}`,
|
|
1183
1201
|
// Espalier's default is no-repeat, so only a tiling decoration emits the hook (TR01416, TR01421).
|
|
1184
1202
|
...(decoration.repeat ? [`--esp-section-decoration-repeat: ${decoration.repeat}`] : []),
|
|
@@ -1206,15 +1224,15 @@ function normalizeSectionDecoration(value: unknown): NormalizedSectionDecoration
|
|
|
1206
1224
|
// TR01329: width and height sizes are exclusive. Read the raw keys, because
|
|
1207
1225
|
// the width default is filled in below.
|
|
1208
1226
|
if (value.inlineSizePercent !== undefined && value.blockSizePercent !== undefined) return undefined;
|
|
1209
|
-
// TR01416: a `repeat` tile keeps the image's natural size, so a size beside it is a conflict. A one-axis tile
|
|
1210
|
-
// (`repeat-x`, `repeat-y`) takes a size like any decoration (TR01421).
|
|
1211
1227
|
if (
|
|
1212
1228
|
value.repeat !== undefined
|
|
1213
1229
|
&& (typeof value.repeat !== "string" || !(fields.repeat.values as readonly string[]).includes(value.repeat))
|
|
1214
1230
|
) return undefined;
|
|
1215
1231
|
const repeatKeyword = value.repeat as string | undefined;
|
|
1216
|
-
|
|
1217
|
-
|
|
1232
|
+
if (value.sizeMode !== undefined && (value.sizeMode !== "natural" || repeatKeyword === undefined)) return undefined;
|
|
1233
|
+
// Two-axis repeat has always used the image's natural size.
|
|
1234
|
+
const naturalSize = repeatKeyword === "repeat" || value.sizeMode === "natural";
|
|
1235
|
+
if (naturalSize && (value.inlineSizePercent !== undefined || value.blockSizePercent !== undefined)) return undefined;
|
|
1218
1236
|
const blockSizePercent = value.blockSizePercent;
|
|
1219
1237
|
const inlineSizePercent = value.inlineSizePercent ?? fields.inlineSizePercent.default;
|
|
1220
1238
|
const opacity = value.opacity ?? fields.opacity.default;
|
|
@@ -1227,7 +1245,7 @@ function normalizeSectionDecoration(value: unknown): NormalizedSectionDecoration
|
|
|
1227
1245
|
return undefined;
|
|
1228
1246
|
}
|
|
1229
1247
|
// A tile has no size to check: it paints at the image's natural size.
|
|
1230
|
-
if (!
|
|
1248
|
+
if (!naturalSize) {
|
|
1231
1249
|
if (blockSizePercent !== undefined) {
|
|
1232
1250
|
if (
|
|
1233
1251
|
!isBoundedNumber(blockSizePercent, fields.blockSizePercent.minimum, fields.blockSizePercent.maximum)
|
|
@@ -1248,46 +1266,17 @@ function normalizeSectionDecoration(value: unknown): NormalizedSectionDecoration
|
|
|
1248
1266
|
anchor,
|
|
1249
1267
|
inlineOffsetPercent,
|
|
1250
1268
|
blockOffsetPercent,
|
|
1251
|
-
size:
|
|
1269
|
+
size: naturalSize
|
|
1270
|
+
? "auto"
|
|
1271
|
+
: blockSizePercent !== undefined
|
|
1272
|
+
? `auto ${blockSizePercent}%`
|
|
1273
|
+
: `${inlineSizePercent}% auto`,
|
|
1252
1274
|
repeat: repeatKeyword,
|
|
1253
1275
|
opacity,
|
|
1254
1276
|
tintToken,
|
|
1255
1277
|
};
|
|
1256
1278
|
}
|
|
1257
1279
|
|
|
1258
|
-
function sectionDecorationPosition(decoration: NormalizedSectionDecoration): string {
|
|
1259
|
-
const [inlineBase, blockBase] = (() => {
|
|
1260
|
-
switch (decoration.anchor) {
|
|
1261
|
-
case "top-start":
|
|
1262
|
-
return [0, 0];
|
|
1263
|
-
case "top-end":
|
|
1264
|
-
return [100, 0];
|
|
1265
|
-
case "bottom-start":
|
|
1266
|
-
return [0, 100];
|
|
1267
|
-
case "bottom-end":
|
|
1268
|
-
return [100, 100];
|
|
1269
|
-
case "center":
|
|
1270
|
-
default:
|
|
1271
|
-
return [50, 50];
|
|
1272
|
-
}
|
|
1273
|
-
})();
|
|
1274
|
-
return `${positionAxis(inlineBase, decoration.inlineOffsetPercent)} ${
|
|
1275
|
-
positionAxis(blockBase, decoration.blockOffsetPercent)
|
|
1276
|
-
}`;
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
function positionAxis(base: number, offset: number): string {
|
|
1280
|
-
if (offset === 0) return `${base}%`;
|
|
1281
|
-
return `calc(${base}% ${offset < 0 ? "-" : "+"} ${Math.abs(offset)}%)`;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
function escapeCssString(value: string): string {
|
|
1285
|
-
return value.replace(/(["\\])/gu, "\\$1").replace(
|
|
1286
|
-
/[\u0000-\u001f\u007f]/gu,
|
|
1287
|
-
(character) => `\\${character.codePointAt(0)?.toString(16)} `,
|
|
1288
|
-
);
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
1280
|
function hasOnlyKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {
|
|
1292
1281
|
return Object.keys(value).every((key) => keys.includes(key));
|
|
1293
1282
|
}
|
|
@@ -1309,9 +1298,33 @@ function isBoundedNumber(value: unknown, minimum: number, maximum: number): valu
|
|
|
1309
1298
|
return typeof value === "number" && Number.isFinite(value) && value >= minimum && value <= maximum;
|
|
1310
1299
|
}
|
|
1311
1300
|
|
|
1301
|
+
/** A reusable reference carries only its key. The type continues to name its renderer. */
|
|
1302
|
+
export function reusableReferenceKey(type: unknown, source: unknown): string | undefined {
|
|
1303
|
+
if (type !== "cta" && type !== "form") return;
|
|
1304
|
+
let data = source;
|
|
1305
|
+
if (typeof source === "string") {
|
|
1306
|
+
try {
|
|
1307
|
+
data = JSON.parse(source);
|
|
1308
|
+
} catch {
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (!isRecord(data) || !hasOnlyKeys(data, ["reusableKey"])) return;
|
|
1313
|
+
const key = data.reusableKey;
|
|
1314
|
+
return typeof key === "string" && key.length <= 64 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(key) ? key : undefined;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
export function componentRenderData(componentType: string, raw: unknown): string {
|
|
1318
|
+
if (typeof raw === "string") return raw || "{}";
|
|
1319
|
+
if (isRecord(raw) && (componentType === "cta" || reusableReferenceKey(componentType, raw))) {
|
|
1320
|
+
return JSON.stringify(raw);
|
|
1321
|
+
}
|
|
1322
|
+
return "{}";
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1312
1325
|
function renderComponentBlock(node: ProseMirrorNode, headingFlow: boolean): string {
|
|
1313
1326
|
const componentType = stringAttr(node.attrs?.componentType) || "placeholder";
|
|
1314
|
-
const componentData =
|
|
1327
|
+
const componentData = componentRenderData(componentType, node.attrs?.componentData);
|
|
1315
1328
|
return renderElement(
|
|
1316
1329
|
"div",
|
|
1317
1330
|
{
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
FREE_FORM_SECTION_REGISTRY,
|
|
7
7
|
normalizeFreeFormSectionBackground,
|
|
8
8
|
normalizeFreeFormSectionDecoration,
|
|
9
|
+
sectionBorderWidthProblem,
|
|
9
10
|
} from "./free-form-sections.js";
|
|
10
11
|
import { normalizeInlineFactsItems } from "./inline-facts.js";
|
|
11
12
|
import {
|
|
@@ -236,6 +237,7 @@ const SECTION_ATTRS = Object.freeze({
|
|
|
236
237
|
}),
|
|
237
238
|
contentPadding: optionalEnum(FREE_FORM_SECTION_REGISTRY.section.attrs.contentPadding.values),
|
|
238
239
|
surface: optionalEnum(FREE_FORM_SECTION_REGISTRY.section.attrs.surface.values),
|
|
240
|
+
borderBlockStartWidth: spec(sectionBorderWidthProblem),
|
|
239
241
|
entrance: optionalEnum(FREE_FORM_SECTION_REGISTRY.section.attrs.entrance.values),
|
|
240
242
|
entranceStagger: optionalEnum(FREE_FORM_SECTION_REGISTRY.section.attrs.entranceStagger.values),
|
|
241
243
|
// Nested field diagnostics are owned by
|