@homepages/concrete 6.1.0 → 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.
- package/CHANGELOG.md +33 -0
- package/codemods/manifest.json +4 -0
- package/dist/fixtures/resolve.js +47 -18
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +2 -1
- package/dist/schema/define-schema.js +19 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @homepages/concrete
|
|
2
2
|
|
|
3
|
+
## 6.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d048e5b: A section's `display.visibility` and `display.variant` can read the section's own slots, computed or filled. Name the slot's const in `reads`, as a sibling-reading `fill()` or `compute()` already does.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const photos = list.of(image({ label: "Photo" }), {
|
|
11
|
+
label: "Photos",
|
|
12
|
+
source: fill({ brief: "Every photo of the property." }),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const Gallery = section(
|
|
16
|
+
{
|
|
17
|
+
key: "gallery",
|
|
18
|
+
label: "Gallery",
|
|
19
|
+
display: {
|
|
20
|
+
visibility: select(["visible", "hidden"], {
|
|
21
|
+
source: compute({ reads: [photos] }, (rows) =>
|
|
22
|
+
(rows ?? []).length >= 3 ? "visible" : "hidden"
|
|
23
|
+
),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
slots: { photos },
|
|
27
|
+
},
|
|
28
|
+
({ slot }) => null
|
|
29
|
+
);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
A computed entry settles once the section's fills have run, and again when an edit changes a slot it reads, unless the user has set that entry themselves. A filled entry is the section's last decision and is shown the values its sibling fills wrote. A variant may read a slot it gates: every declared slot is filled whatever case the variant takes. In the dev playground, a display entry reads the section's slots before the variant gates them.
|
|
33
|
+
|
|
34
|
+
A filled entry reading a sourced sibling (a fact, a `compute()` or a mirror) is still refused when the section is declared, as it is for any `fill()`: that value settles only after every fill has run.
|
|
35
|
+
|
|
3
36
|
## 6.1.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
package/codemods/manifest.json
CHANGED
package/dist/fixtures/resolve.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
182
|
-
if (gate !== void 0 && (variant === void 0 || !
|
|
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
|
-
|
|
232
|
-
|
|
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,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
|
|
|
@@ -29,39 +29,42 @@ function siblingResolver(sectionKey, slots) {
|
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const binding = getFill(slot);
|
|
32
|
+
function resolveBindingReads(at, binding, resolveReads) {
|
|
34
33
|
const reads = binding?.reads;
|
|
35
|
-
if (binding === void 0 || reads === void 0 || !reads.some(isSiblingSlot)) return
|
|
34
|
+
if (binding === void 0 || reads === void 0 || !reads.some(isSiblingSlot)) return binding;
|
|
36
35
|
const resolved = resolveReads(at, reads) ?? [];
|
|
37
36
|
const upstream = resolved[reads.findIndex((read) => isSiblingSlot(read) && read.source !== void 0)];
|
|
38
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.`);
|
|
39
38
|
const sibling = resolved[reads.findIndex(isSiblingSlot)];
|
|
40
39
|
const section = sibling !== void 0 && isSlotRef(sibling) ? sibling.section : void 0;
|
|
41
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 : {
|
|
42
50
|
...slot,
|
|
43
|
-
[FILL]:
|
|
44
|
-
...binding,
|
|
45
|
-
reads: resolved,
|
|
46
|
-
[FILL_SECTION]: section
|
|
47
|
-
}
|
|
51
|
+
[FILL]: resolved
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
|
-
function emitDisplay(display, computed) {
|
|
54
|
+
function emitDisplay(display, computed, resolveReads) {
|
|
51
55
|
const out = {};
|
|
52
56
|
for (const key of ["visibility", "variant"]) {
|
|
53
57
|
const entry = display[key];
|
|
54
58
|
if (entry === void 0) continue;
|
|
59
|
+
const at = `display.${key}`;
|
|
55
60
|
const emitted = { cases: [...entry.cases] };
|
|
56
61
|
if (entry.locked === true) emitted.locked = true;
|
|
57
|
-
const sibling = entry.source?.reads?.find(isSiblingSlot);
|
|
58
|
-
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.`);
|
|
59
62
|
if (isComputeBinding(entry.source)) {
|
|
60
|
-
computed[
|
|
61
|
-
emitted.source = derivedSource(
|
|
63
|
+
computed[at] = entry.source.fn;
|
|
64
|
+
emitted.source = derivedSource(at, resolveReads(at, entry.source.reads));
|
|
62
65
|
} else if (isFillBinding(entry.source)) emitted.fill = {
|
|
63
66
|
pick: entry.source.brief,
|
|
64
|
-
...fillMark(entry.source)
|
|
67
|
+
...fillMark(resolveBindingReads(at, entry.source, resolveReads))
|
|
65
68
|
};
|
|
66
69
|
else if (entry.source !== void 0) emitted.source = entry.source;
|
|
67
70
|
out[key] = emitted;
|
|
@@ -70,14 +73,14 @@ function emitDisplay(display, computed) {
|
|
|
70
73
|
}
|
|
71
74
|
function defineSchema(input) {
|
|
72
75
|
const computed = {};
|
|
76
|
+
const resolveReads = siblingResolver(input.key, input.slots);
|
|
73
77
|
const meta = {
|
|
74
78
|
displayName: input.label,
|
|
75
79
|
...input.anchor !== void 0 ? { anchor: input.anchor } : {},
|
|
76
|
-
...input.display !== void 0 ? { display: emitDisplay(input.display, computed) } : {},
|
|
80
|
+
...input.display !== void 0 ? { display: emitDisplay(input.display, computed, resolveReads) } : {},
|
|
77
81
|
...input.layout !== void 0 ? { groups: groupsFromLayout(input.layout) } : {}
|
|
78
82
|
};
|
|
79
83
|
const slots = {};
|
|
80
|
-
const resolveReads = siblingResolver(input.key, input.slots);
|
|
81
84
|
for (const [key, slot] of Object.entries(input.slots)) {
|
|
82
85
|
let emitted = resolveFillReads(key, slot, resolveReads);
|
|
83
86
|
const fields = emitted.fields;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homepages/concrete",
|
|
3
|
-
"version": "6.
|
|
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",
|