@homepages/concrete 5.0.0 → 6.0.1
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 +342 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +16 -0
- package/codemods/reads-replace-reconcile.mjs +285 -0
- package/dist/artifact/playground/client/assets/{index-D1fwOGVK.js → index-u3T7DiSN.js} +96 -96
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/host.mjs +23 -23
- package/dist/base.css +3 -8
- package/dist/browser/site-config.js +1 -16
- package/dist/browser/submit-lead.js +0 -31
- package/dist/cli/build/artifact.js +16 -23
- package/dist/cli/build/captures.js +0 -6
- package/dist/cli/build/esbuild.js +0 -17
- package/dist/cli/build/fixtures.js +15 -30
- package/dist/cli/build/icons.js +0 -3
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/build/playground.js +4 -8
- package/dist/cli/build/sections.js +9 -30
- package/dist/cli/build/source.js +52 -27
- package/dist/cli/build/static.js +4 -25
- package/dist/cli/capture/bundle.js +0 -9
- package/dist/cli/capture/capture-browser.js +0 -14
- package/dist/cli/capture/capture.js +1 -8
- package/dist/cli/check/analyze.js +2 -5
- package/dist/cli/check/index.js +1 -1
- package/dist/cli/check/line-endings.js +52 -0
- package/dist/cli/check/load-workspace.js +3 -8
- package/dist/cli/check/portable-names.js +48 -0
- package/dist/cli/check/render/class-conflicts.js +0 -5
- package/dist/cli/check/render/html.js +0 -1
- package/dist/cli/check/render/invariants.js +0 -5
- package/dist/cli/check/render/island-frames.js +0 -25
- package/dist/cli/check/render/marker-coverage.js +0 -20
- package/dist/cli/check/render/nav.js +0 -33
- package/dist/cli/check/report.js +0 -3
- package/dist/cli/check/stages/bundles.js +1 -9
- package/dist/cli/check/stages/composition.js +3 -2
- package/dist/cli/check/stages/dependencies.js +7 -38
- package/dist/cli/check/stages/fixtures.js +3 -31
- package/dist/cli/check/stages/lint.js +2 -2
- package/dist/cli/check/stages/logic.js +3 -34
- package/dist/cli/check/stages/relations.js +46 -0
- package/dist/cli/check/stages/render.js +0 -1
- package/dist/cli/check/stages/sections.js +3 -3
- package/dist/cli/check/stages/stylesheet.js +1 -1
- package/dist/cli/check/stages/typecheck.js +5 -11
- package/dist/cli/check/stages/workspace.js +36 -14
- package/dist/cli/commands.js +9 -56
- package/dist/cli/currency/cache.js +4 -17
- package/dist/cli/currency/decide.js +0 -14
- package/dist/cli/currency/opt-out.js +0 -7
- package/dist/cli/currency/preamble.js +3 -24
- package/dist/cli/currency/prompt.js +0 -1
- package/dist/cli/currency/refresh.js +5 -12
- package/dist/cli/currency/resolve-latest.js +3 -64
- package/dist/cli/currency/version-order.js +0 -12
- package/dist/cli/dev/crop.js +0 -2
- package/dist/cli/dev/http.js +0 -13
- package/dist/cli/dev/index.js +3 -4
- package/dist/cli/dev/islands.js +25 -70
- package/dist/cli/dev/listen.js +26 -0
- package/dist/cli/dev/load-template.js +0 -1
- package/dist/cli/dev/request-error.js +0 -4
- package/dist/cli/dev/server.js +46 -52
- package/dist/cli/dev/tsconfig-paths.js +0 -13
- package/dist/cli/dev/vite.js +9 -38
- package/dist/cli/dev/workspace-reader.js +4 -34
- package/dist/cli/media/cache.js +4 -51
- package/dist/cli/media/derive.js +2 -94
- package/dist/cli/media/deriver-plugin.js +0 -2
- package/dist/cli/media/frame-rung-floor.js +0 -6
- package/dist/cli/property/index.js +0 -4
- package/dist/cli/property/library.js +6 -24
- package/dist/cli/publish/client.js +0 -1
- package/dist/cli/publish/freshness.js +0 -2
- package/dist/cli/publish/git.js +2 -8
- package/dist/cli/publish/index.js +8 -15
- package/dist/cli/publish/pack.js +5 -6
- package/dist/cli/publish/report.js +0 -6
- package/dist/cli/publish/target.js +16 -13
- package/dist/cli/publish/wire.js +0 -6
- package/dist/cli/tar.js +2 -9
- package/dist/cli/upgrade/codemod.js +0 -8
- package/dist/cli/upgrade/index.js +0 -24
- package/dist/cli/upgrade/manifest.js +0 -12
- package/dist/cli/upgrade/plan.js +0 -17
- package/dist/cli/upgrade/stage.js +12 -15
- package/dist/cli/version.js +0 -8
- package/dist/cli/workspace.js +2 -34
- package/dist/cli.js +4 -21
- package/dist/css/compile.js +25 -28
- package/dist/css/graph.js +3 -10
- package/dist/css/inline.js +3 -16
- package/dist/css/rules.js +6 -43
- package/dist/design-system/format-variants.js +0 -22
- package/dist/eslint/authoring.js +0 -2
- package/dist/eslint/correctness.js +0 -7
- package/dist/eslint/rules/editor-reason.js +0 -11
- package/dist/eslint/rules/island-ids.js +0 -1
- package/dist/eslint/rules/jsx-visitor.js +0 -13
- package/dist/eslint/rules/no-editor-globals.js +0 -2
- package/dist/eslint/rules/no-raw-values.js +0 -1
- package/dist/fixtures/brand.js +0 -1
- package/dist/fixtures/bundle-rule.js +4 -9
- package/dist/fixtures/canonical.d.ts +20 -0
- package/dist/fixtures/image-dimensions.js +0 -1
- package/dist/fixtures/load.js +8 -17
- package/dist/fixtures/media-plugin.js +4 -31
- package/dist/fixtures/media.js +0 -21
- package/dist/fixtures/package-stylesheets.js +0 -6
- package/dist/fixtures/property.js +16 -15
- package/dist/fixtures/resolve.js +102 -29
- package/dist/fixtures/rows.js +12 -11
- package/dist/fixtures/synthesize-empties.js +0 -4
- package/dist/fixtures.d.ts +19 -4
- package/dist/fixtures.js +0 -18
- package/dist/index.d.ts +8 -9
- package/dist/index.js +2 -11
- package/dist/islands/client-module.js +0 -11
- package/dist/islands/marker.js +0 -33
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +0 -20
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +21 -35
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +4 -0
- package/dist/packages/internal/fill-bake/dist/derive-source.js +40 -0
- package/dist/packages/internal/fill-bake/dist/display.js +0 -1
- package/dist/packages/internal/fill-bake/dist/index.js +4 -4
- package/dist/packages/internal/fill-vocabulary/dist/origination.js +106 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +1 -49
- package/dist/packages/internal/format-geometry/dist/capture.js +10 -240
- package/dist/packages/internal/format-geometry/dist/geometry.js +0 -6
- package/dist/packages/internal/image-ladder/dist/crop.js +0 -12
- package/dist/packages/internal/image-ladder/dist/policy.js +0 -14
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +0 -13
- package/dist/packages/internal/island-runtime/dist/contract.js +0 -34
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/index.js +0 -34
- package/dist/packages/internal/island-runtime/dist/island-id-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +0 -15
- package/dist/packages/internal/island-runtime/dist/use-editor.js +0 -10
- package/dist/packages/internal/island-runtime/dist/use-island-id.js +0 -32
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +2 -17
- package/dist/packages/internal/property-facts/dist/index.js +1 -1
- package/dist/packages/internal/property-facts/dist/{property-facts-CSdkSuD7.js → property-facts-5pxZnlkh.js} +13 -2
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +1 -18
- package/dist/packages/internal/section-contracts/dist/catalog.js +16 -8
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +12 -16
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +5 -11
- package/dist/packages/internal/section-contracts/dist/display-contract.js +2 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +2 -8
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +13 -0
- package/dist/packages/internal/section-contracts/dist/index.js +2 -1
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +16 -42
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +24 -43
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +11 -18
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +10 -12
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +3 -13
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +6 -18
- package/dist/packages/internal/section-contracts/dist/runners.js +21 -13
- package/dist/packages/internal/section-contracts/dist/source-contract.js +13 -2
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +31 -0
- package/dist/packages/internal/source-resolution/dist/index.js +1 -9
- package/dist/packages/internal/template-artifact/dist/hash.js +0 -8
- package/dist/packages/internal/template-artifact/dist/index.js +1 -1
- package/dist/packages/internal/template-artifact/dist/layout.js +0 -39
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -9
- package/dist/packages/internal/template-artifact/dist/sha256.js +0 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +2 -4
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +0 -16
- package/dist/packages/internal/template-contracts/dist/content-categories.js +0 -4
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +16 -10
- package/dist/packages/internal/template-contracts/dist/facts-view.js +15 -28
- package/dist/packages/internal/template-contracts/dist/layout.js +0 -7
- package/dist/packages/internal/template-contracts/dist/markers.js +0 -29
- package/dist/packages/internal/template-contracts/dist/select-key.js +0 -6
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +56 -34
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +22 -389
- package/dist/platform/file-url.js +8 -0
- package/dist/platform/fs.js +73 -0
- package/dist/platform/names.js +63 -0
- package/dist/platform/order.js +7 -0
- package/dist/platform/paths.js +66 -0
- package/dist/platform/process.js +97 -0
- package/dist/playground/host/page-state.js +0 -2
- package/dist/playground/host/paths.js +0 -1
- package/dist/playground/layout.js +0 -7
- package/dist/playground/wire.js +0 -8
- package/dist/primitives/FrameShell.js +0 -18
- package/dist/primitives/Image.d.ts +5 -1
- package/dist/primitives/Image.js +2 -68
- package/dist/primitives/Section.js +0 -13
- package/dist/primitives/Tour.js +0 -26
- package/dist/primitives/Video.js +0 -32
- package/dist/primitives/embed-playback.js +0 -1
- package/dist/primitives/marker-attrs.js +0 -17
- package/dist/primitives/picture-sources.js +6 -1
- package/dist/primitives/probe-context.js +0 -7
- package/dist/primitives/slot-bindings.js +0 -46
- package/dist/primitives/slot-document.js +0 -11
- package/dist/primitives/slot-group.js +0 -9
- package/dist/primitives/slot-media.js +0 -27
- package/dist/primitives/slot-scalar.js +0 -4
- package/dist/primitives/slot.js +0 -6
- package/dist/rules/registry.js +42 -24
- package/dist/schema/compute.d.ts +46 -8
- package/dist/schema/compute.js +21 -15
- package/dist/schema/define-schema.d.ts +1 -1
- package/dist/schema/define-schema.js +37 -17
- package/dist/schema/extract-fill-spec.js +93 -180
- package/dist/schema/extract-used-facts.js +16 -158
- package/dist/schema/fact.d.ts +25 -12
- package/dist/schema/fact.js +7 -11
- package/dist/schema/fill-builders.d.ts +91 -366
- package/dist/schema/fill-builders.js +21 -259
- package/dist/schema/fill-declaration.d.ts +7 -69
- package/dist/schema/fill-declaration.js +5 -34
- package/dist/schema/fill-spec.js +59 -148
- package/dist/schema/format-presets.js +0 -12
- package/dist/schema/format.js +0 -7
- package/dist/schema/layout.js +0 -10
- package/dist/schema/manifest.js +0 -39
- package/dist/schema/property-facts.d.ts +20 -0
- package/dist/schema/section-nav.js +0 -15
- package/dist/schema/section-schema.d.ts +0 -1
- package/dist/schema/section-schema.js +4 -20
- package/dist/schema/slot-builders.d.ts +128 -117
- package/dist/schema/slot-builders.js +18 -201
- package/dist/schema/slot-ref.d.ts +63 -0
- package/dist/schema/slot-ref.js +33 -0
- package/dist/schema/slot-types.d.ts +3 -2
- package/dist/schema/slot-types.js +11 -20
- package/dist/section/declare.d.ts +14 -10
- package/dist/section/declare.js +13 -2
- package/dist/section/discovery.js +6 -21
- package/dist/section/groups.js +0 -6
- package/dist/section/materialize.js +0 -5
- package/dist/section/placements.js +0 -4
- package/dist/section/section.d.ts +8 -5
- package/dist/section/section.js +7 -29
- package/dist/styles.css +5 -0
- package/dist/template/define-template.d.ts +0 -4
- package/dist/template/define-template.js +1 -15
- package/dist/template/logic-build.js +8 -35
- package/dist/template/logic-shim.d.ts +4 -5
- package/dist/template/logic-shim.js +2 -6
- package/dist/template/logic-transform.js +0 -6
- package/dist/template/materialize.js +52 -43
- package/dist/template/mirror-types.js +43 -0
- package/dist/template/running-copy.js +5 -20
- package/dist/template/section-reads.js +83 -0
- package/guide/reference/cli/INDEX.md +12 -6
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +3 -3
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +4 -2
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +26 -13
- package/package.json +4 -2
- package/dist/packages/internal/fact-interpolation/dist/index.js +0 -22
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +0 -170
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +0 -32
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +0 -131
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +0 -11
- package/dist/schema/fill-spec.d.ts +0 -18
- package/dist/template/reconcile.d.ts +0 -67
- package/dist/template/reconcile.js +0 -25
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { mirror } from "./compute.js";
|
|
2
|
+
import { isFillBinding } from "./fill-builders.js";
|
|
1
3
|
import { fillMark, getFill } from "./fill-declaration.js";
|
|
2
4
|
import { itemLayoutFromRows } from "./layout.js";
|
|
5
|
+
import { isFactRef, isSiblingSlot, isSlotRef } from "./slot-ref.js";
|
|
3
6
|
|
|
4
7
|
//#region src/schema/slot-builders.ts
|
|
5
8
|
function head(opts) {
|
|
9
|
+
const source = opts.source;
|
|
10
|
+
const baked = source !== void 0 && !isFillBinding(source);
|
|
6
11
|
return {
|
|
7
12
|
...opts.locked === true ? { locked: true } : {},
|
|
8
|
-
...
|
|
13
|
+
...baked ? { source: isSlotRef(source) || isSiblingSlot(source) ? mirror(source) : source } : {},
|
|
14
|
+
...fillMark(source),
|
|
9
15
|
...opts.writeback !== void 0 ? { writeback: opts.writeback } : {},
|
|
10
16
|
label: opts.label,
|
|
11
17
|
...opts.placeholder !== void 0 ? { placeholder: opts.placeholder } : {},
|
|
@@ -17,54 +23,14 @@ function textOfSize(size) {
|
|
|
17
23
|
type: "text",
|
|
18
24
|
size,
|
|
19
25
|
...head(opts),
|
|
20
|
-
...opts.cap !== void 0 ? { cap: opts.cap } : {}
|
|
21
|
-
...fillMark(opts.fill)
|
|
26
|
+
...opts.cap !== void 0 ? { cap: opts.cap } : {}
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
|
-
/**
|
|
25
|
-
* The text slot, sized by the member you pick: `text.short` / `.medium` / `.long`.
|
|
26
|
-
*
|
|
27
|
-
* `cap` is the slot's character budget and the ONLY declaration of it: it bounds
|
|
28
|
-
* what a user may type in the editor, and the `textBlock` filling the slot inherits
|
|
29
|
-
* it as the budget the model is asked to write to. A slot an AI fill decision
|
|
30
|
-
* targets must declare one. `fill` takes that `textBlock` — the alternative to
|
|
31
|
-
* `source`, never its companion.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { text, textBlock } from "@homepages/concrete";
|
|
35
|
-
*
|
|
36
|
-
* text.medium({
|
|
37
|
-
* cap: 60,
|
|
38
|
-
* label: "Headline",
|
|
39
|
-
* fill: textBlock({
|
|
40
|
-
* structure: "single_sentence",
|
|
41
|
-
* perspective: "third",
|
|
42
|
-
* voice: "Confident premium-listing voice.",
|
|
43
|
-
* content: "Write a marketing headline.",
|
|
44
|
-
* }),
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
29
|
const text = {
|
|
49
30
|
short: textOfSize("short"),
|
|
50
31
|
medium: textOfSize("medium"),
|
|
51
32
|
long: textOfSize("long")
|
|
52
33
|
};
|
|
53
|
-
/**
|
|
54
|
-
* A numeric slot. `prefix`/`suffix` are rendered strings (such as `"$"` /
|
|
55
|
-
* `" sq ft"`), `thousandsSep` toggles grouping-separator formatting, `decimals`
|
|
56
|
-
* toggles decimal display, and `maxDigits` caps the digit count — all read by
|
|
57
|
-
* the renderer's number formatting, not enforced as an input range.
|
|
58
|
-
*
|
|
59
|
-
* Binding-only: no fill decision produces a number, so this builder takes no
|
|
60
|
-
* `fill` — the value comes from `source`.
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* import { fact, number } from "@homepages/concrete";
|
|
64
|
-
*
|
|
65
|
-
* number({ source: fact.unit.sqft, writeback: true, label: "Square feet", thousandsSep: true, suffix: "sqft", maxDigits: 7 });
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
34
|
function number(opts) {
|
|
69
35
|
return {
|
|
70
36
|
type: "number",
|
|
@@ -81,7 +47,7 @@ function selectFn(opts) {
|
|
|
81
47
|
return {
|
|
82
48
|
type: "select",
|
|
83
49
|
...head(opts),
|
|
84
|
-
...source
|
|
50
|
+
...isFactRef(source) ? { options: { source: source.field } } : {},
|
|
85
51
|
...opts.creatable !== void 0 ? { creatable: opts.creatable } : {}
|
|
86
52
|
};
|
|
87
53
|
}
|
|
@@ -90,70 +56,20 @@ function selectOf(values, opts) {
|
|
|
90
56
|
type: "select",
|
|
91
57
|
...head(opts),
|
|
92
58
|
values: [...values],
|
|
93
|
-
...opts.creatable !== void 0 ? { creatable: opts.creatable } : {}
|
|
94
|
-
...fillMark(opts.fill === void 0 ? void 0 : selectAssignOf(opts.fill))
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/** The row planner's spelling of a select field's choice: `{ type: "select-assign", pick }`. */
|
|
98
|
-
function selectAssignOf(choice) {
|
|
99
|
-
return {
|
|
100
|
-
type: "select-assign",
|
|
101
|
-
pick: choice.pick
|
|
59
|
+
...opts.creatable !== void 0 ? { creatable: opts.creatable } : {}
|
|
102
60
|
};
|
|
103
61
|
}
|
|
104
62
|
function displaySelect(cases, opts) {
|
|
105
63
|
return {
|
|
106
64
|
cases: [...cases],
|
|
107
65
|
...opts.locked === true ? { locked: true } : {},
|
|
108
|
-
...opts.source !== void 0 ? { source: opts.source } : {}
|
|
109
|
-
...opts.fill !== void 0 ? { fill: opts.fill } : {}
|
|
66
|
+
...opts.source !== void 0 ? { source: opts.source } : {}
|
|
110
67
|
};
|
|
111
68
|
}
|
|
112
69
|
function selectDispatch(a, b) {
|
|
113
70
|
return Array.isArray(a) ? displaySelect(a, b) : selectFn(a);
|
|
114
71
|
}
|
|
115
|
-
/**
|
|
116
|
-
* The select slot AND the `meta.display` entry, told apart by the call shape.
|
|
117
|
-
*
|
|
118
|
-
* As a slot: `select({ from })` for a fact-derived vocabulary, `select.of([…])`
|
|
119
|
-
* for a hand-authored one. A top-level select is bound with `source` and takes
|
|
120
|
-
* no `fill`. Inside a record item, `select.of` is written one of two ways: by
|
|
121
|
-
* the list's own counted `chooseFrom` origination, which picks the ROWS from
|
|
122
|
-
* this field's vocabulary, or — on a row that already exists, a fact-baked
|
|
123
|
-
* comparable say — by its own countless `chooseFrom({ pick })`, which picks
|
|
124
|
-
* this one field's key per row in the list's batched call.
|
|
125
|
-
*
|
|
126
|
-
* As a display entry: `select(cases, { source: compute(fn) })` or
|
|
127
|
-
* `select(cases, { fill: chooseFrom({ pick }) })` declares a `meta.display`
|
|
128
|
-
* `visibility`/`variant` — the first case is the default and the failure
|
|
129
|
-
* posture, `locked: true` opts a variant out of user switching, and the entry
|
|
130
|
-
* takes exactly one origin.
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* import { chooseFrom, compute, select } from "@homepages/concrete";
|
|
134
|
-
*
|
|
135
|
-
* select.of(["for_sale", "sold"], { label: "Status" });
|
|
136
|
-
* select.of(["regular", "highlight"], { label: "Comparable status", fill: chooseFrom({ pick: "Highlight the two or three strongest sales." }) });
|
|
137
|
-
* select(["visible", "hidden"], { source: compute((f) => (f.tours.length > 0 ? "visible" : "hidden")) });
|
|
138
|
-
* select(["classic", "editorial"], { fill: chooseFrom({ pick: "Prefer editorial for story-driven narratives." }) });
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
72
|
const select = Object.assign(selectDispatch, { of: selectOf });
|
|
142
|
-
/**
|
|
143
|
-
* A URL string slot. `accepts` names a single link kind (such as `"tour"`) or
|
|
144
|
-
* link-provider id (such as `"matterport"`) the value must match. A link kind
|
|
145
|
-
* with no provider behind it admits no url at all, which the type cannot say —
|
|
146
|
-
* check time rejects those.
|
|
147
|
-
*
|
|
148
|
-
* Binding-only: no fill decision produces a url, so this builder takes no
|
|
149
|
-
* `fill` — the value comes from `source`.
|
|
150
|
-
* @example
|
|
151
|
-
* ```ts
|
|
152
|
-
* import { url } from "@homepages/concrete";
|
|
153
|
-
*
|
|
154
|
-
* url({ label: "Tour URL", accepts: "tour" });
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
73
|
function url(opts) {
|
|
158
74
|
return {
|
|
159
75
|
type: "url",
|
|
@@ -161,77 +77,26 @@ function url(opts) {
|
|
|
161
77
|
...opts.accepts !== void 0 ? { accepts: opts.accepts } : {}
|
|
162
78
|
};
|
|
163
79
|
}
|
|
164
|
-
/**
|
|
165
|
-
* A single image slot — the resolved value is always one `ImageValue`, never a
|
|
166
|
-
* list, so it carries no count bounds (a list of them does). `crop` is the asset's
|
|
167
|
-
* contract — the editor's cropper and `<Image>`'s mobile-crop switch read it; the box
|
|
168
|
-
* the image renders in is the section's own classes. `sourceFilter` narrows the
|
|
169
|
-
* candidate pool the editor offers, routing the slot to a dedicated picker.
|
|
170
|
-
* `fill` takes an `imageAssign`, or a `contactAssign` naming one of a contact's
|
|
171
|
-
* image fields — the alternative to `source`, never its companion.
|
|
172
|
-
* @example
|
|
173
|
-
* ```ts
|
|
174
|
-
* import { image } from "@homepages/concrete";
|
|
175
|
-
*
|
|
176
|
-
* image({ label: "Floor plan", sourceFilter: "floorplans" });
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
80
|
function image(opts) {
|
|
180
81
|
return {
|
|
181
82
|
type: "image",
|
|
182
83
|
...head(opts),
|
|
183
84
|
...opts.sourceFilter !== void 0 ? { sourceFilter: opts.sourceFilter } : {},
|
|
184
|
-
...opts.crop !== void 0 ? { crop: opts.crop } : {}
|
|
185
|
-
...fillMark(opts.fill)
|
|
85
|
+
...opts.crop !== void 0 ? { crop: opts.crop } : {}
|
|
186
86
|
};
|
|
187
87
|
}
|
|
188
|
-
/**
|
|
189
|
-
* A single video slot, resolved as a `VideoValue`. Unlike `image`, there is no
|
|
190
|
-
* `crop` — a video is selected, never re-edited. `sources` opts into which
|
|
191
|
-
* origins the value may come from (`"upload"`, `"link"`); omitted means
|
|
192
|
-
* upload-only. `playback` configures the renderer's `<Video>`; the box it plays
|
|
193
|
-
* in is your own classes.
|
|
194
|
-
* `fill` takes a `videoAssign` — the alternative to `source`, never its companion.
|
|
195
|
-
* @example
|
|
196
|
-
* ```ts
|
|
197
|
-
* import { video } from "@homepages/concrete";
|
|
198
|
-
*
|
|
199
|
-
* video({ label: "Property video", playback: { controls: true }, sources: ["upload", "link"] });
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
88
|
function video(opts) {
|
|
203
89
|
return {
|
|
204
90
|
type: "video",
|
|
205
91
|
...head(opts),
|
|
206
92
|
...opts.playback !== void 0 ? { playback: opts.playback } : {},
|
|
207
|
-
...opts.sources !== void 0 ? { sources: opts.sources } : {}
|
|
208
|
-
...fillMark(opts.fill)
|
|
93
|
+
...opts.sources !== void 0 ? { sources: opts.sources } : {}
|
|
209
94
|
};
|
|
210
95
|
}
|
|
211
|
-
/**
|
|
212
|
-
* A single 3D-tour slot, resolved as a `TourValue`. Its own kind rather than a
|
|
213
|
-
* third video source: `playback` is meaningless on a walkthrough, and the fill
|
|
214
|
-
* pool would otherwise mix videos with tour models. It has no type-specific
|
|
215
|
-
* option at all — no `crop` (a tour is selected, never edited), no `playback`,
|
|
216
|
-
* no `sources` and no `accepts`; which providers are admitted widens in the
|
|
217
|
-
* link-provider catalog, never on a slot, and the box the embed fills is your
|
|
218
|
-
* own classes.
|
|
219
|
-
*
|
|
220
|
-
* Render it with `<Slot.Tour>` for the embed, `<Slot.Image>` for the tour's
|
|
221
|
-
* thumbnail, or both — two positions from one selection.
|
|
222
|
-
* `fill` takes a `tourAssign` — the alternative to `source`, never its companion.
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* import { tour, tourAssign } from "@homepages/concrete";
|
|
226
|
-
*
|
|
227
|
-
* tour({ label: "3D tour", fill: tourAssign({ pick: "The whole-home walkthrough." }) });
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
96
|
function tour(opts) {
|
|
231
97
|
return {
|
|
232
98
|
type: "tour",
|
|
233
|
-
...head(opts)
|
|
234
|
-
...fillMark(opts.fill)
|
|
99
|
+
...head(opts)
|
|
235
100
|
};
|
|
236
101
|
}
|
|
237
102
|
const HEAD_KEYS = ["locked"];
|
|
@@ -241,15 +106,14 @@ function stripElementHead(element) {
|
|
|
241
106
|
return bare;
|
|
242
107
|
}
|
|
243
108
|
function listOfElement(element, opts) {
|
|
244
|
-
if (getFill(element) !== void 0) throw new Error(`list.of: the element of "${opts.label}" declares a fill — one decision produces the whole list, so \`fill
|
|
109
|
+
if (getFill(element) !== void 0) throw new Error(`list.of: the element of "${opts.label}" declares a fill — one decision produces the whole list, so \`source: fill(…)\` belongs on the list slot.`);
|
|
245
110
|
return {
|
|
246
111
|
type: "list",
|
|
247
112
|
...head(opts),
|
|
248
113
|
element: stripElementHead(element),
|
|
249
114
|
...opts.min !== void 0 ? { min: opts.min } : {},
|
|
250
115
|
...opts.max !== void 0 ? { max: opts.max } : {},
|
|
251
|
-
...opts.unique !== void 0 ? { unique: opts.unique } : {}
|
|
252
|
-
...fillMark(opts.fill)
|
|
116
|
+
...opts.unique !== void 0 ? { unique: opts.unique } : {}
|
|
253
117
|
};
|
|
254
118
|
}
|
|
255
119
|
function listOfRecord(fields, opts) {
|
|
@@ -260,70 +124,23 @@ function listOfRecord(fields, opts) {
|
|
|
260
124
|
...opts.layout !== void 0 ? { layout: itemLayoutFromRows(opts.layout) } : {},
|
|
261
125
|
...opts.title !== void 0 ? { title: opts.title } : {},
|
|
262
126
|
...opts.min !== void 0 ? { min: opts.min } : {},
|
|
263
|
-
...opts.max !== void 0 ? { max: opts.max } : {}
|
|
264
|
-
...fillMark(opts.fill)
|
|
127
|
+
...opts.max !== void 0 ? { max: opts.max } : {}
|
|
265
128
|
};
|
|
266
129
|
}
|
|
267
130
|
function listOf(item, opts) {
|
|
268
131
|
return typeof item.type === "string" ? listOfElement(item, opts) : listOfRecord(item, opts);
|
|
269
132
|
}
|
|
270
|
-
/**
|
|
271
|
-
* The list slot — one primitive for everything multi-item. The item is a
|
|
272
|
-
* single slot (`list.of(text.short({ label: "Feature", cap: 80 }), { label: "Features" })`,
|
|
273
|
-
* `list.of(image({ label: "Photo", crop }), { min: 3, label: "Photos" })`,
|
|
274
|
-
* `list.of(poi({ label: "Restaurant" }), { max: 6, label: "Restaurants" })`)
|
|
275
|
-
* or a record of slots
|
|
276
|
-
* (`list.of({ photo: image({ label: "Photo" }), caption: text.short({ label: "Caption", cap: 80 }) }, { label: "Slides" })`).
|
|
277
|
-
* A single item emits `element`; a record emits `fields` with the optional
|
|
278
|
-
* `layout`/`title` row surface. Depth is fixed: an item is never a list, a
|
|
279
|
-
* record field is never a record, and a field-level list holds a single
|
|
280
|
-
* non-record item — each violation is a compile error here and a parse error
|
|
281
|
-
* on the wire.
|
|
282
|
-
*/
|
|
283
133
|
const list = { of: listOf };
|
|
284
|
-
/**
|
|
285
|
-
* A single point of interest — one platform-built place (a `PoiRow`), picked
|
|
286
|
-
* in the editor's place search. The platform owns the row's content; there is
|
|
287
|
-
* nothing to configure beyond the head. Usable standalone or as a list item
|
|
288
|
-
* (`list.of(poi({ label: "Restaurant" }), { label: "Restaurants" })`).
|
|
289
|
-
* @example
|
|
290
|
-
* ```ts
|
|
291
|
-
* import { poi } from "@homepages/concrete";
|
|
292
|
-
*
|
|
293
|
-
* poi({ label: "Nearest station", placeholder: "Search places…" });
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
134
|
function poi(opts) {
|
|
297
135
|
return {
|
|
298
136
|
type: "poi",
|
|
299
137
|
...head(opts)
|
|
300
138
|
};
|
|
301
139
|
}
|
|
302
|
-
/**
|
|
303
|
-
* A single platform-hosted document — a pdf, spreadsheet, or office file the
|
|
304
|
-
* visitor opens in the browser or downloads. The value resolves to one
|
|
305
|
-
* `DocumentValue` (served url plus filename, type and size); render it with
|
|
306
|
-
* `Slot.Document`, which is one anchor.
|
|
307
|
-
*
|
|
308
|
-
* Reach for `url({ accepts: "file" })` instead when the file lives somewhere
|
|
309
|
-
* else — a Drive or Dropbox link the platform neither stores nor serves.
|
|
310
|
-
*
|
|
311
|
-
* `fill` takes a `documentAssign`, which picks one file out of the documents
|
|
312
|
-
* stored on the property. Usable standalone or as a list item — a
|
|
313
|
-
* `list.of(document(...))` carries its own `listFill` and picks a SET from the
|
|
314
|
-
* same pool.
|
|
315
|
-
* @example
|
|
316
|
-
* ```ts
|
|
317
|
-
* import { document, documentAssign } from "@homepages/concrete";
|
|
318
|
-
*
|
|
319
|
-
* document({ label: "Offering brochure", fill: documentAssign({ pick: "The full property brochure." }) });
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
140
|
function document(opts) {
|
|
323
141
|
return {
|
|
324
142
|
type: "document",
|
|
325
|
-
...head(opts)
|
|
326
|
-
...fillMark(opts.fill)
|
|
143
|
+
...head(opts)
|
|
327
144
|
};
|
|
328
145
|
}
|
|
329
146
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Slot } from "./slot-types.js";
|
|
2
|
+
import { SlotValue } from "./section-props.js";
|
|
3
|
+
//#region src/schema/slot-ref.d.ts
|
|
4
|
+
/** The reserved `slot` prefix a display entry's ref is addressed by. */
|
|
5
|
+
declare const DISPLAY_REF_PREFIX = "display.";
|
|
6
|
+
/** The two `meta.display` entries a section may declare, and so may be read. */
|
|
7
|
+
type DisplayEntryName = "visibility" | "variant";
|
|
8
|
+
/**
|
|
9
|
+
* A slot of a section, or one of its two display entries, by name — what a
|
|
10
|
+
* declaration `reads`. Both string halves are literal on a section value
|
|
11
|
+
* (`Hero.slots.hero_image` is `SlotRef<"hero", "hero_image", ImageValue | null>`),
|
|
12
|
+
* which is what types the positional value a compute callback receives.
|
|
13
|
+
*/
|
|
14
|
+
interface SlotRef<Section extends string = string, SlotId extends string = string, Value = unknown> {
|
|
15
|
+
readonly section: Section;
|
|
16
|
+
readonly slot: SlotId;
|
|
17
|
+
/**
|
|
18
|
+
* Phantom: the referent's own value type. Never present at runtime —
|
|
19
|
+
* `declareSection` builds `{ section, slot }` — and never serialized.
|
|
20
|
+
*/
|
|
21
|
+
readonly __value?: Value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One fact of the property, by its `FACT_GRAPH` key — what every `fact.*` entry
|
|
25
|
+
* IS. The runtime members are the `direct` source literal (see the module header);
|
|
26
|
+
* `Key` is the registry key and `Value` the phantom type the entry reads at.
|
|
27
|
+
*/
|
|
28
|
+
interface FactRef<Key extends string = string, Value = unknown> {
|
|
29
|
+
readonly kind: "direct";
|
|
30
|
+
readonly field: Key;
|
|
31
|
+
/** Phantom: the value a `compute()` callback receives for this ref. Never present at runtime. */
|
|
32
|
+
readonly __value?: Value;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A typed handle on one value the platform can resolve — what `source:`, a
|
|
36
|
+
* `compute`'s `reads` and a fill decision's `reads` all take. A new kind is
|
|
37
|
+
* additive: it answers where its value comes from and when it settles, and
|
|
38
|
+
* changes no consumer.
|
|
39
|
+
*/
|
|
40
|
+
type Ref = FactRef | SlotRef;
|
|
41
|
+
/** A slot of the declaring section, named by its own const — see the module header. */
|
|
42
|
+
type SiblingSlot = Slot;
|
|
43
|
+
/** What a `compute`'s `reads` (and a mirror's `source:`) may name: any ref, or a sibling slot. */
|
|
44
|
+
type ComputeRead = Ref | SiblingSlot;
|
|
45
|
+
/** The value a ref refers to, read off the phantom member. */
|
|
46
|
+
type RefValue<R> = R extends {
|
|
47
|
+
readonly __value?: infer V;
|
|
48
|
+
} ? V : unknown;
|
|
49
|
+
/**
|
|
50
|
+
* The value ONE ref hands a declaration that reads it. A slot read is always
|
|
51
|
+
* `| undefined` — the upstream section's page may be disabled, the section
|
|
52
|
+
* unplaced on a given composition, the slot empty — so a body must say what it
|
|
53
|
+
* does with nothing. A fact settles at intake and carries its own null.
|
|
54
|
+
*/
|
|
55
|
+
type ReadValue<R> = R extends SlotRef ? RefValue<R> | undefined : R extends SiblingSlot ? SlotValue<R> | undefined : RefValue<R>;
|
|
56
|
+
/**
|
|
57
|
+
* The positional arguments a reads-declaring callback receives: one value per ref,
|
|
58
|
+
* in `reads` order, each at that ref's own value type. Mutable so the tuple is
|
|
59
|
+
* legal in a rest parameter; the list it maps is the author's `const` one.
|
|
60
|
+
*/
|
|
61
|
+
type RefValues<Reads extends readonly ComputeRead[]> = { -readonly [I in keyof Reads]: ReadValue<Reads[I]>; };
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ComputeRead, DISPLAY_REF_PREFIX, DisplayEntryName, FactRef, ReadValue, Ref, RefValue, RefValues, SiblingSlot, SlotRef };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/schema/slot-ref.ts
|
|
2
|
+
const DISPLAY_REF_PREFIX = "display.";
|
|
3
|
+
function isSlotRef(x) {
|
|
4
|
+
return typeof x === "object" && x !== null && "section" in x && typeof x.section === "string" && "slot" in x && typeof x.slot === "string";
|
|
5
|
+
}
|
|
6
|
+
function isFactRef(x) {
|
|
7
|
+
return typeof x === "object" && x !== null && "kind" in x && x.kind === "direct" && "field" in x && typeof x.field === "string";
|
|
8
|
+
}
|
|
9
|
+
function isSiblingSlot(x) {
|
|
10
|
+
return typeof x === "object" && x !== null && "type" in x && typeof x.type === "string" && "label" in x && typeof x.label === "string";
|
|
11
|
+
}
|
|
12
|
+
function serializeSlotRef(ref) {
|
|
13
|
+
return {
|
|
14
|
+
kind: "slot",
|
|
15
|
+
section: ref.section,
|
|
16
|
+
slot: ref.slot
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function serializeRef(ref) {
|
|
20
|
+
return isSlotRef(ref) ? serializeSlotRef(ref) : {
|
|
21
|
+
kind: "fact",
|
|
22
|
+
key: ref.field
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isSerializedSlotRef(ref) {
|
|
26
|
+
return ref.kind !== "fact";
|
|
27
|
+
}
|
|
28
|
+
function serializedSlotRefs(reads) {
|
|
29
|
+
return reads.filter(isSerializedSlotRef);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { DISPLAY_REF_PREFIX, isFactRef, isSerializedSlotRef, isSiblingSlot, isSlotRef, serializeRef, serializeSlotRef, serializedSlotRefs };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FillBinding } from "./fill-builders.js";
|
|
2
|
+
import { FILL } from "./fill-declaration.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
//#region src/schema/slot-types.d.ts
|
|
4
5
|
type SlotBase = {
|
|
5
|
-
[FILL]?:
|
|
6
|
+
[FILL]?: FillBinding;
|
|
6
7
|
locked?: boolean;
|
|
7
8
|
source?: {
|
|
8
9
|
kind: string;
|
|
@@ -25,6 +25,14 @@ const playbackConfigShape = { playback: z.object({
|
|
|
25
25
|
]).optional()
|
|
26
26
|
}).strict().refine((p) => p.autoplay !== true || p.muted === true, { message: "autoplay requires muted (browsers block unmuted autoplay)" }).optional() };
|
|
27
27
|
const videoSourcesShape = { sources: z.array(z.enum(VIDEO_SOURCES)).nonempty().optional() };
|
|
28
|
+
const SerializedReads = z.array(z.union([z.object({
|
|
29
|
+
kind: z.literal("fact"),
|
|
30
|
+
key: z.string().min(1)
|
|
31
|
+
}).strict(), z.object({
|
|
32
|
+
kind: z.literal("slot").default("slot"),
|
|
33
|
+
section: z.string().min(1),
|
|
34
|
+
slot: z.string().min(1)
|
|
35
|
+
}).strict()])).min(1).optional();
|
|
28
36
|
const slotMetadataShape = {
|
|
29
37
|
label: z.string().min(1),
|
|
30
38
|
placeholder: z.string().optional(),
|
|
@@ -37,16 +45,12 @@ const slotMetadataShape = {
|
|
|
37
45
|
}).strict(),
|
|
38
46
|
z.object({
|
|
39
47
|
kind: z.literal("derived"),
|
|
40
|
-
transform: z.string()
|
|
48
|
+
transform: z.string(),
|
|
49
|
+
reads: SerializedReads
|
|
41
50
|
}).strict()
|
|
42
51
|
]).optional(),
|
|
43
52
|
writeback: z.boolean().optional()
|
|
44
53
|
};
|
|
45
|
-
/**
|
|
46
|
-
* The per-slot-type anchor: one entry per slot type declaring that type's
|
|
47
|
-
* type-specific Zod field shape and its fresh default runtime value.
|
|
48
|
-
* `SlotDef` and `defaultForSlotType` are both derived from this table.
|
|
49
|
-
*/
|
|
50
54
|
const SLOT_TYPE_DESCRIPTORS = {
|
|
51
55
|
text: {
|
|
52
56
|
shape: {
|
|
@@ -155,7 +159,6 @@ const LIST_ITEM_DEF_MEMBERS = [
|
|
|
155
159
|
slotMember("url", SLOT_TYPE_DESCRIPTORS.url.shape),
|
|
156
160
|
slotMember("document", SLOT_TYPE_DESCRIPTORS.document.shape)
|
|
157
161
|
];
|
|
158
|
-
/** The Zod union a list's single item (`element`) validates against — any value primitive, never a list or a record. */
|
|
159
162
|
const ListItemDef = z.discriminatedUnion("type", [...LIST_ITEM_DEF_MEMBERS]);
|
|
160
163
|
const FIELD_LIST_DEF_MEMBER = slotMember("list", {
|
|
161
164
|
min: z.number().int().nonnegative().optional(),
|
|
@@ -163,25 +166,13 @@ const FIELD_LIST_DEF_MEMBER = slotMember("list", {
|
|
|
163
166
|
unique: z.boolean().optional(),
|
|
164
167
|
element: z.lazy(() => ListItemDef).optional()
|
|
165
168
|
});
|
|
166
|
-
/** The Zod union a record item's field validates against — any value primitive or a field-level list, never a record. */
|
|
167
169
|
const ListFieldDef = z.discriminatedUnion("type", [...LIST_ITEM_DEF_MEMBERS, FIELD_LIST_DEF_MEMBER]);
|
|
168
170
|
const SLOT_DEF_MEMBERS = [...LIST_ITEM_DEF_MEMBERS, slotMember("list", SLOT_TYPE_DESCRIPTORS.list.shape)];
|
|
169
|
-
/**
|
|
170
|
-
* The Zod discriminated union validating an authored slot definition, built
|
|
171
|
-
* from `SLOT_TYPE_DESCRIPTORS`. Covers every slot kind; a list's item and a
|
|
172
|
-
* record item's field each validate against their own narrower union, which is
|
|
173
|
-
* what makes the depth rules unrepresentable on the wire.
|
|
174
|
-
*/
|
|
175
171
|
const SlotDef = z.discriminatedUnion("type", [...SLOT_DEF_MEMBERS]);
|
|
176
|
-
/**
|
|
177
|
-
* The fresh default runtime value for a slot of the given type, derived from
|
|
178
|
-
* `SLOT_TYPE_DESCRIPTORS`. Returns a NEW value on every call — never a shared
|
|
179
|
-
* reference — and `null` for a type absent from the catalog.
|
|
180
|
-
*/
|
|
181
172
|
function defaultForSlotType(type) {
|
|
182
173
|
if (!SLOT_TYPES.includes(type)) return null;
|
|
183
174
|
return SLOT_TYPE_DESCRIPTORS[type].default();
|
|
184
175
|
}
|
|
185
176
|
|
|
186
177
|
//#endregion
|
|
187
|
-
export { ListFieldDef, ListItemDef, SLOT_TYPE_DESCRIPTORS, SlotDef, defaultForSlotType };
|
|
178
|
+
export { ListFieldDef, ListItemDef, SLOT_TYPE_DESCRIPTORS, SerializedReads, SlotDef, defaultForSlotType };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Slot } from "../schema/slot-types.js";
|
|
2
|
+
import { DISPLAY_REF_PREFIX, DisplayEntryName, SlotRef } from "../schema/slot-ref.js";
|
|
3
|
+
import { SlotValue } from "../schema/section-props.js";
|
|
2
4
|
import { DefinedSchema, DisplayInput } from "../schema/define-schema.js";
|
|
3
5
|
//#region src/section/declare.d.ts
|
|
4
6
|
/** The first argument of `section()`: identity plus the schema declaration. */
|
|
@@ -21,17 +23,18 @@ interface SectionOptions<Key extends string, Slots extends Record<string, Slot>,
|
|
|
21
23
|
}
|
|
22
24
|
/** The schema a section's options materialize to — `defineSchema`'s own shape. */
|
|
23
25
|
type SectionSchemaOf<Slots extends Record<string, Slot>, Display extends DisplayInput> = DefinedSchema<Slots, Display, readonly []>;
|
|
26
|
+
/** One `SlotRef` per declared slot, keyed by slot id, each at that slot's value type. */
|
|
27
|
+
type SlotRefsOf<Key extends string, Slots extends Record<string, Slot>> = { readonly [K in keyof Slots & string]: SlotRef<Key, K, SlotValue<Slots[K]>>; };
|
|
28
|
+
/** A display entry's declared cases — its value type — or `string` for a loose entry. */
|
|
29
|
+
type CasesOf<Entry> = Entry extends {
|
|
30
|
+
cases: readonly (infer C)[];
|
|
31
|
+
} ? C : string;
|
|
24
32
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
33
|
+
* One `SlotRef` per DECLARED display entry, keyed by entry name. A section that
|
|
34
|
+
* declares no `display:` block offers none, so `Hero.display.visibility` is a type
|
|
35
|
+
* error rather than a ref to an entry that does not exist.
|
|
28
36
|
*/
|
|
29
|
-
|
|
30
|
-
readonly section: Section;
|
|
31
|
-
readonly slot: SlotId;
|
|
32
|
-
}
|
|
33
|
-
/** One `SlotRef` per declared slot, keyed by slot id. */
|
|
34
|
-
type SlotRefsOf<Key extends string, Slots extends Record<string, Slot>> = { readonly [K in keyof Slots & string]: SlotRef<Key, K>; };
|
|
37
|
+
type DisplayRefsOf<Key extends string, Display extends DisplayInput> = { readonly [E in Extract<keyof Display, DisplayEntryName>]-?: SlotRef<Key, `${typeof DISPLAY_REF_PREFIX}${E}`, CasesOf<NonNullable<Display[E]>>>; };
|
|
35
38
|
/** What the options declare, before a component is wrapped around it. */
|
|
36
39
|
interface SectionDeclaration<Key extends string, Slots extends Record<string, Slot>, Display extends DisplayInput> {
|
|
37
40
|
readonly key: Key;
|
|
@@ -39,6 +42,7 @@ interface SectionDeclaration<Key extends string, Slots extends Record<string, Sl
|
|
|
39
42
|
readonly required: boolean;
|
|
40
43
|
readonly schema: SectionSchemaOf<Slots, Display>;
|
|
41
44
|
readonly slots: SlotRefsOf<Key, Slots>;
|
|
45
|
+
readonly display: DisplayRefsOf<Key, Display>;
|
|
42
46
|
}
|
|
43
47
|
//#endregion
|
|
44
|
-
export { SectionDeclaration, SectionOptions, SectionSchemaOf, SlotRef, SlotRefsOf };
|
|
48
|
+
export { DisplayRefsOf, SectionDeclaration, SectionOptions, SectionSchemaOf, type SlotRef, SlotRefsOf };
|
package/dist/section/declare.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { DISPLAY_REF_PREFIX } from "../schema/slot-ref.js";
|
|
1
2
|
import { defineSchema } from "../schema/define-schema.js";
|
|
2
3
|
|
|
3
4
|
//#region src/section/declare.ts
|
|
4
|
-
|
|
5
|
+
const DISPLAY_ENTRY_NAMES = ["visibility", "variant"];
|
|
5
6
|
function declareSection(options) {
|
|
6
7
|
const { key, label, required = false } = options;
|
|
7
8
|
const schema = defineSchema({
|
|
9
|
+
key,
|
|
8
10
|
label,
|
|
9
11
|
display: options.display,
|
|
10
12
|
slots: options.slots
|
|
@@ -14,12 +16,21 @@ function declareSection(options) {
|
|
|
14
16
|
section: key,
|
|
15
17
|
slot
|
|
16
18
|
};
|
|
19
|
+
const displayRefs = {};
|
|
20
|
+
for (const entry of DISPLAY_ENTRY_NAMES) {
|
|
21
|
+
if (options.display?.[entry] === void 0) continue;
|
|
22
|
+
displayRefs[entry] = {
|
|
23
|
+
section: key,
|
|
24
|
+
slot: `${DISPLAY_REF_PREFIX}${entry}`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
17
27
|
return {
|
|
18
28
|
key,
|
|
19
29
|
label,
|
|
20
30
|
required,
|
|
21
31
|
schema,
|
|
22
|
-
slots: Object.freeze(refs)
|
|
32
|
+
slots: Object.freeze(refs),
|
|
33
|
+
display: Object.freeze(displayRefs)
|
|
23
34
|
};
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { declaringModule, isSection } from "./section.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { workspacePath } from "../platform/paths.js";
|
|
3
|
+
import { listDirSync } from "../platform/fs.js";
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
5
6
|
|
|
6
7
|
//#region src/section/discovery.ts
|
|
@@ -11,7 +12,6 @@ const SKIPPED_DIRS = /* @__PURE__ */ new Set([
|
|
|
11
12
|
"dist",
|
|
12
13
|
".concrete"
|
|
13
14
|
]);
|
|
14
|
-
/** Two distinct section values under one key: the key is the platform identity. */
|
|
15
15
|
var DuplicateSectionKeyError = class extends Error {
|
|
16
16
|
key;
|
|
17
17
|
first;
|
|
@@ -24,14 +24,12 @@ var DuplicateSectionKeyError = class extends Error {
|
|
|
24
24
|
this.name = "DuplicateSectionKeyError";
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
/** The workspace's modules in discovery order, absolute paths: what discovery imports and `check` loads. */
|
|
28
27
|
function listModules(root) {
|
|
29
28
|
const out = [];
|
|
30
29
|
const walk = (dir, depth) => {
|
|
31
|
-
const
|
|
32
|
-
for (const entry of entries) {
|
|
30
|
+
for (const entry of listDirSync(dir)) {
|
|
33
31
|
if (entry.name.startsWith(".")) continue;
|
|
34
|
-
const path =
|
|
32
|
+
const path = entry.path;
|
|
35
33
|
if (entry.isDirectory()) {
|
|
36
34
|
if (SKIPPED_DIRS.has(entry.name) || depth === 0 && entry.name === "fixtures") continue;
|
|
37
35
|
walk(path, depth + 1);
|
|
@@ -44,17 +42,12 @@ function listModules(root) {
|
|
|
44
42
|
async function defaultImport(file) {
|
|
45
43
|
return await import(pathToFileURL(file).href);
|
|
46
44
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Enumerate the workspace's modules and collect every exported section value. Two
|
|
49
|
-
* DISTINCT sections declaring one key is an error — the key is the platform identity,
|
|
50
|
-
* and two values cannot share it.
|
|
51
|
-
*/
|
|
52
45
|
async function discoverSections(options) {
|
|
53
46
|
const importModule = options.importModule ?? defaultImport;
|
|
54
47
|
const found = [];
|
|
55
48
|
const byKey = /* @__PURE__ */ new Map();
|
|
56
49
|
for (const file of listModules(options.root)) {
|
|
57
|
-
const module =
|
|
50
|
+
const module = workspacePath(options.root, file);
|
|
58
51
|
const exports = await importModule(file);
|
|
59
52
|
for (const [exportName, value] of Object.entries(exports)) {
|
|
60
53
|
if (!isSection(value)) continue;
|
|
@@ -82,14 +75,6 @@ function isDeclaringModule(section, file) {
|
|
|
82
75
|
return false;
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
|
-
/**
|
|
86
|
-
* The export site check and build bundle a section from — the one rule for choosing
|
|
87
|
-
* among a section's several export sites. The module that declares the section wins
|
|
88
|
-
* over any module re-exporting it: an entry through a barrel drags every sibling the
|
|
89
|
-
* barrel lists, their islands and assets, into this section's bundles, and names the
|
|
90
|
-
* barrel in every finding. When the runtime recorded no declaring module among the
|
|
91
|
-
* sites, the first site in discovery order stands.
|
|
92
|
-
*/
|
|
93
78
|
function exportSite(discovered, section) {
|
|
94
79
|
const sites = discovered.filter((candidate) => candidate.section === section);
|
|
95
80
|
return sites.find((site) => site.declares) ?? sites[0];
|
package/dist/section/groups.js
CHANGED
|
@@ -5,7 +5,6 @@ import { createElement } from "react";
|
|
|
5
5
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
6
6
|
|
|
7
7
|
//#region src/section/groups.ts
|
|
8
|
-
/** A group derivation check error, carrying which fault it is so `check` can name its rule. */
|
|
9
8
|
var GroupDerivationError = class extends Error {
|
|
10
9
|
fault;
|
|
11
10
|
constructor(fault, message) {
|
|
@@ -14,11 +13,6 @@ var GroupDerivationError = class extends Error {
|
|
|
14
13
|
this.name = "GroupDerivationError";
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Derive a section's `groups` by rendering it under the groups probe over the blank
|
|
19
|
-
* state plus every `states` entry, for every declared variant case. Throws the check
|
|
20
|
-
* errors named above; returns `[]` for a section that declares no card.
|
|
21
|
-
*/
|
|
22
16
|
function deriveGroups(section, states = []) {
|
|
23
17
|
const { key, schema } = section;
|
|
24
18
|
const slotIds = Object.keys(schema.slots);
|