@homepages/concrete 1.0.3 → 3.0.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/codemods/framework-namespace.mjs +107 -0
  3. package/codemods/manifest.json +17 -0
  4. package/codemods/theme-collapse.mjs +394 -0
  5. package/codemods/unlayer-author-css.mjs +194 -0
  6. package/dist/artifact/playground/client/assets/index-B3eNADCe.js +1107 -0
  7. package/dist/artifact/playground/client/index.html +1 -1
  8. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
  9. package/dist/artifact/playground/host.mjs +21 -21
  10. package/dist/base.css +61 -31
  11. package/dist/cli/build/static.js +1 -1
  12. package/dist/cli/check/render/class-conflicts.js +1 -1
  13. package/dist/cli/dev/islands.js +2 -2
  14. package/dist/cli/dev/server.js +6 -2
  15. package/dist/cli/dev/vite.js +42 -22
  16. package/dist/css/compile.js +26 -4
  17. package/dist/css/rules.js +72 -1
  18. package/dist/eslint/authoring.js +2 -0
  19. package/dist/eslint/rules/island-ids.js +39 -0
  20. package/dist/fixtures/media-plugin.js +32 -17
  21. package/dist/fixtures/media.js +4 -2
  22. package/dist/fixtures/property.js +12 -2
  23. package/dist/fixtures/resolve.js +58 -5
  24. package/dist/fixtures/rows.js +6 -1
  25. package/dist/fixtures.d.ts +57 -12
  26. package/dist/fixtures.js +7 -3
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.js +2 -1
  29. package/dist/islands/island-id.js +8 -0
  30. package/dist/islands/marker.d.ts +14 -4
  31. package/dist/islands/marker.js +18 -6
  32. package/dist/packages/external/concrete/package.js +1 -1
  33. package/dist/packages/internal/island-runtime/dist/index.js +4 -2
  34. package/dist/packages/internal/island-runtime/dist/island-id-context.js +15 -0
  35. package/dist/packages/internal/island-runtime/dist/use-island-id.d.ts +24 -0
  36. package/dist/packages/internal/island-runtime/dist/use-island-id.js +44 -0
  37. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1 -1
  38. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +44 -2
  39. package/dist/primitives/FrameShell.d.ts +1 -1
  40. package/dist/primitives/FrameShell.js +1 -1
  41. package/dist/primitives/Image.d.ts +1 -1
  42. package/dist/primitives/Image.js +3 -3
  43. package/dist/primitives/Section.d.ts +3 -3
  44. package/dist/primitives/Section.js +4 -4
  45. package/dist/primitives/Tour.d.ts +1 -1
  46. package/dist/primitives/Tour.js +3 -3
  47. package/dist/primitives/Video.d.ts +1 -1
  48. package/dist/primitives/Video.js +3 -3
  49. package/dist/rules/registry.js +19 -0
  50. package/dist/styles.css +4 -3
  51. package/dist/template/logic-shim.d.ts +2 -1
  52. package/dist/template/logic-shim.js +2 -1
  53. package/guide/reference/cli/INDEX.md +2 -2
  54. package/guide/reference/cli/build.md +1 -1
  55. package/guide/reference/cli/check.md +1 -1
  56. package/guide/reference/cli/dev.md +1 -1
  57. package/guide/reference/cli/property-add.md +1 -1
  58. package/guide/reference/cli/property-list.md +1 -1
  59. package/guide/reference/cli/publish.md +1 -1
  60. package/guide/reference/cli/upgrade.md +1 -1
  61. package/guide/reference/rules/INDEX.md +4 -1
  62. package/package.json +1 -1
  63. package/dist/artifact/playground/client/assets/index-Da8V3M7E.js +0 -1101
@@ -1,6 +1,7 @@
1
1
  import { createTsconfigPathsPlugin } from "./tsconfig-paths.js";
2
2
  import { islandTransformPlugin, toPosixPath } from "./islands.js";
3
3
  import { imageDimensions } from "../../fixtures/image-dimensions.js";
4
+ import { MEDIA_EXTENSIONS, fixtureMediaModule } from "../../fixtures/media-plugin.js";
4
5
  import { extname, isAbsolute, relative } from "node:path";
5
6
  import { readFile } from "node:fs/promises";
6
7
  import react from "@vitejs/plugin-react";
@@ -19,33 +20,52 @@ const RASTER_EXTENSIONS = /* @__PURE__ */ new Set([
19
20
  ".avif"
20
21
  ]);
21
22
  /**
22
- * A raster imported from a module is an OBJECT in the authoring contract (`AuthorImage`:
23
- * url, width, height, responsive) where Vite would hand back a URL string. `dev` serves
24
- * the master and derives no ladder — the ladder is the build's (`responsive: null`, the
25
- * same answer fixture media gets in `dev`). A query suffix (`?url`, `?raw`) is the
26
- * author asking Vite for the string form on purpose, and is left to Vite.
23
+ * Every asset import in the BROWSER graph, resolved exactly as the server graph resolves
24
+ * it (../../fixtures/media-plugin.ts): a raster yields the `AuthorImage` object the
25
+ * authoring contract promises, everything else its served `/fixture-media/` URL string.
26
+ *
27
+ * Left to itself Vite answers differently on both counts — it inlines a file under
28
+ * `assetsInlineLimit` as a `data:` URI and names the rest by their workspace path — and an
29
+ * island is in BOTH graphs, so a divergence is an attribute mismatch React reports on the
30
+ * island's own element at hydration. `build` has no such split (both its graphs are
31
+ * esbuild's), so this is the dev server's alone to close.
32
+ *
33
+ * What it mints is recorded in `assets`, which the server's `/fixture-media/` route reads
34
+ * alongside the server graph's index: an island declaring `serverFrame = false` is stubbed
35
+ * out of that graph, so its assets are minted only here.
36
+ *
37
+ * A query suffix (`?url`, `?raw`) is the author asking Vite for a form of their own on
38
+ * purpose, and is left to Vite.
27
39
  */
28
- function authorImagePlugin(root) {
40
+ function fixtureMediaVitePlugin(root, assets) {
29
41
  return {
30
- name: "concrete-dev:author-image",
42
+ name: "concrete-dev:fixture-media",
31
43
  enforce: "pre",
32
44
  async load(id) {
33
- if (id.includes("?") || !RASTER_EXTENSIONS.has(extname(id).toLowerCase())) return null;
34
- const bytes = await readFile(id);
35
- const url = isInside(root, id) ? `/${toPosixPath(relative(root, id))}` : `/@fs/${toPosixPath(id).replace(/^\/+/, "")}`;
36
- const size = imageDimensions(bytes) ?? {
37
- width: 0,
38
- height: 0
39
- };
40
- return `export default ${JSON.stringify({
41
- url,
42
- responsive: null,
43
- width: size.width,
44
- height: size.height
45
- })};`;
45
+ if (id.includes("?")) return null;
46
+ const ext = extname(id).toLowerCase();
47
+ if (!isInside(root, id)) return rasterFromPackage(id, ext);
48
+ if (!MEDIA_EXTENSIONS.has(ext)) return null;
49
+ const { asset, value } = fixtureMediaModule(id, await readFile(id));
50
+ assets.set(asset.url, asset);
51
+ return `export default ${JSON.stringify(value)};`;
46
52
  }
47
53
  };
48
54
  }
55
+ async function rasterFromPackage(id, ext) {
56
+ if (!RASTER_EXTENSIONS.has(ext)) return null;
57
+ const size = imageDimensions(await readFile(id)) ?? {
58
+ width: 0,
59
+ height: 0
60
+ };
61
+ const url = `/@fs/${toPosixPath(id).replace(/^\/+/, "")}`;
62
+ return `export default ${JSON.stringify({
63
+ url,
64
+ responsive: null,
65
+ width: size.width,
66
+ height: size.height
67
+ })};`;
68
+ }
49
69
  async function createDevVite(options) {
50
70
  const { root, packageRoot } = options;
51
71
  const pathsPlugin = await createTsconfigPathsPlugin(root);
@@ -60,7 +80,7 @@ async function createDevVite(options) {
60
80
  markerSpecifier: options.markerSpecifier
61
81
  }),
62
82
  react(),
63
- authorImagePlugin(root),
83
+ fixtureMediaVitePlugin(root, options.assets),
64
84
  ...pathsPlugin === null ? [] : [pathsPlugin]
65
85
  ],
66
86
  server: {
@@ -118,4 +138,4 @@ async function settleBrowserDependencies(vite, entryUrls) {
118
138
  }
119
139
 
120
140
  //#endregion
121
- export { authorImagePlugin, createDevVite, settleBrowserDependencies };
141
+ export { createDevVite, fixtureMediaVitePlugin, settleBrowserDependencies };
@@ -1,8 +1,11 @@
1
1
  import { compileFormatVariantsToCss } from "../design-system/format-variants.js";
2
2
  import { collectCssGraph } from "./graph.js";
3
3
  import { inlineCssGraph } from "./inline.js";
4
- import { externalUrlViolations, tailwindImportViolations } from "./rules.js";
4
+ import { externalUrlViolations, retiredLayerViolations, tailwindImportViolations } from "./rules.js";
5
+ import { readFileSync } from "node:fs";
6
+ import { dirname, join } from "node:path";
5
7
  import { createHash } from "node:crypto";
8
+ import { createRequire } from "node:module";
6
9
  import { compile, optimize } from "@tailwindcss/node";
7
10
  import { Scanner } from "@tailwindcss/oxide";
8
11
 
@@ -17,10 +20,26 @@ function buildTailwindEntry(inlinedCss, template) {
17
20
  if (template.output === "website") return inlinedCss;
18
21
  return `${inlinedCss.trimEnd()}\n\n${compileFormatVariantsToCss(template.formats)}`;
19
22
  }
23
+ const TAILWIND_PACKAGE = "tailwindcss";
24
+ /**
25
+ * The framework's own file for a `tailwindcss` stylesheet import — `tailwindcss` or a
26
+ * subpath such as `tailwindcss/theme.css` — read from the package's `style` export.
27
+ * Undefined for any other specifier, and for a subpath the package does not export as
28
+ * a stylesheet, which Tailwind's own resolver then reports.
29
+ */
30
+ function resolveFrameworkTailwindCss(id) {
31
+ if (id !== TAILWIND_PACKAGE && !id.startsWith(`${TAILWIND_PACKAGE}/`)) return void 0;
32
+ const manifest = createRequire(import.meta.url).resolve(`${TAILWIND_PACKAGE}/package.json`);
33
+ const { exports } = JSON.parse(readFileSync(manifest, "utf8"));
34
+ const entry = exports[id === TAILWIND_PACKAGE ? "." : `.${id.slice(11)}`];
35
+ const file = typeof entry === "string" ? entry : entry?.style;
36
+ return file === void 0 ? void 0 : join(dirname(manifest), file);
37
+ }
20
38
  async function compileTailwind(root, entry) {
21
39
  const compiler = await compile(entry, {
22
40
  base: root,
23
- onDependency: () => {}
41
+ onDependency: () => {},
42
+ customCssResolver: (id) => Promise.resolve(resolveFrameworkTailwindCss(id))
24
43
  });
25
44
  const scanner = new Scanner({ sources: [...compiler.root === "none" ? [] : compiler.root === null ? [{
26
45
  base: root,
@@ -53,12 +72,15 @@ async function compileTemplateCss(input) {
53
72
  violations: importViolations
54
73
  };
55
74
  const css = await compileTailwind(input.root, buildTailwindEntry(inlined.css, input.template));
56
- const violations = input.template.output === "website" ? [] : await externalUrlViolations({
75
+ const violations = [...await retiredLayerViolations({
76
+ root: input.root,
77
+ sources: graph
78
+ }), ...input.template.output === "website" ? [] : await externalUrlViolations({
57
79
  root: input.root,
58
80
  templateFile: input.templateFile,
59
81
  css,
60
82
  sources: graph
61
- });
83
+ })];
62
84
  const bytes = new TextEncoder().encode(css);
63
85
  const contentHash = createHash("sha256").update(bytes).digest("hex");
64
86
  return {
package/dist/css/rules.js CHANGED
@@ -24,6 +24,77 @@ function tailwindImportViolations(input) {
24
24
  message: `a second @import "tailwindcss" (the first is in ${first}). The import graph owns exactly one; remove this one.`
25
25
  }));
26
26
  }
27
+ /** The layer names the old kit's build owned. Author CSS may not declare them. */
28
+ const RETIRED_LAYERS = /* @__PURE__ */ new Set(["sections", "template"]);
29
+ /**
30
+ * `css` with comments and string literals blanked to spaces, newlines kept.
31
+ *
32
+ * Both halves are load-bearing. Every ported stylesheet explains the layer it used to
33
+ * sit in, so reading a comment as a declaration would fail the templates this rule
34
+ * exists to keep clean; and `content: "@layer template"` is a string, not a layer.
35
+ */
36
+ function maskNonCode(css) {
37
+ const out = [...css];
38
+ const blank = (from, to) => {
39
+ for (let k = from; k < Math.min(to, css.length); k += 1) if (out[k] !== "\n") out[k] = " ";
40
+ };
41
+ for (let i = 0; i < css.length;) if (css[i] === "/" && css[i + 1] === "*") {
42
+ const end = css.indexOf("*/", i + 2);
43
+ const stop = end === -1 ? css.length : end + 2;
44
+ blank(i, stop);
45
+ i = stop;
46
+ } else if (css[i] === "\"" || css[i] === "'") {
47
+ const quote = css[i];
48
+ let k = i + 1;
49
+ while (k < css.length && css[k] !== quote) k += css[k] === "\\" ? 2 : 1;
50
+ blank(i, k + 1);
51
+ i = k + 1;
52
+ } else i += 1;
53
+ return out.join("");
54
+ }
55
+ const AT_LAYER_RE = /@layer\s+([^;{]+)[;{]/gi;
56
+ const LAYER_FN_RE = /\blayer\(\s*([^)]*?)\s*\)/gi;
57
+ /** Every cascade layer a stylesheet names, root segment only (`sections.hero` → `sections`). */
58
+ function declaredLayerRoots(css) {
59
+ const source = maskNonCode(css);
60
+ const roots = [];
61
+ for (const re of [AT_LAYER_RE, LAYER_FN_RE]) {
62
+ re.lastIndex = 0;
63
+ for (let m = re.exec(source); m !== null; m = re.exec(source)) for (const name of (m[1] ?? "").split(",")) {
64
+ const root = name.trim().split(".")[0]?.trim();
65
+ if (root !== void 0 && root !== "") roots.push(root);
66
+ }
67
+ }
68
+ return roots;
69
+ }
70
+ /**
71
+ * `css/retired-layer`: author CSS declares `sections` or `template`, the layers the old
72
+ * kit's build folded hand-CSS into.
73
+ *
74
+ * Those layers ranked below `utilities`, so a declaration in one lost to any utility
75
+ * setting the same property on the same element — whatever its specificity, and
76
+ * invisibly, since the dev server served the same CSS unlayered. `base.css` no longer
77
+ * declares them, which means a stylesheet naming one now creates an IMPLICIT layer
78
+ * sorted after every declared one: the same rule would silently start winning instead.
79
+ * Either ordering is a trap, so the names are refused outright and author CSS stays
80
+ * unlayered, where what you wrote is what applies.
81
+ */
82
+ async function retiredLayerViolations(input) {
83
+ const violations = [];
84
+ for (const file of input.sources) {
85
+ const seen = /* @__PURE__ */ new Set();
86
+ for (const layer of declaredLayerRoots(await readFile(file, "utf8"))) {
87
+ if (!RETIRED_LAYERS.has(layer) || seen.has(layer)) continue;
88
+ seen.add(layer);
89
+ violations.push({
90
+ rule: "css/retired-layer",
91
+ file: workspaceRelative(input.root, file),
92
+ message: `declares @layer ${layer}, which @homepages/concrete retired. Your CSS is not layered: delete the wrapper and a plain rule outranks every utility setting the same property. To demote someone else's stylesheet instead, import it into a layer of your own naming — @import "pkg/x.css" layer(components).`
93
+ });
94
+ }
95
+ }
96
+ return violations;
97
+ }
27
98
  const EXTERNAL_RE = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
28
99
  const INLINE_RE = /^data:/i;
29
100
  const URL_FUNCTION_RE = /url\(\s*(['"]?)([^'")\s]+)\1\s*\)/gi;
@@ -62,4 +133,4 @@ async function externalUrlViolations(input) {
62
133
  }
63
134
 
64
135
  //#endregion
65
- export { externalUrlViolations, findExternalUrls, tailwindImportViolations, workspaceRelative };
136
+ export { declaredLayerRoots, externalUrlViolations, findExternalUrls, retiredLayerViolations, tailwindImportViolations, workspaceRelative };
@@ -1,6 +1,7 @@
1
1
  import { CONCRETE_RULES } from "../rules/registry.js";
2
2
  import { editorDeclaration } from "./rules/editor-declaration.js";
3
3
  import { editorReason } from "./rules/editor-reason.js";
4
+ import { islandIds } from "./rules/island-ids.js";
4
5
  import { noClientRuntime } from "./rules/no-client-runtime.js";
5
6
  import { noEditorGlobals } from "./rules/no-editor-globals.js";
6
7
  import { noHardCodedColor } from "./rules/no-hard-coded-color.js";
@@ -21,6 +22,7 @@ const AUTHORING_MODULES = {
21
22
  "concrete/islands/editor-declaration": editorDeclaration,
22
23
  "concrete/islands/editor-reason": editorReason,
23
24
  "concrete/islands/no-editor-globals": noEditorGlobals,
25
+ "concrete/islands/island-ids": islandIds,
24
26
  "concrete/slots/no-marker-literal": noMarkerLiteral,
25
27
  "concrete/slots/no-raw-values": noRawValues,
26
28
  "concrete/style/no-hard-coded-color": noHardCodedColor,
@@ -0,0 +1,39 @@
1
+ import { hasClientDirective } from "../../islands/client-module.js";
2
+
3
+ //#region src/eslint/rules/island-ids.ts
4
+ /** The call this node makes, by the name being called — `React.useId()` counts as `useId`. */
5
+ function calledName(callee) {
6
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") return callee.property.name;
7
+ return callee.type === "Identifier" ? callee.name : null;
8
+ }
9
+ const islandIds = {
10
+ meta: {
11
+ type: "problem",
12
+ docs: { description: "An island's own ids come from useIslandId, and only an island's do" },
13
+ schema: [],
14
+ messages: {
15
+ islandUseId: "`useId` returns a different id in this island's server render and its browser hydration, so markup carrying one hydrates into an attribute mismatch — reported in the console, on published pages too. Fix: compose the id from `useIslandId()` (`@homepages/concrete`), which is the id the server minted for this island, read back from its marker in the browser: ``const bodyId = `${useIslandId()}-body`;``.",
16
+ sectionIslandId: "`useIslandId` answers with an island's id, and server-rendered code is not inside one — it would hand back the same constant for every instance of this section on a page, which is a duplicate id. Fix: this markup renders once and hydrates never, so give it an id from what already distinguishes it (a slot id, a row key, `nav.selfAnchor`), and pass that to an island as a prop if the island needs it."
17
+ }
18
+ },
19
+ create(context) {
20
+ const sourceCode = context.sourceCode;
21
+ const inIsland = hasClientDirective(sourceCode.getText());
22
+ const banned = inIsland ? "useId" : "useIslandId";
23
+ const messageId = inIsland ? "islandUseId" : "sectionIslandId";
24
+ return { CallExpression(node) {
25
+ if (calledName(node.callee) !== banned) return;
26
+ if (node.callee.type === "Identifier") {
27
+ const ref = sourceCode.getScope(node).references.find((r) => r.identifier === node.callee);
28
+ if (ref?.resolved && ref.resolved.defs.some((d) => d.type !== "ImportBinding")) return;
29
+ }
30
+ context.report({
31
+ node,
32
+ messageId
33
+ });
34
+ } };
35
+ }
36
+ };
37
+
38
+ //#endregion
39
+ export { islandIds };
@@ -79,6 +79,35 @@ function fixtureMediaUrl(path, bytes) {
79
79
  const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 8);
80
80
  return `${FIXTURE_MEDIA_PATH}/${basename(path, ext)}-${hash}${ext.toLowerCase()}`;
81
81
  }
82
+ /** Every extension a media import can name — the ambient shim's list, spelled once in MEDIA_LOADERS. */
83
+ const MEDIA_EXTENSIONS = new Set(Object.keys(MEDIA_LOADERS));
84
+ /**
85
+ * What a media import evaluates to, and the asset it stands for. THE one spelling of the
86
+ * two lanes: `concrete dev` runs a workspace through two module graphs — esbuild for the
87
+ * server, Vite for the islands — and an island is in BOTH, so an import that evaluates
88
+ * differently in each hydrates into an attribute mismatch on the element carrying it.
89
+ * Both graphs' plugins resolve through here so there is nothing for them to disagree on.
90
+ */
91
+ function fixtureMediaModule(path, bytes) {
92
+ const url = fixtureMediaUrl(path, bytes);
93
+ const derived = DERIVED_EXTENSIONS.has(extname(path).toLowerCase());
94
+ return {
95
+ asset: {
96
+ url,
97
+ path,
98
+ bytes: bytes.byteLength,
99
+ derived
100
+ },
101
+ value: derived ? {
102
+ url,
103
+ responsive: null,
104
+ ...imageDimensions(bytes) ?? {
105
+ width: 0,
106
+ height: 0
107
+ }
108
+ } : url
109
+ };
110
+ }
82
111
  /** A fresh plugin per pass; `assets` is what the pass recorded. */
83
112
  function createFixtureMediaPlugin(root) {
84
113
  const assets = /* @__PURE__ */ new Map();
@@ -109,22 +138,8 @@ function createFixtureMediaPlugin(root) {
109
138
  namespace: NAMESPACE
110
139
  }, async (args) => {
111
140
  const bytes = await readFile(args.path);
112
- const url = fixtureMediaUrl(args.path, bytes);
113
- const derived = DERIVED_EXTENSIONS.has(extname(args.path).toLowerCase());
114
- assets.set(url, {
115
- url,
116
- path: args.path,
117
- bytes: bytes.byteLength,
118
- derived
119
- });
120
- const value = derived ? {
121
- url,
122
- responsive: null,
123
- ...imageDimensions(bytes) ?? {
124
- width: 0,
125
- height: 0
126
- }
127
- } : url;
141
+ const { asset, value } = fixtureMediaModule(args.path, bytes);
142
+ assets.set(asset.url, asset);
128
143
  return {
129
144
  contents: `export default ${JSON.stringify(value)};`,
130
145
  loader: "js",
@@ -138,4 +153,4 @@ function createFixtureMediaPlugin(root) {
138
153
  }
139
154
 
140
155
  //#endregion
141
- export { FIXTURE_MEDIA_PATH, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace, fixtureMediaUrl };
156
+ export { FIXTURE_MEDIA_PATH, MEDIA_EXTENSIONS, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace, fixtureMediaModule, fixtureMediaUrl };
@@ -1,3 +1,5 @@
1
+ import { tourEmbedUrl, videoEmbedUrl } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
+
1
3
  //#region src/fixtures/media.ts
2
4
  const clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
3
5
  /**
@@ -82,7 +84,7 @@ function videoValue(entry, resolver) {
82
84
  const poster = posterOf(entry, resolver);
83
85
  if (entry.file === null) return {
84
86
  video_id: entry.id,
85
- url: entry.url ?? "",
87
+ url: videoEmbedUrl(entry.url ?? "") ?? "",
86
88
  ...poster,
87
89
  alt: entry.alt,
88
90
  source: "link",
@@ -99,7 +101,7 @@ function videoValue(entry, resolver) {
99
101
  function tourValue(entry, resolver) {
100
102
  return {
101
103
  tour_id: entry.id,
102
- url: entry.url ?? "",
104
+ url: tourEmbedUrl(entry.url ?? "") ?? "",
103
105
  ...posterOf(entry, resolver),
104
106
  alt: entry.alt,
105
107
  ...entry.provider === null ? {} : { provider: entry.provider }
@@ -3,6 +3,16 @@ import "../packages/internal/property-facts/dist/index.js";
3
3
  import { basename, extname } from "node:path";
4
4
 
5
5
  //#region src/fixtures/property.ts
6
+ /**
7
+ * The id a contact's image takes. A contact card's avatar and logos are uploads like any
8
+ * other, but the platform holds them on the card rather than in a pool, so a fixture's
9
+ * property has no entry to carry their id and this mints one. The resolver mints the
10
+ * same id when a content entry states the image (a `ContactImageEntry`), which is why
11
+ * both go through here.
12
+ */
13
+ function contactImageId(contactId, field) {
14
+ return `contact:${contactId}:${field}`;
15
+ }
6
16
  const MIME_BY_EXTENSION = {
7
17
  ".pdf": "application/pdf",
8
18
  ".mp4": "video/mp4",
@@ -165,7 +175,7 @@ function canonicalizeProperty(property, file) {
165
175
  const image = (value, field) => {
166
176
  if (value === null || value === void 0) return null;
167
177
  if (!admitFile(value, `${path}.${field}`)) return null;
168
- const id = `contact:${contact.id}:${field}`;
178
+ const id = contactImageId(contact.id, field);
169
179
  media.set(id, entry(id, "image", value, contact.name ?? ""));
170
180
  return id;
171
181
  };
@@ -228,4 +238,4 @@ function entry(id, kind, file, alt) {
228
238
  }
229
239
 
230
240
  //#endregion
231
- export { canonicalizeProperty, mediaUrl };
241
+ export { canonicalizeProperty, contactImageId, mediaUrl };
@@ -4,8 +4,8 @@ import { buildDeriveFactsView } from "../packages/internal/property-facts/dist/d
4
4
  import { bakeDisplayEntries, bakePropertyRefSlots } from "../packages/internal/fill-bake/dist/bake-property-ref.js";
5
5
  import { applyReconcile } from "../packages/internal/fill-bake/dist/reconcile-cross-section.js";
6
6
  import "../packages/internal/fill-bake/dist/index.js";
7
- import { canonicalizeProperty } from "./property.js";
8
- import { canonicalizeRows } from "./rows.js";
7
+ import { canonicalizeProperty, contactImageId } from "./property.js";
8
+ import { blankForField, canonicalizeRows } from "./rows.js";
9
9
 
10
10
  //#region src/fixtures/resolve.ts
11
11
  const MEDIA_KINDS = /* @__PURE__ */ new Set([
@@ -125,7 +125,13 @@ function resolveInstance(placement, entry, ctx) {
125
125
  if (gate !== void 0 && (variant === void 0 || !gate.includes(variant))) continue;
126
126
  const source = def.source;
127
127
  if (source?.kind === "direct" && typeof source.field === "string") {
128
- slots[id] = baked[id] ?? null;
128
+ const rows = baked[id] ?? null;
129
+ const fields = def.type === "list" ? def.fields : void 0;
130
+ slots[id] = fields === void 0 ? rows : enrichedRows(fields, rows, values[id], {
131
+ ...ctx,
132
+ instance: placement.instance,
133
+ slot: id
134
+ });
129
135
  provenance[id] = {
130
136
  kind: "fact",
131
137
  ref: source.field
@@ -164,6 +170,34 @@ function resolveInstance(placement, entry, ctx) {
164
170
  provenance
165
171
  };
166
172
  }
173
+ function enrichedRows(fields, baked, stated, ctx) {
174
+ if (!Array.isArray(baked)) return baked;
175
+ const bakedRows = baked;
176
+ const statedRows = Array.isArray(stated) ? stated : [];
177
+ if (statedRows.length > bakedRows.length) ctx.violations.push({
178
+ rule: "fixtures/rows-not-in-property",
179
+ file: ctx.module,
180
+ message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} states ${String(statedRows.length)} rows, but its property carries ${String(bakedRows.length)} — the rows of a bound list are the property's`
181
+ });
182
+ const blanks = {};
183
+ for (const [field, fieldDef] of Object.entries(fields)) if (fieldDef.source === void 0) blanks[field] = blankForField(fieldDef);
184
+ return bakedRows.map((row, index) => {
185
+ if (typeof row !== "object" || row === null) return row;
186
+ const out = {
187
+ ...blanks,
188
+ ...row
189
+ };
190
+ const statedRow = statedRows[index];
191
+ if (typeof statedRow !== "object" || statedRow === null || Array.isArray(statedRow)) return out;
192
+ for (const [field, fieldDef] of Object.entries(fields)) {
193
+ if (fieldDef.source !== void 0) continue;
194
+ const value = statedRow[field];
195
+ if (value === void 0 || value === null) continue;
196
+ out[field] = authoredValue(fieldDef, value, ctx);
197
+ }
198
+ return out;
199
+ });
200
+ }
167
201
  function authoredValue(def, value, ctx) {
168
202
  if (MEDIA_KINDS.has(def.type)) return mediaRef(def.type, value, ctx);
169
203
  if (def.type === "list") {
@@ -184,14 +218,33 @@ function authoredValue(def, value, ctx) {
184
218
  }
185
219
  return value;
186
220
  }
221
+ const CONTACT_IMAGE_FIELDS = /* @__PURE__ */ new Set([
222
+ "avatar",
223
+ "logo_dark",
224
+ "logo_light"
225
+ ]);
226
+ function contactImage(value) {
227
+ if (typeof value !== "object" || value === null) return null;
228
+ const { contact, field } = value;
229
+ if (typeof field !== "string" || !CONTACT_IMAGE_FIELDS.has(field)) return null;
230
+ const contactId = typeof contact === "object" && contact !== null ? contact.id : void 0;
231
+ if (typeof contactId !== "string") return null;
232
+ return {
233
+ id: contactImageId(contactId, field),
234
+ contact: contactId,
235
+ field
236
+ };
237
+ }
187
238
  function mediaRef(kind, value, ctx) {
188
- const id = typeof value === "object" && value !== null ? value.id : void 0;
239
+ const stated = kind === "image" ? contactImage(value) : null;
240
+ const id = stated?.id ?? (typeof value === "object" && value !== null ? value.id : void 0);
189
241
  const carried = typeof id === "string" ? ctx.media.get(id) : void 0;
190
242
  if (carried === void 0 || carried.kind !== kind) {
243
+ const what = stated !== null ? `the "${stated.field}" of contact "${stated.contact}", which its property does not carry` : typeof id === "string" ? `${kind} "${id}", which its property does not carry` : `a value that is not a ${kind} entry of its property`;
191
244
  ctx.violations.push({
192
245
  rule: "fixtures/media-not-in-property",
193
246
  file: ctx.module,
194
- message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} references ` + (typeof id === "string" ? `${kind} "${id}", which its property does not carry` : `a value that is not a ${kind} entry of its property`)
247
+ message: `fixture "${ctx.fixtureId}": "${ctx.instance}".${ctx.slot} references ${what}`
195
248
  });
196
249
  return null;
197
250
  }
@@ -63,6 +63,11 @@ function blankCollectionRow(collection, facts, rowFields) {
63
63
  };
64
64
  return COLLECTION_PROJECTIONS[collection](oneEmptyRow, rowFields)[0] ?? {};
65
65
  }
66
+ /**
67
+ * The per-kind blank of one declared row field — the same canonical form the binding
68
+ * layer normalizes an unfilled value to. Kept to the kinds a row field may take (a
69
+ * record cannot nest inside a record).
70
+ */
66
71
  function blankForField(def) {
67
72
  switch (def.type) {
68
73
  case "text":
@@ -105,4 +110,4 @@ function canonicalizeRows(slot, value, facts, rowFields) {
105
110
  }
106
111
 
107
112
  //#endregion
108
- export { canonicalizeRows };
113
+ export { blankForField, canonicalizeRows };
@@ -156,12 +156,40 @@ type SlotsOf<S> = S extends {
156
156
  type ContentRow<I> = {
157
157
  readonly id?: string;
158
158
  } & { readonly [K in keyof I]?: ContentSlotValue<I[K]> | null; };
159
+ /** Which of a contact card's three images a {@link ContactImageEntry} names. */
160
+ type ContactImageField = "avatar" | "logo_dark" | "logo_light";
161
+ /**
162
+ * One of a contact's images, stated as the card of the fixture's property plus the field:
163
+ * `{ contact: listingAgent, field: "logo_dark" }`. A contact's avatar and logos are image
164
+ * media like any other, but the platform holds them on the card rather than in a pool, so
165
+ * they have no entry of their own to state — this names the same image the resolver
166
+ * registers, and it resolves to the `{ asset_id }` a `contactAssign` fill bakes for that
167
+ * field. A contact the property does not carry, or a field it holds `null`, is a check
168
+ * error like any other media the property lacks.
169
+ */
170
+ interface ContactImageEntry {
171
+ readonly contact: ContactEntry;
172
+ readonly field: ContactImageField;
173
+ }
174
+ /**
175
+ * The fields of a record list a content entry may state: the ones carrying no `source:`
176
+ * of their own.
177
+ *
178
+ * @remarks
179
+ * On an unbound list every field qualifies, so this is the identity — a per-field
180
+ * source is only legal on a fact-bound list at all (`assertSourceContract`). On a
181
+ * COLLECTION-bound list it is the enriched half: the fields a `list-fill` writes onto
182
+ * rows the facts originate, which is exactly what a fixture states there
183
+ * ({@link ContentSlots}).
184
+ */
185
+ type RowFillFields<I> = { [K in keyof I as I[K] extends {
186
+ source: unknown;
187
+ } ? never : K]: I[K]; };
159
188
  /**
160
189
  * An entry a content doc may state on an `image` slot: every property entry the resolver
161
- * registers as image media — a photo or a floor plan. A contact's avatar and logos are
162
- * image media too, but under minted ids with no entry of their own, so none is stateable.
190
+ * registers as image media — a photo, a floor plan, or one of a contact's images.
163
191
  */
164
- type ImageEntry = PhotoEntry | FloorPlanEntry;
192
+ type ImageEntry = PhotoEntry | FloorPlanEntry | ContactImageEntry;
165
193
  /**
166
194
  * The value one slot takes in a content entry: a media slot takes an entry of the
167
195
  * fixture's property, a list of them an array, a record list its rows, a points-of-
@@ -181,18 +209,31 @@ type ContentSlotValue<S> = S extends {
181
209
  } ? PoiRow : S extends {
182
210
  type: "list";
183
211
  fields: infer I;
184
- } ? readonly ContentRow<I>[] : S extends {
212
+ } ? readonly ContentRow<RowFillFields<I>>[] : S extends {
185
213
  type: "list";
186
214
  element: infer E;
187
215
  } ? readonly NonNullable<ContentSlotValue<E>>[] : SlotValue<S>;
188
216
  /**
189
- * The slots a content entry may state: every declared slot EXCEPT the source-bound
190
- * ones, each optional. A fact-bound or computed slot resolves from the property and is
191
- * never stated, so naming one is a compile error.
217
+ * The slots a content entry may state: every declared slot except the source-bound
218
+ * ones, each optional — plus the one source-bound slot a fill does write, a record
219
+ * list bound to a collection.
220
+ *
221
+ * @remarks
222
+ * A fact-bound or computed slot resolves from the property and is never stated, so
223
+ * naming one is a compile error. A record list bound to a collection is the exception,
224
+ * and it is the platform's own shape rather than a loophole: the fill originates its
225
+ * rows from the facts (`mode: "facts"`) and then plans the fields that carry no
226
+ * `source:` onto them in one batched call, merging both halves into a single stored row
227
+ * (`enrichRef` in `@homepages/fill-bake`). A fixture states that enriched half and
228
+ * nothing else — {@link RowFillFields} drops the baked fields from the row type, and
229
+ * the resolver merges what is stated onto the baked rows by position.
192
230
  */
193
231
  type ContentSlots<Slots> = { readonly [K in keyof Slots as Slots[K] extends {
194
232
  source: unknown;
195
- } ? never : K]?: ContentSlotValue<Slots[K]> | null; };
233
+ } ? Slots[K] extends {
234
+ type: "list";
235
+ fields: unknown;
236
+ } ? K : never : K]?: ContentSlotValue<Slots[K]> | null; };
196
237
  type VariantOf<S> = S extends {
197
238
  readonly schema: {
198
239
  readonly meta: infer Meta;
@@ -223,14 +264,18 @@ type ExactContent<M, Allowed> = M & Allowed & { [K in Exclude<keyof M, keyof All
223
264
  /**
224
265
  * State the content a fill would generate for one placed instance of a section: its
225
266
  * generative slots and its display state, typed by the section value. A fact-bound or
226
- * computed slot is never stated here — derived information is taken from the property.
267
+ * computed slot is never stated here — derived information is taken from the property —
268
+ * with one exception in the platform's own image: a record list bound to a collection
269
+ * takes the fields of each row a fill enriches, stated row by row in the property's own
270
+ * order, while the row's bound fields stay the bake's.
227
271
  * Media is stated by value, as an entry of the fixture's property (`hero_image:
228
272
  * deckShot`), of the slot's own kind; an entry the property does not carry is a check
229
- * error. A second placed instance names itself with `instance`, the same id the
230
- * placement wrote.
273
+ * error. A contact's image, which has no entry, is stated as the card plus the field
274
+ * ({@link ContactImageEntry}). A second placed instance names itself with `instance`,
275
+ * the same id the placement wrote.
231
276
  */
232
277
  declare function content<S extends SectionRef, M extends object>(section: S, values: ExactContent<M, ContentValuesOf<S>>, options?: {
233
278
  readonly instance?: string;
234
279
  }): ContentEntry<S>;
235
280
  //#endregion
236
- export { ContactEntry, ContentDisplay, ContentEntry, ContentRow, ContentSlotValue, ContentSlots, ContentValues, ContentValuesOf, DocumentEntry, ExactContent, Fixture, FixtureSpec, FloorPlanEntry, ImageEntry, LinkVideoEntry, MediaFile, PhotoEntry, Property, SectionRef, TourEntry, UploadVideoEntry, VideoEntry, content, defineFixture };
281
+ export { ContactEntry, ContactImageEntry, ContactImageField, ContentDisplay, ContentEntry, ContentRow, ContentSlotValue, ContentSlots, ContentValues, ContentValuesOf, DocumentEntry, ExactContent, Fixture, FixtureSpec, FloorPlanEntry, ImageEntry, LinkVideoEntry, MediaFile, PhotoEntry, Property, RowFillFields, SectionRef, TourEntry, UploadVideoEntry, VideoEntry, content, defineFixture };
package/dist/fixtures.js CHANGED
@@ -15,11 +15,15 @@ function defineFixture(spec) {
15
15
  /**
16
16
  * State the content a fill would generate for one placed instance of a section: its
17
17
  * generative slots and its display state, typed by the section value. A fact-bound or
18
- * computed slot is never stated here — derived information is taken from the property.
18
+ * computed slot is never stated here — derived information is taken from the property —
19
+ * with one exception in the platform's own image: a record list bound to a collection
20
+ * takes the fields of each row a fill enriches, stated row by row in the property's own
21
+ * order, while the row's bound fields stay the bake's.
19
22
  * Media is stated by value, as an entry of the fixture's property (`hero_image:
20
23
  * deckShot`), of the slot's own kind; an entry the property does not carry is a check
21
- * error. A second placed instance names itself with `instance`, the same id the
22
- * placement wrote.
24
+ * error. A contact's image, which has no entry, is stated as the card plus the field
25
+ * ({@link ContactImageEntry}). A second placed instance names itself with `instance`,
26
+ * the same id the placement wrote.
23
27
  */
24
28
  function content(section, values, options = {}) {
25
29
  const stated = values;