@lacecms/content 0.1.0-alpha.6 → 0.1.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,9 @@
1
+ import { parseVideoEmbed } from "./video-embeds.js";
1
2
  import * as v from "valibot";
3
+ import { decodeEntryLink, MAX_INTERNAL_LINK_REFERENCES } from "./internal-links.js";
4
+ export * from "./internal-links.js";
5
+ export * from "./video-embeds.js";
6
+ export * from "./list-query-policy.js";
2
7
  /** Validates, detaches and freezes optional sibling layout metadata. */
3
8
  export function normalizeFormLayout(value, fields, path = "layout") {
4
9
  if (value === undefined)
@@ -266,11 +271,31 @@ function buildStringValueField(type, input) {
266
271
  "description",
267
272
  "label",
268
273
  "required",
269
- ...(type === "url" ? ["placeholder"] : []),
274
+ ...(type === "url" ? ["placeholder", "embedProviders"] : []),
270
275
  ]);
271
276
  const definition = { type };
272
277
  addCommonOptions(definition, options);
273
- addDefault(definition, options, (value) => typeof value === "string", "must be a string.");
278
+ if (type === "url" && options.embedProviders !== undefined) {
279
+ const providers = options.embedProviders;
280
+ if (!Array.isArray(providers) ||
281
+ providers.length === 0 ||
282
+ providers.some((provider) => provider !== "youtube" && provider !== "vimeo") ||
283
+ new Set(providers).size !== providers.length)
284
+ fail("options.embedProviders", "must be a non-empty unique list of youtube and vimeo.");
285
+ definition.embedProviders = ["youtube", "vimeo"].filter((provider) => providers.includes(provider));
286
+ }
287
+ addDefault(definition, options, (value) => {
288
+ if (typeof value !== "string")
289
+ return false;
290
+ if (definition.embedProviders === undefined)
291
+ return true;
292
+ const embed = parseVideoEmbed(value);
293
+ return (isSafeUrl(value) &&
294
+ embed !== undefined &&
295
+ definition.embedProviders.includes(embed.provider));
296
+ }, definition.embedProviders === undefined
297
+ ? "must be a string."
298
+ : "must be a string matching the declared embed providers.");
274
299
  return deepFreeze(definition);
275
300
  }
276
301
  /** Builders for portable Lace field descriptors. */
@@ -362,6 +387,7 @@ export const field = {
362
387
  "description",
363
388
  "label",
364
389
  "options",
390
+ "presentation",
365
391
  "placeholder",
366
392
  "required",
367
393
  ]);
@@ -383,10 +409,12 @@ export const field = {
383
409
  }
384
410
  const definition = { options: choices, type: "select" };
385
411
  addCommonOptions(definition, normalized);
412
+ if (normalized.presentation !== undefined)
413
+ definition.presentation = normalizeSelectPresentation(normalized.presentation, choices);
386
414
  addDefault(definition, normalized, (value) => typeof value === "string" && seen.has(value), "must be one of the declared select choices.");
387
415
  return deepFreeze(definition);
388
416
  },
389
- /** Define a URL string field; URL protocol validation is added in Session 2B. */
417
+ /** Define a safe URL field, optionally restricted to supported video providers. */
390
418
  url(options) {
391
419
  return buildStringValueField("url", options);
392
420
  },
@@ -395,6 +423,76 @@ export const field = {
395
423
  return buildStringValueField("media", options);
396
424
  },
397
425
  };
426
+ function normalizeSelectPresentation(value, options) {
427
+ const path = "options.presentation";
428
+ const exact = (raw, keys, at) => {
429
+ const record = descriptorRecord(raw, at);
430
+ for (const key of Object.keys(record))
431
+ if (!keys.includes(key))
432
+ fail(`${at}.${key}`, "is not supported.");
433
+ return record;
434
+ };
435
+ const text = (raw, at) => {
436
+ if (typeof raw !== "string" ||
437
+ !raw.trim() ||
438
+ /[<>]/u.test(raw) ||
439
+ [...raw].some((character) => character.charCodeAt(0) < 32))
440
+ fail(at, "must be nonempty plain text.");
441
+ return raw;
442
+ };
443
+ const raw = exact(value, ["control", "choices"], path);
444
+ if (raw.control !== "cards")
445
+ fail(`${path}.control`, 'must be "cards".');
446
+ if (!Array.isArray(raw.choices) || raw.choices.length !== options.length)
447
+ fail(`${path}.choices`, "must cover every select option exactly once.");
448
+ const seen = new Set();
449
+ const choices = raw.choices.map((choice, index) => {
450
+ const at = `${path}.choices[${index}]`;
451
+ const entry = exact(choice, ["value", "label", "description", "diagram"], at);
452
+ if (typeof entry.value !== "string" || !options.includes(entry.value) || seen.has(entry.value))
453
+ fail(`${at}.value`, "must name a unique declared select option.");
454
+ seen.add(entry.value);
455
+ const result = {
456
+ value: entry.value,
457
+ label: text(entry.label, `${at}.label`),
458
+ ...(entry.description !== undefined
459
+ ? { description: text(entry.description, `${at}.description`) }
460
+ : {}),
461
+ ...(entry.diagram !== undefined ? { diagram: diagram(entry.diagram, `${at}.diagram`) } : {}),
462
+ };
463
+ return result;
464
+ });
465
+ return deepFreeze({ control: "cards", choices });
466
+ function diagram(input, at) {
467
+ const rawDiagram = exact(input, ["cells"], at);
468
+ if (!Array.isArray(rawDiagram.cells) ||
469
+ rawDiagram.cells.length < 1 ||
470
+ rawDiagram.cells.length > 16)
471
+ fail(`${at}.cells`, "must contain 1–16 rectangles.");
472
+ const cells = [];
473
+ for (const [index, inputCell] of rawDiagram.cells.entries()) {
474
+ const cellPath = `${at}.cells[${index}]`;
475
+ const rawCell = exact(inputCell, ["x", "y", "width", "height"], cellPath);
476
+ for (const key of ["x", "y", "width", "height"]) {
477
+ const n = rawCell[key];
478
+ if (typeof n !== "number" ||
479
+ !Number.isInteger(n) ||
480
+ n < (key === "x" || key === "y" ? 0 : 1))
481
+ fail(`${cellPath}.${key}`, "must be an integer within the 12 by 12 canvas.");
482
+ }
483
+ const cell = rawCell;
484
+ if (cell.x + cell.width > 12 || cell.y + cell.height > 12)
485
+ fail(cellPath, "must fit within the 12 by 12 canvas.");
486
+ if (cells.some((other) => cell.x < other.x + other.width &&
487
+ cell.x + cell.width > other.x &&
488
+ cell.y < other.y + other.height &&
489
+ cell.y + cell.height > other.y))
490
+ fail(cellPath, "must not overlap another rectangle.");
491
+ cells.push({ ...cell });
492
+ }
493
+ return { cells };
494
+ }
495
+ }
398
496
  /**
399
497
  * Project a field descriptor into a detached, immutable JSON-safe admin form
400
498
  * representation. Runtime schemas and callbacks are deliberately absent.
@@ -585,7 +683,7 @@ function assertExactKeys(value, required, optional, path) {
585
683
  }
586
684
  }
587
685
  }
588
- /** Returns whether a URL is permitted in Lace URL fields and rich-text links. */
686
+ /** Returns whether a URL is permitted as an href, including rich-text links. */
589
687
  export function isSafeUrl(value) {
590
688
  if (typeof value !== "string" ||
591
689
  value.length === 0 ||
@@ -601,6 +699,10 @@ export function isSafeUrl(value) {
601
699
  }
602
700
  return /^(?:https?:\/\/[^/?#\s]+(?:[/?#][^\s]*)?|mailto:[^\s@]+@[^\s@]+|tel:\+?[0-9(). -]+)$/u.test(value);
603
701
  }
702
+ /** Ordinary URL fields support safe manual URLs and canonical entry tokens. */
703
+ export function isUrlFieldTarget(value) {
704
+ return isSafeUrl(value) || decodeEntryLink(value) !== undefined;
705
+ }
604
706
  function assertMarks(value, path) {
605
707
  if (!Array.isArray(value)) {
606
708
  invalid(path, "invalid_marks", "must be an array.");
@@ -811,7 +913,14 @@ function isFieldValue(definition, value) {
811
913
  textarea: (fieldDefinition) => typeof value === "string" &&
812
914
  (fieldDefinition.minLength === undefined || textLength(value) >= fieldDefinition.minLength) &&
813
915
  (fieldDefinition.maxLength === undefined || textLength(value) <= fieldDefinition.maxLength),
814
- url: () => isSafeUrl(value),
916
+ url: (descriptor) => {
917
+ if (descriptor.embedProviders === undefined)
918
+ return isUrlFieldTarget(value);
919
+ if (!isSafeUrl(value))
920
+ return false;
921
+ const embed = parseVideoEmbed(value);
922
+ return embed !== undefined && descriptor.embedProviders.includes(embed.provider);
923
+ },
815
924
  });
816
925
  }
817
926
  /** Compiles a field definition with the same normalization as aggregate validation. */
@@ -908,6 +1017,53 @@ export function validateSnapshotListBudget(fields, values, blocks) {
908
1017
  walk(fields, values, ["fields"]);
909
1018
  blocks.forEach((block) => walk(block.fields, block.data, block.path));
910
1019
  }
1020
+ /** Discover references only in normalized ordinary URL descriptors. */
1021
+ export function collectFieldInternalLinks(definitions, values) {
1022
+ const references = [];
1023
+ function visit(definition, value, path) {
1024
+ if (definition.type === "url" && definition.embedProviders === undefined) {
1025
+ const targetId = decodeEntryLink(value);
1026
+ if (targetId !== undefined)
1027
+ references.push({ targetId, path });
1028
+ }
1029
+ else if (definition.type === "group" && isRecord(value)) {
1030
+ walk(definition.fields, value, path);
1031
+ }
1032
+ else if (definition.type === "list" && Array.isArray(value)) {
1033
+ value.forEach((item, index) => visit(definition.item, item, [...path, index]));
1034
+ }
1035
+ }
1036
+ function walk(fields, data, path) {
1037
+ for (const [key, definition] of Object.entries(fields))
1038
+ visit(definition, data[key], [...path, key]);
1039
+ }
1040
+ walk(definitions, values, []);
1041
+ return deepFreeze(references);
1042
+ }
1043
+ /** Collect and bound every declared internal URL in one normalized snapshot. */
1044
+ export function collectSnapshotInternalLinks(fields, values, blocks) {
1045
+ const references = [];
1046
+ function add(definitions, data, sourceKey, area, delivered, rootPath) {
1047
+ for (const reference of collectFieldInternalLinks(definitions, data)) {
1048
+ if (references.length === MAX_INTERNAL_LINK_REFERENCES)
1049
+ invalid([...rootPath, ...reference.path], "too_many_internal_links", `must not contain more than ${MAX_INTERNAL_LINK_REFERENCES} internal links.`);
1050
+ references.push({
1051
+ sourceKey,
1052
+ area,
1053
+ delivered,
1054
+ targetId: reference.targetId,
1055
+ pointer: `/${reference.path.map((part) => String(part).replaceAll("~", "~0").replaceAll("/", "~1")).join("/")}`,
1056
+ });
1057
+ }
1058
+ }
1059
+ add(fields, values, "$fields", "fields", true, ["fields"]);
1060
+ blocks.forEach((block, index) => add(block.fields, block.data, block.key, "data", block.hidden !== true, [
1061
+ "blocks",
1062
+ index,
1063
+ "data",
1064
+ ]));
1065
+ return deepFreeze(references);
1066
+ }
911
1067
  /** Finds declared media leaves only; ordinary strings never become references. */
912
1068
  export function collectFieldMedia(definitions, values) {
913
1069
  const references = [];
@@ -1037,6 +1193,40 @@ export const BLOCK_SETTING_FIELD_TYPES = Object.freeze([
1037
1193
  "select",
1038
1194
  "text",
1039
1195
  ]);
1196
+ /** Validates and detaches settings-only visibility metadata. */
1197
+ export function normalizeSettingsVisibility(value, settings, path = "settingsVisibility") {
1198
+ if (value === undefined)
1199
+ return undefined;
1200
+ const raw = normalizeJsonValue(value, path, new WeakSet());
1201
+ if (!isRecord(raw))
1202
+ fail(path, "must be a plain object of setting rules.");
1203
+ for (const [target, rule] of Object.entries(raw)) {
1204
+ const at = `${path}.${target}`;
1205
+ if (!Object.hasOwn(settings, target))
1206
+ fail(at, "must target a declared scalar setting.");
1207
+ if (!isRecord(rule) ||
1208
+ Object.keys(rule).some((key) => !["setting", "values"].includes(key)) ||
1209
+ typeof rule.setting !== "string")
1210
+ fail(at, "must contain only setting and values.");
1211
+ if (rule.setting === target || Object.hasOwn(raw, rule.setting))
1212
+ fail(`${at}.setting`, "must be an unconditional sibling select; self references, chains and cycles are not allowed.");
1213
+ const controller = Object.hasOwn(settings, rule.setting)
1214
+ ? settings[rule.setting]
1215
+ : undefined;
1216
+ if (controller?.type !== "select" ||
1217
+ !controller.required ||
1218
+ !Object.hasOwn(controller, "defaultValue") ||
1219
+ typeof controller.defaultValue !== "string" ||
1220
+ !controller.options.includes(controller.defaultValue))
1221
+ fail(`${at}.setting`, "must name a required select setting with a valid default.");
1222
+ if (!Array.isArray(rule.values) ||
1223
+ rule.values.length === 0 ||
1224
+ new Set(rule.values).size !== rule.values.length ||
1225
+ rule.values.some((option) => typeof option !== "string" || !controller.options.includes(option)))
1226
+ fail(`${at}.values`, "must be a nonempty unique subset of the controller options.");
1227
+ }
1228
+ return deepFreeze(raw);
1229
+ }
1040
1230
  function blockFail(message) {
1041
1231
  throw new BlockConfigurationError(message);
1042
1232
  }
@@ -1137,6 +1327,7 @@ export function defineBlock(input) {
1137
1327
  "migrations",
1138
1328
  "layout",
1139
1329
  "settingsLayout",
1330
+ "settingsVisibility",
1140
1331
  "settings",
1141
1332
  "type",
1142
1333
  "version",
@@ -1163,6 +1354,7 @@ export function defineBlock(input) {
1163
1354
  const settings = normalizeBlockSettings(input.settings);
1164
1355
  const layout = normalizeFormLayout(input.layout, fields, `block.${input.type}.layout`);
1165
1356
  const settingsLayout = normalizeFormLayout(input.settingsLayout, settings ?? {}, `block.${input.type}.settingsLayout`);
1357
+ const settingsVisibility = normalizeSettingsVisibility(input.settingsVisibility, settings ?? {}, `block.${input.type}.settingsVisibility`);
1166
1358
  let defaultValue;
1167
1359
  if (input.defaultValue !== undefined) {
1168
1360
  try {
@@ -1187,6 +1379,7 @@ export function defineBlock(input) {
1187
1379
  ...(migrations === undefined ? {} : { migrations }),
1188
1380
  ...(layout === undefined ? {} : { layout }),
1189
1381
  ...(settingsLayout === undefined ? {} : { settingsLayout }),
1382
+ ...(settingsVisibility === undefined ? {} : { settingsVisibility }),
1190
1383
  ...(settings === undefined ? {} : { settings }),
1191
1384
  type: input.type,
1192
1385
  validate: (value, mode) => {
@@ -1218,6 +1411,11 @@ export function toBlockMetadata(definition) {
1218
1411
  : {
1219
1412
  settingsLayout: normalizeFormLayout(definition.settingsLayout, definition.settings ?? {}),
1220
1413
  }),
1414
+ ...(definition.settingsVisibility === undefined
1415
+ ? {}
1416
+ : {
1417
+ settingsVisibility: normalizeSettingsVisibility(definition.settingsVisibility, definition.settings ?? {}),
1418
+ }),
1221
1419
  ...(definition.settings === undefined
1222
1420
  ? {}
1223
1421
  : {
@@ -1367,6 +1565,154 @@ export function effectiveAltText(usageAlt, mediaAlt) {
1367
1565
  return mediaAlt;
1368
1566
  return "";
1369
1567
  }
1568
+ /** Shared presentation rules for the independent scalar list settings. */
1569
+ export function listLayoutSettingsVisibility() {
1570
+ return deepFreeze({
1571
+ layoutWrap: { setting: "layoutMode", values: ["flex-row", "flex-column"] },
1572
+ layoutPreset: { setting: "layoutMode", values: ["grid"] },
1573
+ });
1574
+ }
1575
+ /** Shared scalar settings for one explicitly adopted list, in any block. */
1576
+ export function listLayoutSettings() {
1577
+ const cells = (rects) => ({
1578
+ cells: rects.map(([x, y, width, height]) => ({ x, y, width, height })),
1579
+ });
1580
+ const columns = (count) => cells(Array.from({ length: count }, (_, i) => [i * (12 / count), 0, 12 / count - 1, 12]));
1581
+ return deepFreeze({
1582
+ layoutMode: field.select({
1583
+ options: ["flex-row", "flex-column", "grid"],
1584
+ required: true,
1585
+ defaultValue: "grid",
1586
+ label: "Arrangement",
1587
+ presentation: {
1588
+ control: "cards",
1589
+ choices: [
1590
+ {
1591
+ value: "flex-row",
1592
+ label: "Horizontal",
1593
+ description: "Items flow across rows.",
1594
+ diagram: columns(3),
1595
+ },
1596
+ {
1597
+ value: "flex-column",
1598
+ label: "Vertical",
1599
+ description: "Items flow down columns. Wrapping needs a height set in site CSS.",
1600
+ diagram: cells([
1601
+ [0, 0, 12, 3],
1602
+ [0, 4, 12, 3],
1603
+ [0, 8, 12, 3],
1604
+ ]),
1605
+ },
1606
+ {
1607
+ value: "grid",
1608
+ label: "Grid",
1609
+ description: "Items use the selected grid preset.",
1610
+ diagram: cells([
1611
+ [0, 0, 5, 5],
1612
+ [6, 0, 5, 5],
1613
+ [0, 6, 5, 5],
1614
+ [6, 6, 5, 5],
1615
+ ]),
1616
+ },
1617
+ ],
1618
+ },
1619
+ }),
1620
+ layoutWrap: field.boolean({
1621
+ defaultValue: true,
1622
+ label: "Wrap items",
1623
+ description: "Applies to horizontal and vertical flex lists. Vertical wrapping requires a height set in site CSS.",
1624
+ }),
1625
+ layoutPreset: field.select({
1626
+ options: [
1627
+ "auto",
1628
+ "columns-2",
1629
+ "columns-3",
1630
+ "columns-4",
1631
+ "narrow-wide",
1632
+ "wide-narrow",
1633
+ "featured-first",
1634
+ ],
1635
+ required: true,
1636
+ defaultValue: "auto",
1637
+ label: "Grid preset",
1638
+ description: "Applies when Grid is selected. Schematics show composition; your site controls styling.",
1639
+ presentation: {
1640
+ control: "cards",
1641
+ choices: [
1642
+ {
1643
+ value: "auto",
1644
+ label: "Auto",
1645
+ description: "As many equal columns as fit.",
1646
+ diagram: cells([
1647
+ [0, 0, 3, 5],
1648
+ [4, 0, 3, 5],
1649
+ [8, 0, 3, 5],
1650
+ [0, 6, 3, 5],
1651
+ [4, 6, 3, 5],
1652
+ ]),
1653
+ },
1654
+ {
1655
+ value: "columns-2",
1656
+ label: "Two columns",
1657
+ description: "Two equal columns from 32rem.",
1658
+ diagram: columns(2),
1659
+ },
1660
+ {
1661
+ value: "columns-3",
1662
+ label: "Three columns",
1663
+ description: "Two from 32rem, three from 48rem.",
1664
+ diagram: columns(3),
1665
+ },
1666
+ {
1667
+ value: "columns-4",
1668
+ label: "Four columns",
1669
+ description: "Two from 32rem, three from 48rem, four from 64rem.",
1670
+ diagram: columns(4),
1671
+ },
1672
+ {
1673
+ value: "narrow-wide",
1674
+ label: "Narrow + wide",
1675
+ description: "Alternating 1:2 columns from 32rem.",
1676
+ diagram: cells([
1677
+ [0, 0, 3, 12],
1678
+ [4, 0, 8, 12],
1679
+ ]),
1680
+ },
1681
+ {
1682
+ value: "wide-narrow",
1683
+ label: "Wide + narrow",
1684
+ description: "Alternating 2:1 columns from 32rem.",
1685
+ diagram: cells([
1686
+ [0, 0, 8, 12],
1687
+ [9, 0, 3, 12],
1688
+ ]),
1689
+ },
1690
+ {
1691
+ value: "featured-first",
1692
+ label: "Featured first",
1693
+ description: "First item spans two columns from 32rem.",
1694
+ diagram: cells([
1695
+ [0, 0, 12, 5],
1696
+ [0, 6, 5, 5],
1697
+ [6, 6, 5, 5],
1698
+ ]),
1699
+ },
1700
+ ],
1701
+ },
1702
+ }),
1703
+ });
1704
+ }
1705
+ // The opt-in full-screen original of the `image` and `gallery` blocks.
1706
+ const lightboxSetting = field.boolean({
1707
+ defaultValue: false,
1708
+ description: "Opens the original image full screen when it is selected.",
1709
+ label: "Open full screen",
1710
+ });
1711
+ // The optional link of an `image` block and of each `gallery` item.
1712
+ const imageLinkField = field.url({
1713
+ description: "Selecting the image opens this link instead of the full-screen view.",
1714
+ label: "Link",
1715
+ });
1370
1716
  /** Starter blocks implemented exclusively through the public block and field DSL. */
1371
1717
  export const builtInBlocks = deepFreeze({
1372
1718
  cta: defineBlock({
@@ -1382,12 +1728,14 @@ export const builtInBlocks = deepFreeze({
1382
1728
  version: 1,
1383
1729
  }),
1384
1730
  gallery: defineBlock({
1385
- description: "A grid of images with optional captions.",
1731
+ description: "A list of images with selectable layouts and optional captions.",
1386
1732
  fields: {
1387
1733
  images: field.list({
1388
1734
  defaultValue: [],
1389
1735
  item: field.group({
1736
+ // Media comes first so editors show the image before its overrides.
1390
1737
  fields: {
1738
+ media: field.media({ label: "Image", required: true }),
1391
1739
  alt: field.text({
1392
1740
  description: "Leave empty to use the media item's alt text.",
1393
1741
  label: "Alt text",
@@ -1396,7 +1744,7 @@ export const builtInBlocks = deepFreeze({
1396
1744
  description: "Leave empty to use the media item's caption.",
1397
1745
  label: "Caption",
1398
1746
  }),
1399
- media: field.media({ label: "Image", required: true }),
1747
+ link: imageLinkField,
1400
1748
  },
1401
1749
  }),
1402
1750
  itemLabel: "caption",
@@ -1407,8 +1755,20 @@ export const builtInBlocks = deepFreeze({
1407
1755
  title: field.text({ label: "Title" }),
1408
1756
  },
1409
1757
  label: "Gallery",
1758
+ // Version 2 only added the lightbox setting and version 3 only the optional
1759
+ // item link. Version 4 adds scalar layout defaults; data stays valid.
1760
+ migrations: { 2: (block) => block, 3: (block) => block, 4: (block) => block },
1761
+ settings: { ...listLayoutSettings(), lightbox: lightboxSetting },
1762
+ settingsVisibility: listLayoutSettingsVisibility(),
1763
+ settingsLayout: {
1764
+ mode: "sections",
1765
+ groups: [
1766
+ { key: "layout", label: "Layout", fields: ["layoutMode", "layoutWrap", "layoutPreset"] },
1767
+ { key: "behavior", label: "Behavior", fields: ["lightbox"] },
1768
+ ],
1769
+ },
1410
1770
  type: "gallery",
1411
- version: 1,
1771
+ version: 4,
1412
1772
  }),
1413
1773
  hero: defineBlock({
1414
1774
  description: "Large heading with optional text, image, and action.",
@@ -1426,16 +1786,39 @@ export const builtInBlocks = deepFreeze({
1426
1786
  }),
1427
1787
  image: defineBlock({
1428
1788
  description: "A single image with an optional caption and alt text that overrides the media alt.",
1789
+ // Media comes first so editors show the image before its overrides.
1429
1790
  fields: {
1791
+ media: field.media({ required: true }),
1430
1792
  alt: field.text(),
1431
1793
  caption: field.text(),
1432
- media: field.media({ required: true }),
1794
+ link: imageLinkField,
1433
1795
  },
1434
1796
  label: "Image",
1435
- // Version 2 only made `alt` optional, so version 1 data is already valid.
1436
- migrations: { 2: (block) => block },
1797
+ // Version 2 only made `alt` optional, version 3 only added the lightbox
1798
+ // setting and version 4 only the optional link, so earlier data is valid.
1799
+ migrations: { 2: (block) => block, 3: (block) => block, 4: (block) => block },
1800
+ settings: { lightbox: lightboxSetting },
1437
1801
  type: "image",
1438
- version: 2,
1802
+ version: 4,
1803
+ }),
1804
+ link: defineBlock({
1805
+ description: "A link to a page or URL, presented as a button or text.",
1806
+ fields: {
1807
+ label: field.text({ label: "Label", minLength: 1, maxLength: 200, required: true }),
1808
+ url: field.url({ label: "Destination", required: true }),
1809
+ },
1810
+ settings: {
1811
+ appearance: field.select({
1812
+ label: "Appearance",
1813
+ options: ["button", "text"],
1814
+ defaultValue: "button",
1815
+ required: true,
1816
+ }),
1817
+ newTab: field.boolean({ label: "Open in new tab", defaultValue: false, required: true }),
1818
+ },
1819
+ label: "Link",
1820
+ type: "link",
1821
+ version: 1,
1439
1822
  }),
1440
1823
  navigation: defineBlock({
1441
1824
  description: "A list of links with optional one-level submenus.",
@@ -1493,6 +1876,31 @@ export const builtInBlocks = deepFreeze({
1493
1876
  type: "richText",
1494
1877
  version: 1,
1495
1878
  }),
1879
+ videoEmbed: defineBlock({
1880
+ type: "videoEmbed",
1881
+ version: 1,
1882
+ label: "Video embed",
1883
+ description: "A YouTube or Vimeo video with an optional image preview.",
1884
+ fields: {
1885
+ url: field.url({
1886
+ required: true,
1887
+ embedProviders: ["youtube", "vimeo"],
1888
+ label: "Video URL",
1889
+ description: "Paste a YouTube or Vimeo video link, not iframe code.",
1890
+ }),
1891
+ title: field.text({
1892
+ required: true,
1893
+ minLength: 1,
1894
+ label: "Title",
1895
+ description: "Names the video for visitors using assistive technology.",
1896
+ }),
1897
+ poster: field.media({
1898
+ label: "Preview image",
1899
+ description: "Optional. Load the video player only when a visitor selects this preview.",
1900
+ }),
1901
+ caption: field.text({ label: "Caption" }),
1902
+ },
1903
+ }),
1496
1904
  });
1497
1905
  /** Maximum title length shared by draft, publish, REST, and admin validation. */
1498
1906
  export const MAX_TITLE_LENGTH = 200;
@@ -1673,6 +2081,12 @@ export function validateEntryAggregate(input, model, registry, mode) {
1673
2081
  data: block.data,
1674
2082
  path: ["blocks", index, "data"],
1675
2083
  })));
2084
+ collectSnapshotInternalLinks(model.fields, fields, blocks.map((block) => ({
2085
+ key: block.key,
2086
+ fields: registry.get(block.type).fields,
2087
+ data: block.data,
2088
+ hidden: block.hidden,
2089
+ })));
1676
2090
  return deepFreeze({
1677
2091
  blocks: deepFreeze(blocks),
1678
2092
  fields,