@jam-overture/loom 0.1.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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
import { NO_DATA } from "../data/resolution.js";
|
|
3
|
+
import { NO_FRAMES } from "../frame/resolution.js";
|
|
4
|
+
import { ANCHOR_PROP_KEY, DATA_PROP_KEY, SUBMIT_PROP_KEY } from "../reserved-props.js";
|
|
5
|
+
import { assertNever } from "../result.js";
|
|
6
|
+
import { themeVariables } from "../theme/apply.js";
|
|
7
|
+
import { findNode, textOf } from "../tree/navigation.js";
|
|
8
|
+
import { createAnchorLedger, resolveAnchor, } from "./anchor.js";
|
|
9
|
+
import { isBehaviourResolver, NO_RESOLVED_BEHAVIOURS, resolveBehaviours, } from "./behaviour.js";
|
|
10
|
+
import { literalThemeElement } from "./inline-variables.js";
|
|
11
|
+
import { editableAttributes } from "./editable.js";
|
|
12
|
+
import { isFrameResolver, resolveNodeFrames } from "./frame.js";
|
|
13
|
+
import { NO_SLOTS, } from "./primitive.js";
|
|
14
|
+
import { isBindingReader, unreadBindings } from "./reads.js";
|
|
15
|
+
import { isTextResolver, NO_TEXT, overlayText, } from "./text.js";
|
|
16
|
+
import { partitionReservedProps, resolveTheme, themeStyle, THEME_PROP_KEY } from "./theme.js";
|
|
17
|
+
const renderChildren = (children, context) => children.length === 0 ? null : children.map((child) => renderNode(child, context));
|
|
18
|
+
const isRootNode = (node, context) => node.id === context.tree.root.id;
|
|
19
|
+
const renderElementBody = (node, context) => {
|
|
20
|
+
if (!node.children.some((child) => child.kind === "slot")) {
|
|
21
|
+
return { children: renderChildren(node.children, context), slots: NO_SLOTS };
|
|
22
|
+
}
|
|
23
|
+
const slots = Object.create(null);
|
|
24
|
+
const rest = [];
|
|
25
|
+
for (const child of node.children) {
|
|
26
|
+
if (child.kind !== "slot") {
|
|
27
|
+
rest.push(renderNode(child, context));
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const placed = renderNode(child, context);
|
|
31
|
+
const existing = slots[child.name];
|
|
32
|
+
slots[child.name] =
|
|
33
|
+
existing === undefined ? placed : [...(Array.isArray(existing) ? existing : [existing]), placed];
|
|
34
|
+
}
|
|
35
|
+
return { children: rest.length === 0 ? null : rest, slots: Object.freeze(slots) };
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A decorative render walks nodes the primary render has already walked, so
|
|
39
|
+
* every diagnostic it could raise is one the caller has been told. Dropping
|
|
40
|
+
* them is what keeps `renderLoomTree`'s output a function of the tree rather
|
|
41
|
+
* than of which primitives happened to ask for a copy.
|
|
42
|
+
*/
|
|
43
|
+
const discardDiagnostic = () => undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The node's children again, with identity off — see `decorative.ts` for what
|
|
46
|
+
* that buys and what it does not.
|
|
47
|
+
*
|
|
48
|
+
* Rendered on the first call and kept, so a primitive that places the copy in
|
|
49
|
+
* two arrangements gets the same elements both times, and one that never asks
|
|
50
|
+
* pays a closure. The cache lives in this closure rather than at module scope,
|
|
51
|
+
* for the reason `composeText` keeps its map here: two renders of the same tree
|
|
52
|
+
* must not be able to disagree because one of them ran first.
|
|
53
|
+
*/
|
|
54
|
+
const decorativeChildrenFor = (node, context) => {
|
|
55
|
+
let copy;
|
|
56
|
+
let rendered = false;
|
|
57
|
+
return () => {
|
|
58
|
+
if (!rendered) {
|
|
59
|
+
copy = renderChildren(node.children, {
|
|
60
|
+
...context,
|
|
61
|
+
editMode: false,
|
|
62
|
+
addressed: false,
|
|
63
|
+
decorative: true,
|
|
64
|
+
collect: discardDiagnostic,
|
|
65
|
+
});
|
|
66
|
+
rendered = true;
|
|
67
|
+
}
|
|
68
|
+
return copy;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const renderContextFor = (node, slots, data, submit, frames, anchor, text, behaviours, context) => {
|
|
72
|
+
const isRoot = isRootNode(node, context);
|
|
73
|
+
const theme = isRoot ? context.theme : undefined;
|
|
74
|
+
return {
|
|
75
|
+
nodeId: node.id,
|
|
76
|
+
type: node.type,
|
|
77
|
+
slots,
|
|
78
|
+
data,
|
|
79
|
+
frames,
|
|
80
|
+
text,
|
|
81
|
+
behaviours,
|
|
82
|
+
decorative: decorativeChildrenFor(node, context),
|
|
83
|
+
...(submit ? { submit } : {}),
|
|
84
|
+
...(anchor ? { anchor } : {}),
|
|
85
|
+
...(context.editMode || context.addressed
|
|
86
|
+
? { editable: editableAttributes(node, isRoot ? context.tree : undefined) }
|
|
87
|
+
: {}),
|
|
88
|
+
...(theme ? { theme } : {}),
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The answers for a node that declared bindings, and a diagnostic for each one
|
|
93
|
+
* that has none. The plan was read from this same tree before the walk began, so
|
|
94
|
+
* the lookup is a map read: nothing here parses, asks or waits.
|
|
95
|
+
*/
|
|
96
|
+
const nodeDataFor = (node, declared, context) => {
|
|
97
|
+
if (!context.data) {
|
|
98
|
+
context.collect({ code: "data-unresolved", nodeId: node.id, resolution: "absent" });
|
|
99
|
+
return NO_DATA;
|
|
100
|
+
}
|
|
101
|
+
let reported = 0;
|
|
102
|
+
for (const problem of context.data.problemsFor(node.id)) {
|
|
103
|
+
reported += 1;
|
|
104
|
+
context.collect(problem.kind === "misdeclared"
|
|
105
|
+
? { code: "data-misdeclared", nodeId: node.id, error: problem.error }
|
|
106
|
+
: {
|
|
107
|
+
code: "data-unavailable",
|
|
108
|
+
nodeId: node.id,
|
|
109
|
+
name: problem.name,
|
|
110
|
+
source: problem.source,
|
|
111
|
+
unavailable: problem.unavailable,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const data = context.data.lookup(node.id);
|
|
115
|
+
/**
|
|
116
|
+
* A resolution that answered nothing for a node that asked for something has
|
|
117
|
+
* never heard of the node: `buildDataResolution` gives every planned binding an
|
|
118
|
+
* outcome and every malformed declaration a problem, so silence on both means
|
|
119
|
+
* the answers were built from a different tree's plan.
|
|
120
|
+
*
|
|
121
|
+
* Said here rather than left to the seam because the seam cannot say it — a
|
|
122
|
+
* resolution is asked about a node id and has no way to know the node declared
|
|
123
|
+
* anything. The walk holds both halves, which is what makes this the only place
|
|
124
|
+
* the two facts meet.
|
|
125
|
+
*/
|
|
126
|
+
if (reported === 0 && !hasAnswers(data) && asksForSomething(declared)) {
|
|
127
|
+
context.collect({ code: "data-unresolved", nodeId: node.id, resolution: "unrelated" });
|
|
128
|
+
}
|
|
129
|
+
reportUnreadBindings(node, data, context);
|
|
130
|
+
return data;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* A diagnostic for every name this node was answered under that its primitive
|
|
134
|
+
* says it does not read.
|
|
135
|
+
*
|
|
136
|
+
* Measured on the *answers* rather than on the declaration, and the difference
|
|
137
|
+
* matters in one direction only: a binding whose source could not answer is
|
|
138
|
+
* already reported as `data-unavailable`, and saying of the same name that
|
|
139
|
+
* nobody reads it either is two true things about one mistake, in the order
|
|
140
|
+
* they would be fixed. A malformed declaration reaches neither, because there
|
|
141
|
+
* are no names in it to be read.
|
|
142
|
+
*
|
|
143
|
+
* Silent unless the primitive has declared, which is the whole bargain: the
|
|
144
|
+
* reader answers `undefined` both for a primitive whose author has said nothing
|
|
145
|
+
* and for a type this registry does not hold, and neither is a primitive
|
|
146
|
+
* claiming it reads nothing.
|
|
147
|
+
*
|
|
148
|
+
* The node's props go to the seam alongside the declaration, because a
|
|
149
|
+
* declaration may name the prop that names the binding rather than the binding
|
|
150
|
+
* (0184), and this walk is the only place holding both.
|
|
151
|
+
*/
|
|
152
|
+
const reportUnreadBindings = (node, data, context) => {
|
|
153
|
+
const declared = context.reads?.bindingsReadBy(node.type);
|
|
154
|
+
if (declared === undefined)
|
|
155
|
+
return;
|
|
156
|
+
const asked = [];
|
|
157
|
+
for (const name in data)
|
|
158
|
+
asked.push(name);
|
|
159
|
+
for (const name of unreadBindings(asked, declared, node.props)) {
|
|
160
|
+
context.collect({ code: "data-unread", nodeId: node.id, type: node.type, name });
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/** Whether the resolution answered this node at all. Early-return rather than
|
|
164
|
+
* `Object.keys`, because it runs on every bound node of every render and the
|
|
165
|
+
* question is only ever whether the bag is empty. */
|
|
166
|
+
const hasAnswers = (data) => {
|
|
167
|
+
for (const _name in data)
|
|
168
|
+
return true;
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Whether a declaration is a question at all. The one value that asks for
|
|
173
|
+
* nothing is an object with no entries — `"loom:data": {}` — and a render that
|
|
174
|
+
* answered it with nothing has served it correctly.
|
|
175
|
+
*
|
|
176
|
+
* Everything else asks, malformed included: a string or a number under
|
|
177
|
+
* `loom:data` is not a node that stayed quiet, it is a node whose declaration
|
|
178
|
+
* the plan will refuse. It did ask; the plan is the thing that judges how well.
|
|
179
|
+
*
|
|
180
|
+
* Deliberately a shape test rather than a parse — the walk's contract, stated in
|
|
181
|
+
* `nodeDataFor` above, is that nothing here parses.
|
|
182
|
+
*/
|
|
183
|
+
const asksForSomething = (declared) => typeof declared !== "object" || declared === null || Object.keys(declared).length > 0;
|
|
184
|
+
/**
|
|
185
|
+
* The target for a node that named an endpoint, and a diagnostic when it has
|
|
186
|
+
* none. The plan was read from this same tree before the walk began, so the
|
|
187
|
+
* lookup is a map read: nothing here parses, asks or waits.
|
|
188
|
+
*/
|
|
189
|
+
const nodeSubmissionFor = (node, context) => {
|
|
190
|
+
if (!context.submissions) {
|
|
191
|
+
context.collect({ code: "submit-unresolved", nodeId: node.id, resolution: "absent" });
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
let reported = 0;
|
|
195
|
+
for (const problem of context.submissions.problemsFor(node.id)) {
|
|
196
|
+
reported += 1;
|
|
197
|
+
context.collect(problem.kind === "misdeclared"
|
|
198
|
+
? { code: "submit-misdeclared", nodeId: node.id, error: problem.error }
|
|
199
|
+
: {
|
|
200
|
+
code: "submit-unavailable",
|
|
201
|
+
nodeId: node.id,
|
|
202
|
+
to: problem.to,
|
|
203
|
+
unavailable: problem.unavailable,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const outcome = context.submissions.lookup(node.id);
|
|
207
|
+
/**
|
|
208
|
+
* The data seam's case exactly, and it needs no emptiness test: a submission is
|
|
209
|
+
* one declaration rather than a map, so a node that carries `loom:submit` at all
|
|
210
|
+
* has asked, and `buildSubmissionResolution` answers every planned one.
|
|
211
|
+
*/
|
|
212
|
+
if (reported === 0 && !outcome) {
|
|
213
|
+
context.collect({ code: "submit-unresolved", nodeId: node.id, resolution: "unrelated" });
|
|
214
|
+
}
|
|
215
|
+
return outcome;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* The verdict on every framable prop this node's primitive declared, and a
|
|
219
|
+
* diagnostic for each one that will not be framed.
|
|
220
|
+
*
|
|
221
|
+
* Read from the node's own props rather than from a plan, because there is
|
|
222
|
+
* nothing to plan: the allowlist is already in hand and the check is a URL
|
|
223
|
+
* parse. That is the whole of what makes this seam synchronous where the data
|
|
224
|
+
* and submission seams are not.
|
|
225
|
+
*
|
|
226
|
+
* `frame-same-origin` is reported for a frame that *is* permitted, which no
|
|
227
|
+
* other diagnostic here does. It is not a complaint about the tree — a host
|
|
228
|
+
* registered that origin deliberately — it is the only place in the system that
|
|
229
|
+
* can notice a sandbox is inert, and noticing silently would be the same as not
|
|
230
|
+
* noticing.
|
|
231
|
+
*/
|
|
232
|
+
const nodeFramesFor = (node, props, context) => {
|
|
233
|
+
const declared = context.frames?.framePropsFor(node.type) ?? [];
|
|
234
|
+
if (declared.length === 0)
|
|
235
|
+
return NO_FRAMES;
|
|
236
|
+
return resolveNodeFrames(props, declared, context.origins, (prop, outcome) => {
|
|
237
|
+
if (outcome.status === "refused") {
|
|
238
|
+
context.collect({ code: "frame-refused", nodeId: node.id, prop, refusal: outcome.refusal });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (outcome.sameOrigin) {
|
|
242
|
+
context.collect({
|
|
243
|
+
code: "frame-same-origin",
|
|
244
|
+
nodeId: node.id,
|
|
245
|
+
prop,
|
|
246
|
+
origin: outcome.origin,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* The `id` this node was given, and a diagnostic when the tree named one it
|
|
253
|
+
* could not have.
|
|
254
|
+
*
|
|
255
|
+
* Read from the node's own props with nothing to plan and nothing to wire,
|
|
256
|
+
* exactly as a frame is — an anchor is a string held against a grammar and
|
|
257
|
+
* against the anchors already taken, and neither of those waits on anybody.
|
|
258
|
+
*
|
|
259
|
+
* Nothing is read at all inside a decorative copy. A copy is the same children
|
|
260
|
+
* with identity switched off, and an anchor is identity: emitting one would put
|
|
261
|
+
* the same `id` on two elements, which is the failure the copy exists to avoid
|
|
262
|
+
* in the first place, in the other of its two spellings.
|
|
263
|
+
*/
|
|
264
|
+
const nodeAnchorFor = (node, reserved, context) => {
|
|
265
|
+
if (context.decorative)
|
|
266
|
+
return undefined;
|
|
267
|
+
const reading = resolveAnchor(reserved[ANCHOR_PROP_KEY], node.id, context.anchors);
|
|
268
|
+
switch (reading.status) {
|
|
269
|
+
case "anchored":
|
|
270
|
+
return reading.attributes;
|
|
271
|
+
case "unusable":
|
|
272
|
+
context.collect({ code: "anchor-unusable", nodeId: node.id, detail: reading.detail });
|
|
273
|
+
return undefined;
|
|
274
|
+
case "claimed":
|
|
275
|
+
context.collect({
|
|
276
|
+
code: "anchor-claimed",
|
|
277
|
+
nodeId: node.id,
|
|
278
|
+
anchor: reading.anchor,
|
|
279
|
+
holder: reading.holder,
|
|
280
|
+
});
|
|
281
|
+
return undefined;
|
|
282
|
+
default:
|
|
283
|
+
return assertNever(reading, "nodeAnchorFor");
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* The controls this node's primitive declared, built from the tree.
|
|
288
|
+
*
|
|
289
|
+
* The content a behaviour acts on is `textOf` the node — read from the tree
|
|
290
|
+
* rather than from the markup around it, so a copy button copies what the page
|
|
291
|
+
* says and not the language label its own primitive rendered beside it.
|
|
292
|
+
*
|
|
293
|
+
* A behaviour whose name could not be resolved is left out and reported, for
|
|
294
|
+
* the reason `resolveBehaviours` gives: a control a screen reader announces as
|
|
295
|
+
* "button" is worse than no control, and this is the only place that can say so.
|
|
296
|
+
*/
|
|
297
|
+
const nodeBehavioursFor = (node, text, context) => {
|
|
298
|
+
const declared = context.behaviours?.behavioursFor(node.type) ?? [];
|
|
299
|
+
if (declared.length === 0)
|
|
300
|
+
return NO_RESOLVED_BEHAVIOURS.behaviours;
|
|
301
|
+
const resolved = resolveBehaviours(declared, textOf(node), text);
|
|
302
|
+
for (const { behaviour, key } of resolved.unnamed) {
|
|
303
|
+
context.collect({ code: "behaviour-unnamed", nodeId: node.id, behaviour, key });
|
|
304
|
+
}
|
|
305
|
+
return resolved.behaviours;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Reserved keys are removed from every node's props, whether or not anything
|
|
309
|
+
* reads them here; a key that reaches a primitive is a key that primitive has
|
|
310
|
+
* to know about. What each one means, though, depends on where it sits, so
|
|
311
|
+
* anything unread is reported rather than dropped in silence.
|
|
312
|
+
*/
|
|
313
|
+
const reportUnreadReservedProps = (node, reserved, isRoot, context) => {
|
|
314
|
+
for (const key of Object.keys(reserved)) {
|
|
315
|
+
if (key === THEME_PROP_KEY) {
|
|
316
|
+
if (!isRoot)
|
|
317
|
+
context.collect({ code: "theme-misplaced", nodeId: node.id });
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
/** Read before the walk, by the data seam, and reported by `nodeDataFor`. */
|
|
321
|
+
if (key === DATA_PROP_KEY)
|
|
322
|
+
continue;
|
|
323
|
+
/** The same, by the submission seam and `nodeSubmissionFor`. */
|
|
324
|
+
if (key === SUBMIT_PROP_KEY)
|
|
325
|
+
continue;
|
|
326
|
+
/** Read inside the walk, by `nodeAnchorFor`, which reports its own faults. */
|
|
327
|
+
if (key === ANCHOR_PROP_KEY)
|
|
328
|
+
continue;
|
|
329
|
+
context.collect({ code: "reserved-prop-unrecognised", nodeId: node.id, key });
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const renderElement = (node, context) => {
|
|
333
|
+
const primitive = context.resolver.resolve(node.type);
|
|
334
|
+
/**
|
|
335
|
+
* An unknown primitive omits its whole subtree rather than promoting the
|
|
336
|
+
* children into the missing container's place: a card's contents spilling
|
|
337
|
+
* into the page body is a worse failure than a gap, and a gap is what the
|
|
338
|
+
* diagnostic describes.
|
|
339
|
+
*/
|
|
340
|
+
if (!primitive) {
|
|
341
|
+
context.collect({ code: "unknown-primitive", nodeId: node.id, type: node.type });
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
const { props, reserved } = partitionReservedProps(node.props);
|
|
345
|
+
reportUnreadReservedProps(node, reserved, isRootNode(node, context), context);
|
|
346
|
+
/**
|
|
347
|
+
* Props that do not satisfy the primitive's declared schema omit the node the
|
|
348
|
+
* same way an unknown primitive does. Rendering it anyway would hand a
|
|
349
|
+
* primitive a bag its own types say cannot occur, which pushes an unchecked
|
|
350
|
+
* cast into every primitive author's lap; refusing one node and reporting why
|
|
351
|
+
* keeps the failure where the mismatch is.
|
|
352
|
+
*/
|
|
353
|
+
const verdict = context.validator?.validateProps(node.type, props);
|
|
354
|
+
if (verdict?.outcome === "invalid") {
|
|
355
|
+
context.collect({
|
|
356
|
+
code: "invalid-props",
|
|
357
|
+
nodeId: node.id,
|
|
358
|
+
type: node.type,
|
|
359
|
+
issues: verdict.issues,
|
|
360
|
+
});
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
if (verdict?.outcome === "undeclared") {
|
|
364
|
+
context.collect({ code: "props-undeclared", nodeId: node.id, type: node.type });
|
|
365
|
+
}
|
|
366
|
+
const data = reserved[DATA_PROP_KEY] === undefined
|
|
367
|
+
? NO_DATA
|
|
368
|
+
: nodeDataFor(node, reserved[DATA_PROP_KEY], context);
|
|
369
|
+
const submit = reserved[SUBMIT_PROP_KEY] === undefined ? undefined : nodeSubmissionFor(node, context);
|
|
370
|
+
/**
|
|
371
|
+
* A map read, and the same map for every node of one type — the merge with
|
|
372
|
+
* whatever dictionary this deployment supplied happened once, when the
|
|
373
|
+
* resolver was built.
|
|
374
|
+
*/
|
|
375
|
+
const frames = nodeFramesFor(node, props, context);
|
|
376
|
+
/**
|
|
377
|
+
* Claimed here rather than while the render context is built, which happens
|
|
378
|
+
* after this node's children have already been walked. First claim in document
|
|
379
|
+
* order has to mean the ancestor, not whichever descendant the walk reached
|
|
380
|
+
* before returning to its parent.
|
|
381
|
+
*/
|
|
382
|
+
const anchor = reserved[ANCHOR_PROP_KEY] === undefined ? undefined : nodeAnchorFor(node, reserved, context);
|
|
383
|
+
const text = context.text?.textFor(node.type) ?? NO_TEXT;
|
|
384
|
+
const behaviours = nodeBehavioursFor(node, text, context);
|
|
385
|
+
const body = renderElementBody(node, context);
|
|
386
|
+
const rendered = {
|
|
387
|
+
loom: renderContextFor(node, body.slots, data, submit, frames, anchor, text, behaviours, context),
|
|
388
|
+
props,
|
|
389
|
+
children: body.children,
|
|
390
|
+
};
|
|
391
|
+
return context.literals
|
|
392
|
+
? literalThemeElement(primitive, context.literals, node.id, rendered)
|
|
393
|
+
: createElement(primitive, { key: node.id, ...rendered });
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* A slot is a projection point, not a box. It renders its projected content, or
|
|
397
|
+
* its own children as the fallback when the host projected nothing, and adds no
|
|
398
|
+
* element of its own in either case.
|
|
399
|
+
*/
|
|
400
|
+
const renderSlot = (node, context) => {
|
|
401
|
+
/** Own-property only, for the reason given in `staticPrimitiveResolver`. */
|
|
402
|
+
const projected = Object.hasOwn(context.slots, node.name)
|
|
403
|
+
? context.slots[node.name]
|
|
404
|
+
: renderChildren(node.children, context);
|
|
405
|
+
return createElement(Fragment, { key: node.id }, projected);
|
|
406
|
+
};
|
|
407
|
+
const renderNode = (node, context) => {
|
|
408
|
+
switch (node.kind) {
|
|
409
|
+
case "element":
|
|
410
|
+
return renderElement(node, context);
|
|
411
|
+
case "text":
|
|
412
|
+
return node.value;
|
|
413
|
+
case "slot":
|
|
414
|
+
return renderSlot(node, context);
|
|
415
|
+
default:
|
|
416
|
+
return assertNever(node, "renderNode");
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* The theme is resolved once, from the root, before the walk begins — a tree
|
|
421
|
+
* wears one theme and the variables cascade to everything under it, so
|
|
422
|
+
* resolving per node would be the same answer computed for every node in the
|
|
423
|
+
* page.
|
|
424
|
+
*/
|
|
425
|
+
const mountedTheme = (tree, registry, collect) => {
|
|
426
|
+
const { reserved } = partitionReservedProps(tree.root.props);
|
|
427
|
+
const resolution = resolveTheme(reserved, registry);
|
|
428
|
+
switch (resolution.outcome) {
|
|
429
|
+
case "themed":
|
|
430
|
+
return resolution.theme;
|
|
431
|
+
case "unthemed":
|
|
432
|
+
return undefined;
|
|
433
|
+
case "unregistered":
|
|
434
|
+
collect({ code: "theme-unregistered", nodeId: tree.root.id });
|
|
435
|
+
return undefined;
|
|
436
|
+
case "unresolved":
|
|
437
|
+
collect({ code: "theme-unresolved", nodeId: tree.root.id, error: resolution.error });
|
|
438
|
+
return undefined;
|
|
439
|
+
default:
|
|
440
|
+
return assertNever(resolution, "mountedTheme");
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* The two halves of the text seam, composed into the one lookup the walk uses.
|
|
445
|
+
*
|
|
446
|
+
* Declarations are read off the resolver, because they belong to the primitive
|
|
447
|
+
* and travel with it; the host's dictionary is laid over them, because the
|
|
448
|
+
* language is the host's. Neither half is required and neither is enough on its
|
|
449
|
+
* own: with no dictionary a page renders the authors' strings, and with a
|
|
450
|
+
* dictionary that answers for only part of the library the rest keeps theirs.
|
|
451
|
+
*
|
|
452
|
+
* The merge is memoised per type for the length of one render — a page with
|
|
453
|
+
* fifty markers merges once, not fifty times — and the cache lives in this
|
|
454
|
+
* closure rather than at module scope, so two renders of the same tree cannot
|
|
455
|
+
* disagree because one of them ran first.
|
|
456
|
+
*/
|
|
457
|
+
const composeText = (resolver, supplied) => {
|
|
458
|
+
const declared = isTextResolver(resolver) ? resolver : undefined;
|
|
459
|
+
if (!supplied)
|
|
460
|
+
return declared;
|
|
461
|
+
if (!declared)
|
|
462
|
+
return supplied;
|
|
463
|
+
const merged = new Map();
|
|
464
|
+
return {
|
|
465
|
+
textFor: (type) => {
|
|
466
|
+
const cached = merged.get(type);
|
|
467
|
+
if (cached)
|
|
468
|
+
return cached;
|
|
469
|
+
const resolved = overlayText(declared.textFor(type), supplied.textFor(type));
|
|
470
|
+
merged.set(type, resolved);
|
|
471
|
+
return resolved;
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* One walk, from wherever it is told to start.
|
|
477
|
+
*
|
|
478
|
+
* The theme is the *tree's* — resolved from the root's reserved props whichever
|
|
479
|
+
* node this render begins at, because a theme is a fact about the document and
|
|
480
|
+
* not about the node you happened to ask for. What differs between a page and an
|
|
481
|
+
* excerpt is only who mounts it, which is `renderLoomExcerpt`'s business and not
|
|
482
|
+
* this function's.
|
|
483
|
+
*/
|
|
484
|
+
const renderFrom = (tree, from, options, collect) => {
|
|
485
|
+
const theme = mountedTheme(tree, options.themes, collect);
|
|
486
|
+
/**
|
|
487
|
+
* There is nothing to substitute against when no theme mounted, so the render
|
|
488
|
+
* proceeds as it always would and says why. The caller asked for values
|
|
489
|
+
* because whatever it is feeding cannot resolve a reference, and in that
|
|
490
|
+
* medium nothing downstream would have noticed they never arrived.
|
|
491
|
+
*/
|
|
492
|
+
if (options.themeValues === "literals" && !theme) {
|
|
493
|
+
collect({ code: "theme-values-unmounted", nodeId: tree.root.id });
|
|
494
|
+
}
|
|
495
|
+
const element = renderNode(from, {
|
|
496
|
+
resolver: options.resolver,
|
|
497
|
+
validator: options.validator,
|
|
498
|
+
editMode: options.editMode ?? false,
|
|
499
|
+
addressed: options.addressed ?? false,
|
|
500
|
+
slots: options.slots ?? {},
|
|
501
|
+
tree,
|
|
502
|
+
theme: theme ? themeStyle(theme) : undefined,
|
|
503
|
+
data: options.data,
|
|
504
|
+
submissions: options.submissions,
|
|
505
|
+
origins: options.origins,
|
|
506
|
+
frames: isFrameResolver(options.resolver) ? options.resolver : undefined,
|
|
507
|
+
reads: isBindingReader(options.resolver) ? options.resolver : undefined,
|
|
508
|
+
text: composeText(options.resolver, options.text),
|
|
509
|
+
behaviours: isBehaviourResolver(options.resolver) ? options.resolver : undefined,
|
|
510
|
+
anchors: createAnchorLedger(),
|
|
511
|
+
decorative: false,
|
|
512
|
+
literals: options.themeValues === "literals" && theme ? themeVariables(theme) : undefined,
|
|
513
|
+
collect,
|
|
514
|
+
});
|
|
515
|
+
return { element, theme };
|
|
516
|
+
};
|
|
517
|
+
export const renderLoomTree = (tree, options) => {
|
|
518
|
+
const diagnostics = [];
|
|
519
|
+
const collect = (diagnostic) => {
|
|
520
|
+
diagnostics.push(diagnostic);
|
|
521
|
+
};
|
|
522
|
+
const { element, theme } = renderFrom(tree, tree.root, options, collect);
|
|
523
|
+
return { element, diagnostics, ...(theme ? { theme } : {}) };
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Part of a tree, rendered on its own and wearing the tree's theme.
|
|
527
|
+
*
|
|
528
|
+
* A preview, an inspector and a side-by-side are all the same shape: one node of
|
|
529
|
+
* a page, shown somewhere that is not the page. Rendering one by hand loses the
|
|
530
|
+
* theme silently. 0049 mounts a theme on the *root primitive* — `loom.page` puts
|
|
531
|
+
* the variables on its own element — so a walk that starts anywhere else hands
|
|
532
|
+
* `var(--loom-…)` to a subtree with nothing above it to resolve them, and
|
|
533
|
+
* `resolveTheme` is right to call that node unthemed. Nothing is wrong; there is
|
|
534
|
+
* simply no theme, and no diagnostic says so because none is owed.
|
|
535
|
+
*
|
|
536
|
+
* So the seam mounts it, on an element of its own around the excerpt:
|
|
537
|
+
*
|
|
538
|
+
* - **The excerpt is self-contained.** It carries the variables it references,
|
|
539
|
+
* whichever node it starts from, and can be dropped into a page that owns a
|
|
540
|
+
* different theme or none at all.
|
|
541
|
+
* - **The wrapper is always there and always carries the theme**, the root
|
|
542
|
+
* included. An excerpt of the root then mounts the same variables twice, on
|
|
543
|
+
* nested elements, which is the same values by construction — and the rule a
|
|
544
|
+
* caller can hold is *the excerpt carries its theme* rather than *the excerpt
|
|
545
|
+
* carries its theme unless you asked for the node that carries it already*.
|
|
546
|
+
*
|
|
547
|
+
* Everything else is the page render: the same walk, the same resolvers, the
|
|
548
|
+
* same diagnostics. The excerpt's root is not the tree's root, so it does not
|
|
549
|
+
* receive the root's `theme` prop, its editable attributes name no tree, and a
|
|
550
|
+
* `loom:theme` sitting on it is `theme-misplaced` — all of which is what those
|
|
551
|
+
* rules already say, applied to a node that is not the root.
|
|
552
|
+
*/
|
|
553
|
+
export const renderLoomExcerpt = (tree, nodeId, options) => {
|
|
554
|
+
const diagnostics = [];
|
|
555
|
+
const collect = (diagnostic) => {
|
|
556
|
+
diagnostics.push(diagnostic);
|
|
557
|
+
};
|
|
558
|
+
const from = findNode(tree.root, nodeId);
|
|
559
|
+
if (!from) {
|
|
560
|
+
collect({ code: "excerpt-absent", nodeId });
|
|
561
|
+
return { element: null, diagnostics, found: false };
|
|
562
|
+
}
|
|
563
|
+
const { element, theme } = renderFrom(tree, from, options, collect);
|
|
564
|
+
return {
|
|
565
|
+
element: createElement("div", { style: theme ? themeStyle(theme) : undefined }, element),
|
|
566
|
+
diagnostics,
|
|
567
|
+
found: true,
|
|
568
|
+
...(theme ? { theme } : {}),
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { DataRegistry } from "../data/adapter.js";
|
|
2
|
+
import type { FrameOriginRegistry } from "../frame/origin.js";
|
|
3
|
+
import type { TreeId } from "../ids.js";
|
|
4
|
+
import type { JsonObject } from "../json.js";
|
|
5
|
+
import { type Result } from "../result.js";
|
|
6
|
+
import type { EndpointRegistry } from "../submit/endpoint.js";
|
|
7
|
+
import type { ThemeRegistry } from "../theme/registry.js";
|
|
8
|
+
import type { TreeError } from "../tree/errors.js";
|
|
9
|
+
import { type LoomTree } from "../tree/tree.js";
|
|
10
|
+
import type { PrimitiveResolver } from "./primitive.js";
|
|
11
|
+
import type { PropsValidator } from "./props.js";
|
|
12
|
+
import { type RenderOutput, type SlotContent } from "./render.js";
|
|
13
|
+
import type { TextResolver } from "./text.js";
|
|
14
|
+
/**
|
|
15
|
+
* Resolution, once per request.
|
|
16
|
+
*
|
|
17
|
+
* The adaptive part of an adaptive renderer is that the tree served is a
|
|
18
|
+
* function of who is asking, so the tree is loaded per request rather than
|
|
19
|
+
* imported: there is no module-level cache here, and a host that wants one puts
|
|
20
|
+
* it behind `TreeSource` where it can be keyed and invalidated deliberately.
|
|
21
|
+
*
|
|
22
|
+
* `TreeSource.load` returns `unknown`. Storage is a boundary like any other —
|
|
23
|
+
* a document written by an older schema version, or by something that never
|
|
24
|
+
* went through the Gate, must not reach the renderer unvalidated — so the
|
|
25
|
+
* parse happens here rather than being something every host remembers to do.
|
|
26
|
+
*/
|
|
27
|
+
export type RenderRequest = {
|
|
28
|
+
readonly treeId: TreeId;
|
|
29
|
+
/** Decoration is a property of the request, so one process can serve both. */
|
|
30
|
+
readonly editMode: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Identity on a published page's markup, so reader signals can name the node
|
|
33
|
+
* they are about. Off when absent (0136).
|
|
34
|
+
*/
|
|
35
|
+
readonly addressed?: boolean;
|
|
36
|
+
/** Opaque host context — audience, locale, flags — passed through to the source. */
|
|
37
|
+
readonly context?: JsonObject;
|
|
38
|
+
};
|
|
39
|
+
export type TreeSourceError = {
|
|
40
|
+
readonly code: "not-found" | "unavailable";
|
|
41
|
+
readonly detail: string;
|
|
42
|
+
};
|
|
43
|
+
export interface TreeSource {
|
|
44
|
+
readonly load: (request: RenderRequest) => Promise<Result<unknown, TreeSourceError>>;
|
|
45
|
+
}
|
|
46
|
+
export type RenderDependencies = {
|
|
47
|
+
readonly source: TreeSource;
|
|
48
|
+
readonly resolver: PrimitiveResolver;
|
|
49
|
+
readonly validator?: PropsValidator;
|
|
50
|
+
/** Absent means the tree's theme is not resolved — see `RenderOptions.themes`. */
|
|
51
|
+
readonly themes?: ThemeRegistry;
|
|
52
|
+
/**
|
|
53
|
+
* Absent means the tree's bindings are not answered — see `RenderOptions.data`.
|
|
54
|
+
* Supplying a registry is what bounds the sources a proposal may name, the
|
|
55
|
+
* same way `themes` bounds the palettes (0058).
|
|
56
|
+
*/
|
|
57
|
+
readonly sources?: DataRegistry;
|
|
58
|
+
/**
|
|
59
|
+
* Absent means the tree's submissions are not answered — see
|
|
60
|
+
* `RenderOptions.submissions`. Supplying a registry is what bounds the
|
|
61
|
+
* destinations a proposal may name, and it is the only thing that does: an
|
|
62
|
+
* address never appears in a tree, so a deployment that registers nothing has
|
|
63
|
+
* no form that posts anywhere (0065).
|
|
64
|
+
*/
|
|
65
|
+
readonly endpoints?: EndpointRegistry;
|
|
66
|
+
/**
|
|
67
|
+
* The origins this deployment will frame — see `RenderOptions.origins`.
|
|
68
|
+
* Absent means every framable prop is refused with a diagnostic (0095).
|
|
69
|
+
*
|
|
70
|
+
* It sits here beside the other three registries and, unlike them, adds no
|
|
71
|
+
* `await`: an allowlist is a static fact, so it is passed straight through to
|
|
72
|
+
* the walk rather than resolved first.
|
|
73
|
+
*/
|
|
74
|
+
readonly origins?: FrameOriginRegistry;
|
|
75
|
+
/**
|
|
76
|
+
* Absent means primitives render the strings their authors declared — see
|
|
77
|
+
* `RenderOptions.text`. A host serving one language in the library's own
|
|
78
|
+
* language wires nothing here; a host serving another builds a resolver per
|
|
79
|
+
* dictionary and picks by whatever it reads the request's language from, which
|
|
80
|
+
* is its own business and not the framework's.
|
|
81
|
+
*/
|
|
82
|
+
readonly text?: TextResolver;
|
|
83
|
+
readonly slots?: SlotContent;
|
|
84
|
+
/**
|
|
85
|
+
* References or values — see `RenderOptions.themeValues`. It belongs to the
|
|
86
|
+
* request rather than to the deployment: one route serves a page to a browser
|
|
87
|
+
* and the next draws the same tree into an image, off the same dependencies.
|
|
88
|
+
*/
|
|
89
|
+
readonly themeValues?: "variables" | "literals";
|
|
90
|
+
};
|
|
91
|
+
export type RenderRequestError = {
|
|
92
|
+
readonly code: "source-failed";
|
|
93
|
+
readonly error: TreeSourceError;
|
|
94
|
+
} | {
|
|
95
|
+
readonly code: "invalid-tree";
|
|
96
|
+
readonly error: TreeError;
|
|
97
|
+
} | {
|
|
98
|
+
readonly code: "tree-id-mismatch";
|
|
99
|
+
readonly requested: TreeId;
|
|
100
|
+
readonly received: TreeId;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The rendered result carries the tree it came from: the caller needs
|
|
104
|
+
* `revision` to set a cache validator, and needs the parsed tree to be the same
|
|
105
|
+
* object the element was built from rather than one it loads again.
|
|
106
|
+
*/
|
|
107
|
+
export type RenderedRequest = RenderOutput & {
|
|
108
|
+
readonly tree: LoomTree;
|
|
109
|
+
};
|
|
110
|
+
export declare const renderRequest: (request: RenderRequest, dependencies: RenderDependencies) => Promise<Result<RenderedRequest, RenderRequestError>>;
|
|
111
|
+
//# sourceMappingURL=request.d.ts.map
|