@homepages/concrete 6.0.1 → 6.2.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.
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Playground</title>
7
- <script type="module" crossorigin src="./assets/index-u3T7DiSN.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-Cqz-jjVw.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="./assets/index-CckS2ONm.css">
9
9
  </head>
10
10
  <body>
@@ -156,16 +156,36 @@ function resolveInstance(placement, entry, ctx) {
156
156
  const resolvedDisplay = bakeDisplayEntries({ display }, ctx.facts, bakeCtx);
157
157
  const computeFns = getComputed(schema);
158
158
  const factsView = buildDeriveFactsView(ctx.facts);
159
+ const values = entry?.values ?? {};
160
+ const slotPass = {
161
+ placement,
162
+ values,
163
+ baked,
164
+ computeFns,
165
+ factsView
166
+ };
167
+ let ungated;
159
168
  for (const [entryName, entryDef] of Object.entries(display)) {
160
169
  const reads = declaredReads(entryDef?.source);
161
170
  const transform = entryDef?.source?.transform;
162
171
  if (reads.length === 0 || typeof transform !== "string") continue;
163
- const answered = runDeclared(computeFns, transform, valuesFor(reads, factsView, ctx.settled));
172
+ let own;
173
+ if (reads.some((ref) => ref.kind !== "fact" && ref.section === section.key)) {
174
+ ungated ??= buildSlots(slotPass, {
175
+ ...ctx,
176
+ violations: [],
177
+ log: void 0
178
+ }, null).slots;
179
+ own = {
180
+ section: section.key,
181
+ slots: ungated
182
+ };
183
+ }
184
+ const answered = runDeclared(computeFns, transform, valuesFor(reads, factsView, ctx.settled, own));
164
185
  const answer = typeof answered?.value === "string" ? answered.value : "";
165
186
  if (entryDef?.cases?.includes(answer) === true) resolvedDisplay[entryName] = answer;
166
187
  else delete resolvedDisplay[entryName];
167
188
  }
168
- const values = entry?.values ?? {};
169
189
  const visibility = resolvedDisplay.visibility ?? display.visibility?.cases?.[0];
170
190
  const enabled = typeof values.enabled === "boolean" ? values.enabled : visibility === void 0 ? true : visibility !== "hidden";
171
191
  const declaredCases = display.variant?.cases;
@@ -174,12 +194,32 @@ function resolveInstance(placement, entry, ctx) {
174
194
  if (declaredCases?.includes(values.variant) !== true) throw new Error(`Fixture "${ctx.fixtureId}" (${ctx.module}): content for "${placement.instance}" names variant "${values.variant}", which section "${section.key}" does not declare.`);
175
195
  variant = values.variant;
176
196
  }
197
+ const { slots, provenance } = buildSlots(slotPass, ctx, { variant });
198
+ return {
199
+ instance: {
200
+ instance_id: placement.instance,
201
+ section_key: section.key,
202
+ enabled,
203
+ ...variant === void 0 ? {} : { variant },
204
+ slots
205
+ },
206
+ provenance,
207
+ settled: {
208
+ slots,
209
+ visibility: resolvedDisplay.visibility ?? display.visibility?.cases?.[0],
210
+ variant
211
+ }
212
+ };
213
+ }
214
+ function buildSlots(pass, ctx, gate) {
215
+ const { placement, values, baked, computeFns, factsView } = pass;
216
+ const section = placement.section;
177
217
  const slots = {};
178
218
  const provenance = {};
179
219
  const declared = /* @__PURE__ */ new Map();
180
- for (const [id, def] of Object.entries(schema.slots)) {
181
- const gate = def.variant?.cases;
182
- if (gate !== void 0 && (variant === void 0 || !gate.includes(variant))) continue;
220
+ for (const [id, def] of Object.entries(section.schema.slots)) {
221
+ const cases = def.variant?.cases;
222
+ if (gate !== null && cases !== void 0 && (gate.variant === void 0 || !cases.includes(gate.variant))) continue;
183
223
  const source = def.source;
184
224
  if (source?.kind === "direct" && typeof source.field === "string") {
185
225
  const rows = baked[id] ?? null;
@@ -228,19 +268,8 @@ function resolveInstance(placement, entry, ctx) {
228
268
  };
229
269
  for (const [id, slot] of sameSectionOrder(section.key, declared)) slots[id] = runDeclared(computeFns, slot.transform, valuesFor(slot.reads, factsView, ctx.settled, own))?.value ?? emptyValueFor(slot.type);
230
270
  return {
231
- instance: {
232
- instance_id: placement.instance,
233
- section_key: section.key,
234
- enabled,
235
- ...variant === void 0 ? {} : { variant },
236
- slots
237
- },
238
- provenance,
239
- settled: {
240
- slots,
241
- visibility: resolvedDisplay.visibility ?? display.visibility?.cases?.[0],
242
- variant
243
- }
271
+ slots,
272
+ provenance
244
273
  };
245
274
  }
246
275
  function enrichedRows(fields, baked, stated, ctx) {
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "6.0.1";
2
+ var version = "6.2.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,9 +1,10 @@
1
1
  //#region ../../internal/section-contracts/dist/display-evidence-contract.js
2
2
  function assertDisplayEvidenceContract(schema, fillSpec, sectionKey) {
3
3
  if ((fillSpec.reads ?? []).length > 0) return;
4
+ if ((fillSpec.decisions.find((decision) => decision.kind === "display")?.reads ?? []).length > 0) return;
4
5
  for (const [entryKey, entry] of Object.entries(schema.display ?? {})) {
5
6
  if (entry?.fill === void 0) continue;
6
- throw new Error(`Section "${sectionKey}": display ${entryKey}'s \`pick\` names no evidence — its fill reads nothing, and a fill is shown exactly its \`reads\`. Declare the fact it judges (\`reads: [fact.contact.website]\`).`);
7
+ throw new Error(`Section "${sectionKey}": display ${entryKey}'s \`pick\` names no evidence — its fill reads nothing, and a fill is shown exactly its \`reads\`. Declare the fact or slot it judges (\`reads: [fact.contact.website]\`).`);
7
8
  }
8
9
  }
9
10
 
@@ -1,8 +1,8 @@
1
1
  import { COMPUTED, isComputeBinding } from "./compute.js";
2
2
  import { isFillBinding } from "./fill-builders.js";
3
- import { fillMark } from "./fill-declaration.js";
3
+ import { FILL, FILL_SECTION, fillMark, getFill } from "./fill-declaration.js";
4
4
  import { groupsFromLayout } from "./layout.js";
5
- import { isSiblingSlot, serializeRef } from "./slot-ref.js";
5
+ import { isSiblingSlot, isSlotRef, serializeRef } from "./slot-ref.js";
6
6
 
7
7
  //#region src/schema/define-schema.ts
8
8
  function derivedSource(transform, reads) {
@@ -29,21 +29,42 @@ function siblingResolver(sectionKey, slots) {
29
29
  };
30
30
  });
31
31
  }
32
- function emitDisplay(display, computed) {
32
+ function resolveBindingReads(at, binding, resolveReads) {
33
+ const reads = binding?.reads;
34
+ if (binding === void 0 || reads === void 0 || !reads.some(isSiblingSlot)) return binding;
35
+ const resolved = resolveReads(at, reads) ?? [];
36
+ const upstream = resolved[reads.findIndex((read) => isSiblingSlot(read) && read.source !== void 0)];
37
+ if (upstream !== void 0 && isSlotRef(upstream)) throw new Error(`\`${at}\` is filled and reads its sibling slot "${upstream.slot}", which is sourced — a fact, a \`compute()\` or another slot settles it, not a fill. A sourced value settles at finalize, AFTER every fill has run, so the fill would read nothing. Read the refs that slot reads instead, or read a slot a fill writes.`);
38
+ const sibling = resolved[reads.findIndex(isSiblingSlot)];
39
+ const section = sibling !== void 0 && isSlotRef(sibling) ? sibling.section : void 0;
40
+ return {
41
+ ...binding,
42
+ reads: resolved,
43
+ [FILL_SECTION]: section
44
+ };
45
+ }
46
+ function resolveFillReads(at, slot, resolveReads) {
47
+ const binding = getFill(slot);
48
+ const resolved = resolveBindingReads(at, binding, resolveReads);
49
+ return resolved === binding ? slot : {
50
+ ...slot,
51
+ [FILL]: resolved
52
+ };
53
+ }
54
+ function emitDisplay(display, computed, resolveReads) {
33
55
  const out = {};
34
56
  for (const key of ["visibility", "variant"]) {
35
57
  const entry = display[key];
36
58
  if (entry === void 0) continue;
59
+ const at = `display.${key}`;
37
60
  const emitted = { cases: [...entry.cases] };
38
61
  if (entry.locked === true) emitted.locked = true;
39
62
  if (isComputeBinding(entry.source)) {
40
- const sibling = entry.source.reads?.find(isSiblingSlot);
41
- if (sibling !== void 0) throw new Error(`\`display.${key}\` reads the section's own slot "${sibling.label}". A display entry settles which of the section's slots exist, so it may read facts and other sections only.`);
42
- computed[`display.${key}`] = entry.source.fn;
43
- emitted.source = derivedSource(`display.${key}`, entry.source.reads);
63
+ computed[at] = entry.source.fn;
64
+ emitted.source = derivedSource(at, resolveReads(at, entry.source.reads));
44
65
  } else if (isFillBinding(entry.source)) emitted.fill = {
45
66
  pick: entry.source.brief,
46
- ...fillMark(entry.source)
67
+ ...fillMark(resolveBindingReads(at, entry.source, resolveReads))
47
68
  };
48
69
  else if (entry.source !== void 0) emitted.source = entry.source;
49
70
  out[key] = emitted;
@@ -52,16 +73,24 @@ function emitDisplay(display, computed) {
52
73
  }
53
74
  function defineSchema(input) {
54
75
  const computed = {};
76
+ const resolveReads = siblingResolver(input.key, input.slots);
55
77
  const meta = {
56
78
  displayName: input.label,
57
79
  ...input.anchor !== void 0 ? { anchor: input.anchor } : {},
58
- ...input.display !== void 0 ? { display: emitDisplay(input.display, computed) } : {},
80
+ ...input.display !== void 0 ? { display: emitDisplay(input.display, computed, resolveReads) } : {},
59
81
  ...input.layout !== void 0 ? { groups: groupsFromLayout(input.layout) } : {}
60
82
  };
61
83
  const slots = {};
62
- const resolveReads = siblingResolver(input.key, input.slots);
63
84
  for (const [key, slot] of Object.entries(input.slots)) {
64
- let emitted = slot;
85
+ let emitted = resolveFillReads(key, slot, resolveReads);
86
+ const fields = emitted.fields;
87
+ if (emitted.type === "list" && fields !== void 0) {
88
+ const resolvedFields = Object.fromEntries(Object.entries(fields).map(([field, def]) => [field, resolveFillReads(`${key}.${field}`, def, resolveReads)]));
89
+ if (Object.keys(fields).some((field) => resolvedFields[field] !== fields[field])) emitted = {
90
+ ...emitted,
91
+ fields: resolvedFields
92
+ };
93
+ }
65
94
  if (isComputeBinding(slot.source)) {
66
95
  computed[key] = slot.source.fn;
67
96
  emitted = {
@@ -1,6 +1,6 @@
1
1
  import { DISPLAY_ENTRIES } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
- import { getFill } from "./fill-declaration.js";
3
- import { serializeRef } from "./slot-ref.js";
2
+ import { getFill, getFillSection } from "./fill-declaration.js";
3
+ import { isSiblingSlot, serializeRef } from "./slot-ref.js";
4
4
  import { byCodeUnit } from "../platform/order.js";
5
5
  import { plannerForField } from "../packages/internal/fill-vocabulary/dist/row-planners.js";
6
6
  import { isListSlot, originationFor } from "../packages/internal/fill-vocabulary/dist/origination.js";
@@ -23,11 +23,15 @@ function optionsOf(binding) {
23
23
  return out;
24
24
  }
25
25
  function serializedReads(reads) {
26
- return (reads ?? []).map(serializeRef);
26
+ return (reads ?? []).map((read) => {
27
+ if (isSiblingSlot(read)) throw new Error(`fillSpecFromSchema: a fill reads the slot "${read.label}" by its const, which only a section declared with \`section()\` resolves — read another section's slot through its ref (\`Section.slots.<key>\`).`);
28
+ return serializeRef(read);
29
+ });
27
30
  }
28
31
  function collectReads(into, binding) {
32
+ const ownSection = getFillSection(binding);
29
33
  for (const read of serializedReads(binding?.reads)) if (read.kind === "fact") into.facts.add(read.key);
30
- else into.slots.set(`${read.section} ${read.slot}`, read);
34
+ else if (read.section !== ownSection) into.slots.set(`${read.section} ${read.slot}`, read);
31
35
  }
32
36
  function editorPickedOrigin(slot) {
33
37
  return slot.type === "poi";
@@ -1,4 +1,4 @@
1
- import { Ref } from "./slot-ref.js";
1
+ import { ComputeRead } from "./slot-ref.js";
2
2
  //#region src/schema/fill-builders.d.ts
3
3
  /**
4
4
  * How many items a list fill produces.
@@ -50,10 +50,12 @@ type FillInput<Legal extends FillOptionName = FillOptionName> = {
50
50
  readonly brief: string;
51
51
  /**
52
52
  * Exactly what the model sees beside the brief: fact refs (`fact.property.address`,
53
- * `fact.description`) and slot refs of other sections (`Hero.slots.headline`).
54
- * A pick's candidates come from the slot's own pool and need no read.
53
+ * `fact.description`), slot refs of other sections (`Hero.slots.headline`), and a
54
+ * sibling slot of the same section by its own const — read the way a `compute()`
55
+ * reads one, and filled first. A pick's candidates come from the slot's own pool
56
+ * and need no read.
55
57
  */
56
- readonly reads?: readonly Ref[];
58
+ readonly reads?: readonly ComputeRead[];
57
59
  } & { readonly [K in Legal]?: FillOptionTypes[K]; } & { readonly [K in Exclude<FillOptionName, Legal>]?: never; };
58
60
  /**
59
61
  * A fill as a slot's `source:` holds it — what `fill()` returns. `O` is the input
@@ -5,10 +5,14 @@ const FILL = Symbol.for("@homepages/concrete:fill:declaration");
5
5
  function fillMark(source) {
6
6
  return isFillBinding(source) ? { [FILL]: source } : {};
7
7
  }
8
+ const FILL_SECTION = Symbol.for("@homepages/concrete:fill:section");
9
+ function getFillSection(binding) {
10
+ return binding?.[FILL_SECTION];
11
+ }
8
12
  function getFill(slot) {
9
13
  if (typeof slot !== "object" || slot === null) return void 0;
10
14
  return slot[FILL];
11
15
  }
12
16
 
13
17
  //#endregion
14
- export { FILL, fillMark, getFill };
18
+ export { FILL, FILL_SECTION, fillMark, getFill, getFillSection };
@@ -40,7 +40,7 @@ interface FactRef<Key extends string = string, Value = unknown> {
40
40
  type Ref = FactRef | SlotRef;
41
41
  /** A slot of the declaring section, named by its own const — see the module header. */
42
42
  type SiblingSlot = Slot;
43
- /** What a `compute`'s `reads` (and a mirror's `source:`) may name: any ref, or a sibling slot. */
43
+ /** What a `compute`'s or a fill's `reads` (and a mirror's `source:`) may name: any ref, or a sibling slot. */
44
44
  type ComputeRead = Ref | SiblingSlot;
45
45
  /** The value a ref refers to, read off the phantom member. */
46
46
  type RefValue<R> = R extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homepages/concrete",
3
- "version": "6.0.1",
3
+ "version": "6.2.0",
4
4
  "description": "Concrete, the HomePages template framework: the authoring API, the contract primitives, the styles, the lint preset and the `concrete` command in one package that owns its whole toolchain.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",