@taprootio/site-authoring 0.56.0 → 0.59.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 +13 -11
- package/package.json +2 -2
- package/src/api.js +7 -0
- package/src/block-flow.js +4 -2
- package/src/changelog.json +87 -0
- package/src/chrome-additions.js +106 -0
- package/src/chrome-features.js +43 -10
- package/src/chrome-input.js +137 -30
- package/src/chrome-report.js +4 -2
- package/src/cli.js +54 -17
- package/src/content/button-styles.js +27 -0
- package/src/content/components.js +76 -10
- package/src/content/free-form-section-registry.json +9 -0
- package/src/content/free-form-sections.js +55 -16
- package/src/content/markdown.js +133 -56
- package/src/content/media-presentation.js +37 -0
- package/src/content/tiptap-prosemirror.ts +26 -10
- package/src/credentials.js +2 -1
- package/src/delivery-check.js +10 -2
- package/src/font-catalog.js +9 -6
- package/src/footer-content.js +1 -1
- package/src/footer-contract.js +3 -0
- package/src/footer-draft-hash.js +1 -0
- package/src/heading-outline.js +94 -6
- package/src/image-description-contract.js +5 -3
- package/src/image-description-write.js +26 -0
- package/src/index.js +1 -0
- package/src/output.js +2 -1
- package/src/page-structure-checks.js +14 -25
- package/src/placed-image-ids.js +42 -17
- package/src/presentation-reference.js +63 -18
- package/src/problems.js +147 -4
- package/src/reference-help.js +102 -57
- package/src/site-check-findings.js +2 -3
- package/src/site-check-rules.json +0 -1
- package/src/site-health-findings.js +7 -9
- package/src/site-health-image-checks.js +4 -1
- package/src/site-health-precheck.js +23 -6
- package/src/site-navigation-groups.js +16 -0
- package/src/status-warning-paints.js +175 -0
- package/src/template-token-reach.json +13 -18
- package/src/theme-proposals.js +143 -55
- package/src/theme-resolve.js +14 -1
- package/src/theme-validation.js +70 -38
- package/src/token-reach.js +20 -0
- package/src/typed-page-reference.js +3 -2
- package/src/typed-pages.js +7 -7
- package/src/verbs/changelog.js +23 -2
- package/src/verbs/delivery-check.js +43 -9
- package/src/verbs/media-images.js +4 -4
- package/src/verbs/pages-push.js +38 -32
- package/src/verbs/plan.js +28 -20
- package/src/verbs/pull.js +179 -24
- package/src/verbs/theme-push.js +59 -15
- package/src/verbs/theme-resolve.js +109 -11
- package/src/verbs/validate.js +97 -16
- package/src/workspace-check.js +4 -4
- package/src/workspace-context-usage.js +180 -0
- package/src/workspace.js +12 -0
- package/test/fixtures/default-site-theme.json +1 -1
|
@@ -21,6 +21,12 @@ import {
|
|
|
21
21
|
isUuid,
|
|
22
22
|
pointerSegment,
|
|
23
23
|
} from "./vocabulary.js";
|
|
24
|
+
import {
|
|
25
|
+
BUTTON_STYLE_DESCRIPTIONS,
|
|
26
|
+
CTA_BUTTON_STYLE_DEFAULT,
|
|
27
|
+
HERO_PRIMARY_ACTION_STYLE_DEFAULT,
|
|
28
|
+
HERO_SECONDARY_ACTION_STYLE_DEFAULT,
|
|
29
|
+
} from "./button-styles.js";
|
|
24
30
|
import { normalizeCssLengthOverride } from "./media-presentation.js";
|
|
25
31
|
import { isVideoEmbedId, parseVideoEmbedUrl, VIDEO_EMBED_REFUSAL } from "./video-embed-url.js";
|
|
26
32
|
import {
|
|
@@ -92,10 +98,18 @@ const safeUrl = (options = {}) =>
|
|
|
92
98
|
Object.freeze({ kind: "safe-url", ...(options.https ? { required: true, allowEmpty: false } : {}), ...options });
|
|
93
99
|
/** A CSS length the published renderer accepts as a per-block override; `allowNone` adds `none` (a max height). */
|
|
94
100
|
const cssLength = (options = {}) => Object.freeze({ kind: "css-length", ...options });
|
|
101
|
+
// A border width: CSS takes no percentage there.
|
|
102
|
+
const borderLength = (options = {}) => cssLength({ ...options, percent: false });
|
|
95
103
|
const textureName = () => Object.freeze({ kind: "texture-name", maximumLength: 64 });
|
|
96
104
|
const withOmission = (spec, whenOmitted) => Object.freeze({ ...spec, whenOmitted: Object.freeze(whenOmitted) });
|
|
97
105
|
/** The same spec with a description `help component` prints beside its constraints. */
|
|
98
106
|
const described = (spec, description) => Object.freeze({ ...spec, description });
|
|
107
|
+
/**
|
|
108
|
+
* An enum whose values each carry a sentence; `help component` prints one per
|
|
109
|
+
* value beside the constraints (TR01414). `descriptions` maps every value.
|
|
110
|
+
*/
|
|
111
|
+
const describedEnum = (descriptions) =>
|
|
112
|
+
Object.freeze({ ...enumOf(...Object.keys(descriptions)), valueDescriptions: Object.freeze({ ...descriptions }) });
|
|
99
113
|
|
|
100
114
|
/**
|
|
101
115
|
* `ComponentImageData`. `src` and `urls` are the only required-by-key fields
|
|
@@ -148,19 +162,40 @@ const HERO_ACTION = shape({
|
|
|
148
162
|
url: safeUrl({ required: true, allowEmpty: false }),
|
|
149
163
|
});
|
|
150
164
|
|
|
165
|
+
/** Help for a hero or call-to-action image frame; the same override the image and video blocks take. */
|
|
166
|
+
const MEDIA_BORDER_HELP =
|
|
167
|
+
"Leave mediaBorderWidth out to follow the site's image border; set it (such as 4px, or 0 for no border) to frame this image differently. It has the same meaning as borderWidth on an image block.";
|
|
168
|
+
|
|
169
|
+
/** The button look's values with the one an absent option renders marked as the default. */
|
|
170
|
+
const buttonStyleValues = (defaultStyle) =>
|
|
171
|
+
describedEnum(Object.fromEntries(Object.entries(BUTTON_STYLE_DESCRIPTIONS).map(([style, description]) =>
|
|
172
|
+
[style, style === defaultStyle ? `${description} This is the default, and it writes no attribute in the delivered HTML, so the HTML shows a style only when it differs from the default.` : description]
|
|
173
|
+
)));
|
|
174
|
+
|
|
151
175
|
/** The pre-adoption `HeroSectionData` replacement. */
|
|
152
176
|
const HERO_SECTION = Object.freeze({
|
|
153
177
|
overline: str(),
|
|
154
178
|
title: str({ required: true, nonWhitespace: true }),
|
|
155
|
-
titleSize:
|
|
179
|
+
titleSize: describedEnum({
|
|
180
|
+
normal: "The heading size (the theme's huge type step).",
|
|
181
|
+
compact: "A smaller title (the theme's large type step), so the next section can sit nearer the fold.",
|
|
182
|
+
display: "The theme's display type recipe, a larger title.",
|
|
183
|
+
}),
|
|
156
184
|
lead: str(),
|
|
185
|
+
leadSize: describedEnum({
|
|
186
|
+
normal: "The theme's lead size (its medium type step).",
|
|
187
|
+
compact: "Body-sized lead copy (the theme's normal type step).",
|
|
188
|
+
}),
|
|
157
189
|
primaryAction: Object.freeze({ ...HERO_ACTION, required: true }),
|
|
190
|
+
primaryActionStyle: buttonStyleValues(HERO_PRIMARY_ACTION_STYLE_DEFAULT),
|
|
158
191
|
secondaryAction: Object.freeze({ ...HERO_ACTION, nullable: true }),
|
|
192
|
+
secondaryActionStyle: buttonStyleValues(HERO_SECONDARY_ACTION_STYLE_DEFAULT),
|
|
159
193
|
alignment: enumOf("start", "center"),
|
|
160
194
|
media: image(),
|
|
161
195
|
mediaArrangement: enumOf("split", "stacked"),
|
|
162
196
|
mediaPosition: enumOf("before", "after"),
|
|
163
197
|
mediaWidth: enumOf("narrow", "equal", "wide"),
|
|
198
|
+
mediaBorderWidth: borderLength({ description: MEDIA_BORDER_HELP }),
|
|
164
199
|
});
|
|
165
200
|
|
|
166
201
|
/**
|
|
@@ -179,11 +214,19 @@ const HERO_SECTION = Object.freeze({
|
|
|
179
214
|
* current value, which is also what the editor does on its next save.
|
|
180
215
|
*/
|
|
181
216
|
const CTA = Object.freeze({
|
|
217
|
+
context: str({
|
|
218
|
+
maximumLength: registry.section.attrs.context.maximumLength,
|
|
219
|
+
pattern: new RegExp(registry.section.attrs.context.pattern, "u"),
|
|
220
|
+
patternDescription: "a theme context name: a letter, then letters, digits, hyphens or underscores, at most 64 characters",
|
|
221
|
+
description:
|
|
222
|
+
"A theme context declared by both the light and dark themes. It gives the panel that context's background and border, with its text and button colors; run 'theme resolve' to see the context's colors. Omit it to leave the panel unfilled.",
|
|
223
|
+
}),
|
|
182
224
|
heading: str(),
|
|
183
225
|
description: str(),
|
|
184
226
|
buttonText: str(),
|
|
185
227
|
buttonUrl: safeUrl(),
|
|
186
228
|
variant: enumOf("primary", "danger"),
|
|
229
|
+
buttonStyle: buttonStyleValues(CTA_BUTTON_STYLE_DEFAULT),
|
|
187
230
|
borderWidth: num({
|
|
188
231
|
integer: true,
|
|
189
232
|
minimum: 0,
|
|
@@ -191,6 +234,7 @@ const CTA = Object.freeze({
|
|
|
191
234
|
}),
|
|
192
235
|
imagePosition: enumOf("top", "left", "right"),
|
|
193
236
|
mediaImage: image(),
|
|
237
|
+
mediaBorderWidth: borderLength({ description: MEDIA_BORDER_HELP }),
|
|
194
238
|
});
|
|
195
239
|
|
|
196
240
|
/** `FeatureGridData`. */
|
|
@@ -298,7 +342,7 @@ const IMAGE_ROW_HEIGHT_SIZES = Object.entries(IMAGE_ROW_HEIGHTS)
|
|
|
298
342
|
.map(([name, rem]) => `${name} ${rem} (${Number.parseFloat(rem) * 16}px)`)
|
|
299
343
|
.join(", ");
|
|
300
344
|
const IMAGE_ROW_HEIGHT_HELP =
|
|
301
|
-
`Each image's height: ${IMAGE_ROW_HEIGHT_SIZES} at a 16px root; width follows each image's own shape, never cropped
|
|
345
|
+
`Each image's height: ${IMAGE_ROW_HEIGHT_SIZES} at a 16px root; width follows each image's own shape, never cropped.`;
|
|
302
346
|
|
|
303
347
|
/** The registry owns the card image spacings too; each side takes the same four names (TR01326). */
|
|
304
348
|
const CARD_IMAGE_SPACINGS = registry.components["card-grid"].imageSpacings;
|
|
@@ -308,6 +352,13 @@ const CARD_IMAGE_SPACING_VALUES =
|
|
|
308
352
|
const CARD_IMAGE_SPACING_SIDE_HELP = (side, defaults) =>
|
|
309
353
|
`Space on the ${side} of each card image: ${CARD_IMAGE_SPACING_VALUES}. Left out, it is ${defaults}.`;
|
|
310
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Help for the frame on card-grid and image-row images (TR01421). Unlike a hero or call-to-action
|
|
357
|
+
* image, leaving it out does not follow the site's image border.
|
|
358
|
+
*/
|
|
359
|
+
const MEDIA_FRAME_HELP = (subject) =>
|
|
360
|
+
`Frames ${subject}: a CSS width such as 4px or 0.25rem, drawn in the theme's border color; 0 means no frame. Leave it out to keep the images unframed (unlike hero and call-to-action images, which follow the site's image border when it is left out).`;
|
|
361
|
+
|
|
311
362
|
/** `CardGridData`. `cropState` is the one genuinely optional field in types.ts. */
|
|
312
363
|
const CARD_GRID = Object.freeze({
|
|
313
364
|
cards: withOmission(
|
|
@@ -326,7 +377,7 @@ const CARD_GRID = Object.freeze({
|
|
|
326
377
|
imageFit: withOmission(
|
|
327
378
|
described(
|
|
328
379
|
enumOf("cover", "contain"),
|
|
329
|
-
"cover fills the card and crops each image to imageAspect; contain shows the whole image at imageHeight, never cropped
|
|
380
|
+
"cover fills the card and crops each image to imageAspect; contain shows the whole image at imageHeight, never cropped, and needs each image's width and height.",
|
|
330
381
|
),
|
|
331
382
|
{ kind: "value", value: "cover" },
|
|
332
383
|
),
|
|
@@ -353,12 +404,19 @@ const CARD_GRID = Object.freeze({
|
|
|
353
404
|
}),
|
|
354
405
|
"Space around each card image; name only the sides to change, and a side left out keeps its default for the fit. With imageFit contain, start moves an image aligned to start and end moves one aligned to end; otherwise they only limit how wide the image can be.",
|
|
355
406
|
),
|
|
356
|
-
interaction:
|
|
407
|
+
interaction: describedEnum({
|
|
408
|
+
none: "No hover effect.",
|
|
409
|
+
lift: "On hover or focus a card rises and casts a shadow (none on editorial cards).",
|
|
410
|
+
zoom: "On hover a card's image scales up inside its frame; has no effect on a whole image (imageFit contain).",
|
|
411
|
+
"caption-reveal": "Each card's description is hidden until hover or keyboard focus; it always shows on touch screens, with reduced motion and on cards without a link. The title is always shown.",
|
|
412
|
+
press: "A card rests on a shadow, moves toward it on hover and presses flat when pressed. It reads as a press when theme shadow levels 1 and 2 are hard offsets; see 'help theme'.",
|
|
413
|
+
}),
|
|
357
414
|
borderWidth: num({
|
|
358
415
|
integer: true,
|
|
359
416
|
minimum: 0,
|
|
360
|
-
description: "Pixel border around each card; the grid itself is never framed. 0 boxes nothing.",
|
|
417
|
+
description: "Pixel border around each card; the grid itself is never framed. 0 boxes nothing. mediaBorderWidth frames the card images instead.",
|
|
361
418
|
}),
|
|
419
|
+
mediaBorderWidth: borderLength({ description: MEDIA_FRAME_HELP("each card image") }),
|
|
362
420
|
});
|
|
363
421
|
|
|
364
422
|
/** `ImageBannerData`. */
|
|
@@ -520,6 +578,7 @@ const IMAGE_ROW = Object.freeze({
|
|
|
520
578
|
"Where the images sit when they do not fill the row: start is the left edge and end the right edge in a "
|
|
521
579
|
+ "left-to-right page.",
|
|
522
580
|
),
|
|
581
|
+
mediaBorderWidth: borderLength({ description: MEDIA_FRAME_HELP("every image in the row") }),
|
|
523
582
|
});
|
|
524
583
|
|
|
525
584
|
/**
|
|
@@ -630,6 +689,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
630
689
|
title: "Welcome",
|
|
631
690
|
titleSize: "normal",
|
|
632
691
|
lead: "",
|
|
692
|
+
leadSize: "normal",
|
|
633
693
|
primaryAction: { label: "Learn more", url: "/" },
|
|
634
694
|
secondaryAction: null,
|
|
635
695
|
alignment: "start",
|
|
@@ -641,15 +701,18 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
641
701
|
[
|
|
642
702
|
"Use a descriptive alt value on every meaningful image; use an empty alt value only for decorative imagery.",
|
|
643
703
|
"Action labels should describe their destination or action instead of using generic text such as 'Click here'.",
|
|
644
|
-
"The
|
|
704
|
+
"The secondary action is an outline button by default. It casts the theme's button shadow only when the theme sets --esp-button-outline-background in componentProperties; with the solid style it keeps the theme shadow.",
|
|
705
|
+
"The hero title is the page's h1 when nothing earlier is, and an h2 after an earlier h1; do not add an h1 around it.",
|
|
645
706
|
],
|
|
646
707
|
{
|
|
647
708
|
overline: "Riverbend Hot Yoga · Elm Harbor",
|
|
648
709
|
title: "Come as you are. Leave feeling stronger.",
|
|
649
710
|
titleSize: "display",
|
|
650
711
|
lead: "Hot yoga, barre, and wellness practices for every body.",
|
|
712
|
+
leadSize: "normal",
|
|
651
713
|
primaryAction: { label: "View class schedule", url: "/classes" },
|
|
652
714
|
secondaryAction: { label: "Meet the studio", url: "/about" },
|
|
715
|
+
secondaryActionStyle: "text",
|
|
653
716
|
alignment: "start",
|
|
654
717
|
media: {
|
|
655
718
|
imageId: "3f1c2b4a-5d6e-4f70-8a91-b2c3d4e5f607",
|
|
@@ -850,6 +913,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
850
913
|
imageAspect: "landscape",
|
|
851
914
|
interaction: "lift",
|
|
852
915
|
borderWidth: 1,
|
|
916
|
+
mediaBorderWidth: "4px",
|
|
853
917
|
},
|
|
854
918
|
),
|
|
855
919
|
"image-banner": component(
|
|
@@ -969,12 +1033,12 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
969
1033
|
"image-row": component(
|
|
970
1034
|
IMAGE_ROW,
|
|
971
1035
|
"Image Row",
|
|
972
|
-
"A wrapping row of pictures at one height, each with alt text and an optional link, never cropped
|
|
1036
|
+
"A wrapping row of pictures at one height, each with alt text and an optional link, never cropped and unframed unless mediaBorderWidth is set.",
|
|
973
1037
|
{ height: "medium", align: "start" },
|
|
974
1038
|
[
|
|
975
1039
|
"Every image needs alt text unless its descriptionMode is inherit, in which case the inherited description must resolve to non-blank text before deployment. A row of pictures carries no other text. For a linked image the alt is the link's name, so name the destination or action, such as \"Download on the App Store\"; for an unlinked image, describe the picture.",
|
|
976
1040
|
"In Markdown the alt comes from the media manifest entry the image path names; a blank alt is refused.",
|
|
977
|
-
"Each image keeps its own shape at the chosen height and is never cropped
|
|
1041
|
+
"Each image keeps its own shape at the chosen height and is never cropped; it is unframed unless you set mediaBorderWidth, which frames every image in the row. An image wider than the row shrinks to fit. Width and height are required so the row can size the image; media upload records them.",
|
|
978
1042
|
"A link to another site opens in a new tab with nothing to set. The site's own addresses, relative paths, mailto: and tel: links open in the same tab.",
|
|
979
1043
|
],
|
|
980
1044
|
{
|
|
@@ -1004,6 +1068,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
1004
1068
|
],
|
|
1005
1069
|
height: "small",
|
|
1006
1070
|
align: "start",
|
|
1071
|
+
mediaBorderWidth: "2px",
|
|
1007
1072
|
},
|
|
1008
1073
|
),
|
|
1009
1074
|
"product-grid": component(
|
|
@@ -1146,7 +1211,7 @@ function referenceSchema(spec) {
|
|
|
1146
1211
|
} explicit HTTP(S), mailto, or tel URL; a root-relative path that does not begin with //; a fragment; a query; or a relative URL. Backslashes and ASCII control characters are rejected. Contact URLs require a non-empty body and refuse tel:// and mailto:// authority forms. A web address on another site opens in a new tab with nothing to set; the site's own addresses, relative paths, fragments, queries, mailto and tel links do not.`,
|
|
1147
1212
|
};
|
|
1148
1213
|
case "css-length":
|
|
1149
|
-
return { type: "string", description: `Must be ${describe(spec)}
|
|
1214
|
+
return { type: "string", description: `Must be ${describe(spec)}.${spec.description ? ` ${spec.description}` : ""}` };
|
|
1150
1215
|
case "texture-name":
|
|
1151
1216
|
return {
|
|
1152
1217
|
type: "string",
|
|
@@ -1168,6 +1233,7 @@ function referenceSchema(spec) {
|
|
|
1168
1233
|
return {
|
|
1169
1234
|
type: "string",
|
|
1170
1235
|
enum: [...spec.values],
|
|
1236
|
+
...(spec.valueDescriptions ? { valueDescriptions: { ...spec.valueDescriptions } } : {}),
|
|
1171
1237
|
...(spec.description ? { description: spec.description } : {}),
|
|
1172
1238
|
};
|
|
1173
1239
|
case "number": {
|
|
@@ -1323,7 +1389,7 @@ function validateValue(spec, value, path, errors) {
|
|
|
1323
1389
|
return;
|
|
1324
1390
|
case "css-length":
|
|
1325
1391
|
// The renderer drops a value outside this grammar silently, so it is refused here instead.
|
|
1326
|
-
if (normalizeCssLengthOverride(value, { allowNone: spec.allowNone === true }) === null) fail(describe(spec));
|
|
1392
|
+
if (normalizeCssLengthOverride(value, { allowNone: spec.allowNone === true, percent: spec.percent !== false }) === null) fail(describe(spec));
|
|
1327
1393
|
return;
|
|
1328
1394
|
case "texture-name":
|
|
1329
1395
|
if (
|
|
@@ -323,6 +323,15 @@
|
|
|
323
323
|
"minimum": 10,
|
|
324
324
|
"maximum": 200
|
|
325
325
|
},
|
|
326
|
+
"repeat": {
|
|
327
|
+
"type": "enum",
|
|
328
|
+
"required": false,
|
|
329
|
+
"values": [
|
|
330
|
+
"repeat",
|
|
331
|
+
"repeat-x",
|
|
332
|
+
"repeat-y"
|
|
333
|
+
]
|
|
334
|
+
},
|
|
326
335
|
"opacity": {
|
|
327
336
|
"type": "number",
|
|
328
337
|
"required": false,
|
|
@@ -470,8 +470,11 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
470
470
|
validateImageDescription(image, imagePath, "Section decoration image", report);
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
// TR01416: a `repeat` tile paints at the image's natural size, so an authored size beside it is refused. A
|
|
474
|
+
// one-axis tile (`repeat-x`, `repeat-y`) takes a size (TR01421).
|
|
475
|
+
const tiling = value.repeat === "repeat";
|
|
473
476
|
// TR01329: width and height sizes are exclusive, so one conflict replaces both range checks.
|
|
474
|
-
const sizeConflict = Object.hasOwn(value, "inlineSizePercent") && Object.hasOwn(value, "blockSizePercent");
|
|
477
|
+
const sizeConflict = !tiling && Object.hasOwn(value, "inlineSizePercent") && Object.hasOwn(value, "blockSizePercent");
|
|
475
478
|
if (sizeConflict) {
|
|
476
479
|
report(
|
|
477
480
|
`${path}/blockSizePercent`,
|
|
@@ -480,11 +483,26 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
480
483
|
);
|
|
481
484
|
}
|
|
482
485
|
|
|
486
|
+
if (tiling) {
|
|
487
|
+
for (const name of ["inlineSizePercent", "blockSizePercent"]) {
|
|
488
|
+
if (!Object.hasOwn(value, name)) continue;
|
|
489
|
+
report(
|
|
490
|
+
`${path}/${name}`,
|
|
491
|
+
CODES.attrInvalid,
|
|
492
|
+
`Section decoration ${name} cannot be combined with repeat "repeat". A repeating decoration tiles at the image's natural size, so leave the size out.`,
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
483
497
|
for (const [name, definition] of Object.entries(fields)) {
|
|
484
498
|
if (name === "image" || !Object.hasOwn(value, name)) continue;
|
|
485
|
-
if (sizeConflict && (name === "inlineSizePercent" || name === "blockSizePercent")) continue;
|
|
499
|
+
if ((sizeConflict || tiling) && (name === "inlineSizePercent" || name === "blockSizePercent")) continue;
|
|
486
500
|
const fieldPath = `${path}/${name}`;
|
|
487
501
|
const entry = value[name];
|
|
502
|
+
if (definition.type === "boolean") {
|
|
503
|
+
if (typeof entry !== "boolean") report(fieldPath, CODES.attrInvalid, `Section decoration ${name} must be true or false.`);
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
488
506
|
if (definition.type === "enum") {
|
|
489
507
|
if (typeof entry !== "string" || !definition.values.includes(entry)) {
|
|
490
508
|
report(
|
|
@@ -527,8 +545,9 @@ export function normalizeFreeFormSectionDecoration(
|
|
|
527
545
|
const normalized = { image: Object.freeze(normalizedImage) };
|
|
528
546
|
for (const [name, definition] of Object.entries(fields)) {
|
|
529
547
|
if (name === "image") continue;
|
|
530
|
-
// A field with no default stays absent. The width default applies only without a height size
|
|
531
|
-
|
|
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)
|
|
532
551
|
? undefined
|
|
533
552
|
: definition.default;
|
|
534
553
|
const resolved = value[name] ?? fallback;
|
|
@@ -557,19 +576,38 @@ export function freeFormRootPresentation(node, source = FREE_FORM_SECTION_REGIST
|
|
|
557
576
|
return Object.hasOwn(source.rootNodes, node.type) ? source.rootNodes[node.type] : undefined;
|
|
558
577
|
}
|
|
559
578
|
|
|
579
|
+
/**
|
|
580
|
+
* The theme context a node names: a section's `context` attribute, or a call
|
|
581
|
+
* to action's `context` field inside its `componentData` JSON string (TR01413).
|
|
582
|
+
* Returns the field's location relative to the node, or undefined.
|
|
583
|
+
*/
|
|
584
|
+
export function namedContext(node, source = FREE_FORM_SECTION_REGISTRY) {
|
|
585
|
+
if (!isPlainObject(node) || !isPlainObject(node.attrs)) return undefined;
|
|
586
|
+
if (node.type === source.section.nodeType) {
|
|
587
|
+
return typeof node.attrs.context === "string"
|
|
588
|
+
? { context: node.attrs.context, field: "/attrs/context" }
|
|
589
|
+
: undefined;
|
|
590
|
+
}
|
|
591
|
+
if (node.type !== "componentBlock" || node.attrs.componentType !== "cta") return undefined;
|
|
592
|
+
if (typeof node.attrs.componentData !== "string") return undefined;
|
|
593
|
+
let data;
|
|
594
|
+
try {
|
|
595
|
+
data = JSON.parse(node.attrs.componentData);
|
|
596
|
+
} catch {
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
return isPlainObject(data) && typeof data.context === "string"
|
|
600
|
+
? { context: data.context, field: "/attrs/componentData" }
|
|
601
|
+
: undefined;
|
|
602
|
+
}
|
|
603
|
+
|
|
560
604
|
/** Whether a structurally validated document needs staged theme settings. */
|
|
561
605
|
export function hasNamedFreeFormSectionContext(document, source = FREE_FORM_SECTION_REGISTRY) {
|
|
562
606
|
let found = false;
|
|
563
|
-
const sectionType = source.section.nodeType;
|
|
564
607
|
|
|
565
608
|
function visit(node) {
|
|
566
609
|
if (found || !isPlainObject(node)) return;
|
|
567
|
-
if (
|
|
568
|
-
node.type === sectionType
|
|
569
|
-
&& isPlainObject(node.attrs)
|
|
570
|
-
&& typeof node.attrs.context === "string"
|
|
571
|
-
&& node.attrs.context !== ""
|
|
572
|
-
) {
|
|
610
|
+
if (namedContext(node, source)?.context) {
|
|
573
611
|
found = true;
|
|
574
612
|
return;
|
|
575
613
|
}
|
|
@@ -598,18 +636,19 @@ export function validateFreeFormSectionContexts(
|
|
|
598
636
|
? `Declared alternatives: ${alternatives.join(", ")}.`
|
|
599
637
|
: "The staged light and dark themes declare no shared context alternatives.";
|
|
600
638
|
const errors = [];
|
|
601
|
-
const sectionType = source.section.nodeType;
|
|
602
639
|
|
|
603
640
|
function visit(node, path) {
|
|
604
641
|
if (errors.length >= CONTENT_LIMITS.documentErrors) return false;
|
|
605
642
|
if (!isPlainObject(node)) return true;
|
|
606
|
-
|
|
607
|
-
|
|
643
|
+
const named = namedContext(node, source);
|
|
644
|
+
if (named) {
|
|
645
|
+
const { context } = named;
|
|
608
646
|
if (!allowed.has(context)) {
|
|
647
|
+
const owner = node.type === source.section.nodeType ? "Section" : "Call to action";
|
|
609
648
|
errors.push(contentError(
|
|
610
|
-
`${path}
|
|
649
|
+
`${path}${named.field}`,
|
|
611
650
|
CODES.sectionContextUnknown,
|
|
612
|
-
|
|
651
|
+
`${owner} context '${context}' is not declared by both staged themes. ${suffix}`,
|
|
613
652
|
));
|
|
614
653
|
if (errors.length >= CONTENT_LIMITS.documentErrors) return false;
|
|
615
654
|
}
|